Ruby gem to work with Odnoklassniki's URL shortening service okey.link. Tested against Ruby 2.0, 2.1, 2.2 and 2.3.
Via RubyGems:
$ gem install ok_linker
Or add it to your Gemfile
:
gem 'ok_linker'
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.
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.
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')
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.
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 .
Licensed under the MIT License.
Copyright (c) 2016 Ilya Bodrov