Project

ok_linker

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Ruby gem for Odnoklassniki's URL shortening service okey.link.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
= 0.10.3
~> 10.4
~> 3.4
>= 3.0.0, ~> 3.0
~> 1.22

Runtime

 Project Readme

OkLinker

Gem Version Build Status Code Climate

Ruby gem to work with Odnoklassniki's URL shortening service okey.link. Tested against Ruby 2.0, 2.1, 2.2 and 2.3.

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 (c) 2016 Ilya Bodrov