Gamifier

This gem abstracts the Badgeville API behind high level concepts such as user, player, activities, rewards, etc.

Installation

Add this line to your application's Gemfile:

gem 'gamifier'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gamifier

Usage

Configure Gamifier with the right parameter for the API you're using:

Gamifier.set :key => "1234", :uri => "http://sandbox.v2.badgeville.com/api/berlin/"

Gamifier support the last version of Badgeville API using enterprise api key:

Gamifier.set :key => '1234', :uri => "http://sandbox.v2.badgeville.com/api/berlin/", :enterprise_key => '5678'

Note that you have to specify either a private API key or an enterprise API key.

Then here is an example usage to credit an existing player:

Gamifier.engine do |engine|
  player = engine.players.find_by_site_and_email('my-site.com', '[email protected]')
  player.credit('visit', :url => "http://server.ltd/page.html", :other_key => "value")
end

See the examples/ directory for examples on how to use the DSL to declare activities, rewards and missions, and you can execute a DSL as follows:

BADGEVILLE_KEY=xzy bundle exec ruby -I lib examples/dev.rb

Create Network using the DSL

Since the new Badgeville API, you can create new Network and API Keys using the Badgeville API. We updated the DSL for you:

network = Gamifier.dsl do
  set :label, 'MyNetwork'
  set :email, '[email protected]'

  api_key do
    set :access, 'public'
  end

  api_key do
    set :access, 'private'
  end

  site 'foo' do
    # as usual here
  end
end

To only save the network on Badgeville do:

network.save_network!

To only save the sites, behaviors, rewards, etc do:

network.save!

If you want to create a new Network and create Sites, Behaviors, Rewards, etc on that new Network, you'll need the network's private API key.

api_key do
  set :access, 'private'
end

These lines will create a new Private API key on current network. You'll need to:

  1. Create and Save the network: network.save_network!
  2. Create and Save the sites, behaviors and so on: network.save!

network.save! will use by default the new private API key if any, otherwise it will fallback to Gamifier's config.

Tests

Run the unit tests with:

bundle exec rspec spec/unit

Run the integration tests as follows:

BADGEVILLE_KEY=1234 bundle exec rspec spec/integration

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request on Github

Authors

Contributors