Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reward_sciences

Package Overview
Dependencies
Maintainers
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reward_sciences

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
3
Created
Source

Getting Started

How to Build

This client library is a Ruby gem which can be compiled and used in your Ruby and Ruby on Rails project. This library requires a few gems from the RubyGems repository.

  1. Open the command line interface or the terminal and navigate to the folder containing the source code.
  2. Run gem build reward_sciences.gemspec to build the gem.
  3. Once built, the gem can be installed on the current work environment using gem install reward_sciences-1.0.gem

![Building Gem](http://apidocs.io/illustration/ruby?step=buildSDK&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

How to Use

The following section explains how to use the RewardSciences Ruby Gem in a new Rails project using RubyMine™. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

1. Starting a new project

Close any existing projects in RubyMine™ by selecting File -> Close Project. Next, click on Create New Project to create a new project from scratch.

![Create a new project in RubyMine](http://apidocs.io/illustration/ruby?step=createNewProject0&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

Next, provide TestApp as the project name, choose Rails Application as the project type, and click OK.

![Create a new Rails Application in RubyMine - step 1](http://apidocs.io/illustration/ruby?step=createNewProject1&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

In the next dialog make sure that correct Ruby SDK is being used (minimum 2.0.0) and click OK.

![Create a new Rails Application in RubyMine - step 2](http://apidocs.io/illustration/ruby?step=createNewProject2&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

This will create a new Rails Application project with an existing set of files and folder.

2. Add reference of the gem

In order to use the RewardSciences gem in the new project we must add a gem reference. Locate the Gemfile in the Project Explorer window under the TestApp project node. The file contains references to all gems being used in the project. Here, add the reference to the library gem by adding the following line: gem 'reward_sciences', '~> 1.0'

![Add references of the Gemfile](http://apidocs.io/illustration/ruby?step=addReference&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

3. Adding a new Rails Controller

Once the TestApp project is created, a folder named controllers will be visible in the Project Explorer under the following path: TestApp > app > controllers. Right click on this folder and select New -> Run Rails Generator....

![Run Rails Generator on Controllers Folder](http://apidocs.io/illustration/ruby?step=addCode0&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

Selecting the said option will popup a small window where the generator names are displayed. Here, select the controller template.

![Create a new Controller](http://apidocs.io/illustration/ruby?step=addCode1&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

Next, a popup window will ask you for a Controller name and included Actions. For controller name provide Hello and include an action named Index and click OK.

![Add a new Controller](http://apidocs.io/illustration/ruby?step=addCode2&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

A new controller class anmed HelloController will be created in a file named hello_controller.rb containing a method named Index. In this method, add code for initialization and a sample for its usage.

![Initialize the library](http://apidocs.io/illustration/ruby?step=addCode3&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0)

How to Test

You can test the generated SDK and the server with automatically generated test cases as follows:

  1. From terminal/cmd navigate to the root directory of the SDK.
  2. Invoke: bundle exec rake

Initialization

Authentication and Initialization

In order to setup authentication and initialization of the API client, you need the following information.

ParameterDescription
o_auth_access_tokenThe OAuth 2.0 access token to be set before API calls

API client can be initialized as following.

# Configuration parameters and credentials
o_auth_access_token = "o_auth_access_token"; # The OAuth 2.0 access token to be set before API calls

client = RewardSciences::RewardSciencesClient.new(o_auth_access_token)

The added initlization code can be debugged by putting a breakpoint in the Index method and running the project in debug mode by selecting Run -> Debug 'Development: TestApp'.

![Debug the TestApp](http://apidocs.io/illustration/ruby?step=addCode4&workspaceFolder=Reward Sciences-Ruby&workspaceName=RewardSciences&projectName=reward_sciences&gemName=reward_sciences&gemVer=1.0&initLine=client%20%3D%20RewardSciencesClient.new%28%27o_auth_access_token%27%29)

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:
ParameterTagsDescription
user_idRequiredThe ID of the user who is bidding on the reward auction.
reward_idRequiredThe ID of the reward auction to be bid on.
amountRequiredCan 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:
ParameterTagsDescription
category_idOptionalThe id of the category to filter rewards by
limitOptional DefaultValueThe number of rewards you want to be retrieved.
offsetOptional DefaultValueThe 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:
ParameterTagsDescription
user_idRequiredThe ID of the user who is redeeming the reward.
reward_idRequiredThe 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:
ParameterTagsDescription
reward_idRequiredThe 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:
ParameterTagsDescription
limitOptional DefaultValueThe number of reward categories you want to be retrieved.
offsetOptional DefaultValueThe 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:
ParameterTagsDescription
user_idRequiredThe 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:
ParameterTagsDescription
emailRequiredThe user's email address
first_nameOptionalThe user's first name
last_nameOptionalThe 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:
ParameterTagsDescription
user_idRequiredThe ID of the user who is performing the activity.
activity_typeRequiredThe type of activity the user is performing. Example: 'purchased-a-product'
priceOptionalThe price related to the activity, if any. Expressed in USD
record_idOptionalThe 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

FAQs

Package last updated on 26 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc