Skip to content

byteg/odnoklassniki

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Odnoklassniki

Build Status CodeClimate

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.

Amplifr Sponsored by Evil Martians

Installation

You can install the gem via RubyGems:

gem install odnoklassniki

Or by using Bundler: put

gem 'odnoklassniki'

in your Gemfile.

Usage

To use Odnoklassniki API methods you should have "VALUABLE ACCESS" to Odnoklassniki.

Configuration

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')

Example

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)

Error Handling

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.

TODO

  1. Wrap some usual methods like users.getCurrentUser, mediatopic.post etc.
  2. Write tests with real credentials

Contributing

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

Contributors

  • @gazay

Special thanks to @strech, @igas.

License

The MIT License

About

Ruby wrapper for Odnoklassniki API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%