Odnoklassniki
Ruby wrapper for Odnoklassniki API
Right now it is a simple wrapper on get and post requests to Odnoklassniki api.
This gem widely used in Amplifr and currently being developed
Installation
gem install odnoklassniki
Usage
To use odnoklassniki api methods you should have VALUABLE ACCESS to odnoklassniki.
Configuration
You can create global configuration for your application. Create initializer config/initializers/ok_api.rb
:
Odnoklassniki.configure do |c|
c.application_key = 'You application key'
c.client_id = 'Your client id'
c.client_secret = 'Your client secret'
end
Or you can create config object and feed it to Odnoklassniki
module:
config = Odnoklassniki::Config.configure do |c|
...
end
Odnoklassniki.config = config
Also, when you create new Odnoklassniki::Client
you can pass all needed (or missed on configuration step) options right there:
Odnoklassniki::Client.new(access_token: 'your token', client_id: 'your client id')
Example
client = Odnoklassniki::Client.new(access_token: token)
new_token = client.refresh_token! # This method will be called automaticaly just once
# for each client before performing request
client.get('friends.get')
client.get('friends/get')
client.get('api/friends/get')
client.get('/api/friends/get')
# All get requests above identical
client.post('mediatopic.post', type: 'USER_STATUS', attachment: )
Error handling
Most of errors from Odnoklassniki API retruned in success response (with status code 200). So there is a wrapper for it in this gem:
begin
client.get('some.wrong.request')
rescue Odnoklassniki::Error::ClientError => e
e.inspect
end
Also there are bunch of client/server error classes which structure was gratefully copied and adopted from @sferik's twitter gem. They can be useful when Odnoklassniki API wasn't reached or when some other issue occured.
TODO
- Wrap some usual methods like
users.getCurrentUser
,mediatopic.post
etc. - Write tests with real credentials
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Contributors
- @gazay
Special thanks to @Strech, @igas.
License
The MIT License