Skip to content

rewardsciences/rewardsciences-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started

The Reward Sciences gem lets you integrate with our API to track activities, assign points to customers and and let them redeem rewards without leaving your application.

Installation

gem install reward_sciences

Or add it to your gemfile

gem 'reward_sciences'

Quick Start Example

  1. Contact us at [email protected] to get a test account on our sandbox environment.

  2. Log in to our web app and get your API token from the 'API Tokens' area available under 'Settings'.

  3. Define the methods you'll use accross the app

module Rewardable
  def identify_reward_sciences_user(user)
    session[:reward_sciences_user_id] = reward_sciences.users.identify(user.email)['id']
  end

  def track_reward_sciences_activity(activity_slug)
    reward_sciences.activities.track(session[:reward_sciences_user_id], activity_slug)
  end

  def list_reward_sciences_rewards
    reward_sciences.rewards.list
  end

  def show_reward_sciences_reward(reward_id)
    reward_sciences.rewards.show(reward_id)
  end

  def redeem_reward_sciences_reward(reward_id)
    reward_sciences.rewards.redeem(session[:reward_sciences_user_id], reward_id)
  rescue RewardSciences::APIException => e
    redirect_to :back, alert: e.message.split(':').last
  end

  private

  def reward_sciences
    RewardSciences::RewardSciencesClient.new(
      Rails.application.secrets.reward_sciences_access_token,
      Rails.application.secrets.reward_sciences_environment
    )
  end
end
  1. Use the methods defined in the previous step

Sample Project

Check out our Sample Ruby on Rails project.

Help

If you have any questions feel free to email us at [email protected]. We are happy to help.

Class Reference

List of Controllers

Class: Rewards

Get singleton instance

The singleton instance of the Rewards class can be accessed from the API Client.

rewards = client.rewards

Method: bid

Bid on a reward auction.

def bid(user_id,
            reward_id,
            amount); end

Parameters:

Parameter Tags Description
user_id Required The ID of the user who is bidding on the reward auction.
reward_id Required The ID of the reward auction to be bid on.
amount Required Can be either 'max' (when max bidding) or the number of points the user wants to bid.

Example Usage:

user_id = 225
reward_id = 225
amount = 'amount'

result = rewards.bid(user_id, reward_id, amount)

Method: list

List all the available rewards.

def list(category_id = nil,
             limit = 25,
             offset = 0); end

Parameters:

Parameter Tags Description
category_id Optional The id of the category to filter rewards by
limit Optional DefaultValue The number of rewards you want to be retrieved.
offset Optional DefaultValue The number of rewards you want to skip before starting the retrieval.

Example Usage:

category_id = 225
limit = 25
offset = 0

result = rewards.list(category_id, limit, offset)

Method: redeem

Redeem a reward.

def redeem(user_id,
               reward_id); end

Parameters:

Parameter Tags Description
user_id Required The ID of the user who is redeeming the reward.
reward_id Required The ID of the reward to be redeemed.

Example Usage:

user_id = 225
reward_id = 225

result = rewards.redeem(user_id, reward_id)

Method: show

Show a reward's details.

def show(reward_id); end

Parameters:

Parameter Tags Description
reward_id Required The ID of the reward to be retrieved.

Example Usage:

reward_id = 225

result = rewards.show(reward_id)

Back to List of Controllers

Class: RewardCategories

Get singleton instance

The singleton instance of the RewardCategories class can be accessed from the API Client.

rewardCategories = client.reward_categories

Method: list

List all the available reward categories.

def list(limit = 25,
             offset = 0); end

Parameters:

Parameter Tags Description
limit Optional DefaultValue The number of reward categories you want to be retrieved.
offset Optional DefaultValue The number of reward categories you want to skip before starting the retrieval.

Example Usage:

limit = 25
offset = 0

result = rewardCategories.list(limit, offset)

Back to List of Controllers

Class: Users

Get singleton instance

The singleton instance of the Users class can be accessed from the API Client.

users = client.users

Method: show

This endpoint lets retrieve a user's details.

def show(user_id); end

Parameters:

Parameter Tags Description
user_id Required The ID of the user to be retrieved.

Example Usage:

user_id = 225

result = users.show(user_id)

Method: identify

This endpoint lets you tie a user with his/her activities. You’ll want to identify a user with any relevant information as soon as they log-in or sign-up.

def identify(email,
                 first_name = nil,
                 last_name = nil); end

Parameters:

Parameter Tags Description
email Required The user's email address
first_name Optional The user's first name
last_name Optional The user's last name

Example Usage:

email = 'email'
first_name = 'first_name'
last_name = 'last_name'

result = users.identify(email, first_name, last_name)

Back to List of Controllers

Class: Activities

Get singleton instance

The singleton instance of the Activities class can be accessed from the API Client.

activities = client.activities

Method: track

This endpoint lets you track the activities your users perform.

def track(user_id,
              activity_type,
              price = nil,
              record_id = nil); end

Parameters:

Parameter Tags Description
user_id Required The ID of the user who is performing the activity.
activity_type Required The type of activity the user is performing. Example: 'purchased-a-product'
price Optional The price related to the activity, if any. Expressed in USD
record_id Optional The ID for the record associated with the activity in your database.

Example Usage:

user_id = 225
activity_type = 'activity_type'
price = 225
record_id = 'record_id'

result = activities.track(user_id, activity_type, price, record_id)

Back to List of Controllers

About

Reward Sciences Ruby Gem. Need help? Email us at [email protected]

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages