class Shortly::Clients::ShortSwitch

Attributes

apiKey[RW]

Public Class Methods

shorten(url, options = {}) click to toggle source

shorts provided url by making call to is.gd api with given options.

# File lib/shortly/clients/shortswitch.rb, line 37
def self.shorten(url, options = {})
  validate_uri!(url)
  options = {:apiKey => self.apiKey, :format => :json, :longUrl => url}.merge(options)
  validate!(options)
  response = get("/shorten", get_params(options))
  OpenStruct.new(response['results'][url])
end

Private Class Methods

validate!(options) click to toggle source
# File lib/shortly/clients/shortswitch.rb, line 47
def self.validate!(options)
  raise NotAuthorizedError.new("Credentials required(apiKey)") unless 
    options.authenticable?(:apiKey)
end