ZooppaApiV3

TODO: Write a gem description

Installation

Add this line to your application's Gemfile:

gem 'zooppa_api_v3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install zooppa_api_v3

Requirements & Limitations

Requires ruby 2.0 or greater and works only with API V3.

Installation & Setup

  1. Add to Gemfile: gem 'zooppa_api_v3'

  2. Add to config/initializers/zooppa_api_v3.rb:

ZOOPPA_API = ZooppaApiV3.new( app_secret: 'app_secret',
                            app_id: 'app_id'
                          )

Possible configuration options:

  1. api_host: specify host of API (default: http://zooppa.com/)
  2. app_secret: Secret key of the registered Oauth App
  3. app_id: ID of the registered Oauth App
  4. encrypt: #authenticate method returns encrypted access token if true (default: true)
  5. version: specify version of API (default: 'v3')
  6. iv: the Initialization vector used for encryption (use your Rails secret_key_base here, for instance)

Usage

Authentication:

ZOOPPA_API.authenticate('[email protected]', 'pass')

If authentication was successful, it returns the access token (encrypted if encrypt is set to true) or returns JSON with an error key and message.

Find a resource

ZOOPPA_API.ads.find(1).execute('token')

Find ad with id 1

ZOOPPA_API.contests.find(1).execute('token')

Find contest with id 1

Get collection of a resource

ZOOPPA_API.contests.execute('token')

Gets the first 10 contests

Pagination

ZOOPPA_API.contests.page(2).per_page(100).execute('token')

Get 100 contests with offset 100

Filtering

ZOOPPA_API.ads.where('contest_id,=,1').execute('token')

Get ads which contest_id attributes equals 1

ZOOPPA_API.ads.where('contest_id,=,1', 'resource_type,=,video').execute('token')

Get ads which contest_id attributes equals 1 and resource_type equals 'video'

Sorting

ZOOPPA_API.ads.sort('title ASC').execute('token')

Sort ads by title ascending

Combine filtering, sorting and pagination

ZOOPPA_API.ads.where('contest_id,=,1', 'resource_type,=,video').sort('title DESC').page(2).per_page(9)execute('token')

Delete a resource

ZOOPPA_API.users.find(1).delete.execute('token')

Update a resource

ZOOPPA_API.users.find(1).update_attributes({user: { name: 'new' }}).execute('token')

Create a resource

ZOOPPA_API.users.create({user: { name: 'new' }}).execute('token')

General

If the request you make requires authentication, you need to pass in the token into the .execute method. If authentication is not needed, you don't need to pass in any argument.