OkLinker

Ruby gem to work with Odnoklassniki’s URL shortening service okey.link. Tested against Ruby 1.9.3, 2.0, 2.1, 2.2, jRuby and rbx.

Installation

Via RubyGems:

$ gem install ok_linker

Or add it to your Gemfile:

gem 'ok_linker'

Usage

Prerequisites

First of all, you will require access to okey.link. Fill in this submission form to gain access.

After logging in, copy your API access token from the API section. This token has unlimited lifetime and has to be stored securely.

Instantiating a Client

Create a new client by typing

client = OkLinker::Client.new(opts)

or simply with

client = OkLinker.new(opts)

You can now call OkLinker’s methods.

Configuration

OkLinker does not require much configuration. The only thing that you need to provide is your access token. You can either use an initializer (for example, ok_linker.rb):

OkLinker.configure do |c|
  c.access_token = 'Your token'
end

or provide it when instantiating a new client:

client = OkLinker::Client.new(access_token: 'Your token')

Calling methods

You can read more about available methods here.

OkLinker provides the following conventional methods:

shorten(url)        # Shorten a given URL

hide(url)           # Hide a URL that was previously shorten

clicks(url)         # Get clicks statistics for the given URL

urls(params)        # Get a list of shortened URLs.
                    # Allowed options:
                    ## :epp  - integer, optional. Elements per page. Default is 20.
                    ## :page - integer, optional. Page to fetch. Default is 1.

Also, you can call raw methods:

get(method, params = {}, &block)

post(method, params = {}, &block)

For example,

client.get('get-urls', page: 2)

These methods always return JSON or one of the errors listed here.

Testing

Rename .env.sample to .env and assign OKEY_LINK_KEY to your API key. This file is excluded from version control, so your token won’t be exposed.

Then run

$ bundle exec rspec .

License

Licensed under the MIT License.

Copyright © 2015 Ilya Bodrov