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
Add to
Gemfile:gem 'zooppa_api_v3'Add to
config/initializers/zooppa_api_v3.rb:
ZOOPPA_API = ZooppaApiV3.new( app_secret: 'app_secret',
app_id: 'app_id'
)
Possible configuration options:
- api_host: specify host of API (default: http://zooppa.com/)
- app_secret: Secret key of the registered Oauth App
- app_id: ID of the registered Oauth App
- encrypt: #authenticate method returns encrypted access token if true (default: true)
- version: specify version of API (default: 'v3')
- iv: the Initialization vector used for encryption (use your Rails secret_key_base here, for instance)
Usage
Authentication:
Both authentication return an access token.
Authenticate a user:
ZOOPPA_API.authenticate_user('[email protected]', 'pass')
Authenticate a client app:
ZOOPPA_API.authenticate_application
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 is 1').execute('token')
Get ads which contest_id attributes equals 1
ZOOPPA_API.awards.where('custom:method_without_params').execute(token)
Call a custom method called method_without_params
ZOOPPA_API.awards.where('custom:method_with_one_param:param1').execute(token)
Call a the custom method method_with_one_param with the parameter param1
ZOOPPA_API.awards.where('custom:method_with_two_params:param1/param2').execute(token)
Call the custom method method_with_two_params with parameters: param1 and param2
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.