Git Product home page Git Product logo

odnoklassniki's Introduction

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)

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

odnoklassniki's People

Contributors

dreikanter avatar gazay avatar yaroslav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

odnoklassniki's Issues

Missed required parameter: access_token

При любом запросе, к примеру client.get('friends.get') выдает ошибку:
Odnoklassniki::Error::ClientError: PARAM : Missed required parameter: access_token
После этого проверяю установки клиента, там действительно отсутствует токен:
<Odnoklassniki::Client:0x007fc3b92c4de8 @access_token=nil, @client_id="*************", @client_secret="*************", @application_key="*********", @refreshed=true, @request=#<Odnoklassniki::Request:0x007fc3b8c92100 @access_token=nil, @client_secret="***********", @application_key="**********">>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.