$ gem install tremendous_ruby
or, add to your Gemfile
source 'https://rubygems.org'
gem 'tremendous_ruby'
require 'tremendous'
# Access token
# (apply for a production token at https://www.tremendous.com/api-access-request)
access_token = "[YOUR SANDBOX ACCESS TOKEN]"
# URL
# (production: use "https://www.tremendous.com/api/v2/")
url = "https://testflight.tremendous.com/api/v2/"
client = Tremendous::Rest.new(access_token, url)
#
# Generate an order.
#
# Campaigns are created within the dashboard by team admins.
# They define the catalog and presentation of your reward.
# API requests can always override these settings
# within the specific reward object by specifying the catalog, message, etc.
campaigns = client.campaigns.list
campaign_id = campaigns.first[:id]
# The funding source you select is how you are charged for the order.
# In this example, we use the prefunded balance funding source
funding_source_id = client.funding_sources.list.find { |f| f[:method] == "balance" }[:id]
# Optionally pass a unique external_id for each order create call
# to guarantee that your order is idempotent and not executed multiple times.
external_id = "[OPTIONAL_EXTERNAL_ID]"
# An hash representing the rewards you'd like to send.
order_data = {
external_id: external_id,
payment: {
funding_source_id: funding_source_id,
},
reward: {
value: {
denomination: 20,
currency_code: 'USD'
},
campaign_id: campaign_id,
delivery: {
method: 'EMAIL',
},
recipient: {
email: '[email protected]',
name: 'Sarah Smith'
}
}
}
# Submit the order.
order = client.orders.create!(order_data)
# Retrieve the reward.
client.rewards.show(order[:rewards].first[:id])
The gem is maintained by Tremendous engineers, but all are welcome to contribute. Feel free to open an issue, submit a PR, or post a question.