punchtab

Ruby wrapper for PunchTab API.

View project onGitHub

punchtab

Ruby wrapper for PunchTab API, the world's first instant loyalty platform.

Installation

gem install punchtab

Prerequisites

  1. Get a developer account at PunchTab.
  2. Make sure your PunchTab account is enabled for SSO authentication. Do so, by going to the developer account page, and checking the 'Single Sign On (SSO)' checkbox.

Enable SSO authentication for PunchTab account

Getting Started

Authenticate using Single Sign On (SSO)

# authenticate with PunchTab
client = Punchtab::Client.new(
  :client_id  => 'your client_id',
  :access_key => 'your access_key',
  :secret_key => 'your secret_key',
  :domain     => 'www.mydomain.com',
  :user_info => {
    :first_name => 'your first_name',
    :last_name  => 'your last_name',
    :email      => 'me@mydomain.com'}
)
# if authentication is successful, you should get an access token back
puts "Access Token: #{client.access_token}"

# if authentication fails, an exception is thrown

Note: You can get all of the above values from your PunchTab developer account page.

Authentication

# check authentication status
client.status
# logout
client.logout

Activity

# get all activities
client.get_activity
# get 2 activities
client.get_activity(:limit => 2)
# get only 'like' activities
client.get_activity(:activity_name => :like)
# create a new activity, and assign it relevant 'points'
client.create_activity(:comment, 600)
# redeem offer for an activity using a 'reward_id'
client.redeem_activity_offer(123)

User

# get details about the current user
client.get_user

Reward

# get all the rewards
client.get_reward
# get specified number of rewards
client.get_reward(:limit => 1)

Leaderboard

# get the current user's leaderboard
client.get_leaderboard
# get the specified user's leaderboard
client.get_leaderboard(111111)
# get leaderboard for current user with optional parameters
client.get_leaderboard(:days => 10, :limit => 3, :page => 1)
# get leaderboard for specified user's leaderboard, with optional parameters
client.get_leaderboard(:with => 111111, :days => 10, :limit => 3, :page => 1)

Contributions

Patches and Pull Requests are most welcome.

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, but do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself, so I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2013 Rupak Ganguly. See LICENSE for details.