Odnoklassniki is a Ruby wrapper for the Odnoklassniki social network API.
At the moment, it is just a simple wrapper for GET and POST requests for Odnoklassniki API.
This gem is widely used by Amplifr social media management tool and is currently under development.
You can install the gem via RubyGems:
gem install odnoklassniki
Or by using Bundler: put
gem 'odnoklassniki'
in your Gemfile
.
To use Odnoklassniki API methods you should have "VALUABLE ACCESS" to Odnoklassniki.
When using the gem with a Ruby on Rails application, you can configure Odnoklassniki globally by creating an 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 a Config
object and feed it to the Odnoklassniki
module:
config = Odnoklassniki::Config.configure do |c|
# ...
end
Odnoklassniki.config = config
Also, when creating a new Odnoklassniki::Client
, you can pass along all required (or missing from the configuration step) options right there:
Odnoklassniki::Client.new(access_token: 'your token', client_id: 'your client id')
client = Odnoklassniki::Client.new(access_token: token, refresh_token: refresh_token)
new_token = client.refresh_token! # This method will be called automatically just once
# for each client before performing the request
client.get('friends.get')
client.get('friends/get')
client.get('api/friends/get')
client.get('/api/friends/get')
# NOTE: All GET requests above are identical!
client.post('mediatopic.post', type: 'USER_STATUS', attachment: attachment)
Unfortunately, most errors from Odnoklassniki API are returned within a success response (200 HTTP status code). So, there is a wrapper just for that in this gem:
begin
client.get('some.wrong.request')
rescue Odnoklassniki::Error::ClientError => e
e.inspect
end
Also there is a bunch of client/server error classes whose structure was gratefully copied and adopted from @sferik's twitter gem. They can be useful in case when Odnoklassniki API wasn't reached at all or when some other issue has occured.
- Wrap some usual methods like
users.getCurrentUser
,mediatopic.post
etc. - Write tests with real credentials
- 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
- @gazay