class Shortly::Clients::Googl

Attributes

apiKey[RW]

apiKey = “<your apiKey>”

Public Class Methods

analytics(url, options ={}) click to toggle source
# File lib/shortly/clients/googl.rb, line 49
def self.analytics(url, options ={})
  validate_uri!(url)
  info(options.merge(:shortUrl => url), true)
end
expand(url, options ={}) click to toggle source
# File lib/shortly/clients/googl.rb, line 44
def self.expand(url, options ={})
  validate_uri!(url)
  info(options.merge(:shortUrl => url))
end
shorten(url, options = {}) click to toggle source

shorts provided url by making call to goo.gl api with given options.

# File lib/shortly/clients/googl.rb, line 38
def self.shorten(url, options = {})
  validate_uri!(url)
  response = post(relative_path_with_key(options), post_params({:longUrl => url}.to_json))
  OpenStruct.new(response.merge(:shortUrl => response["id"]))
end

Private Class Methods

info(options, full = false) click to toggle source
# File lib/shortly/clients/googl.rb, line 64
def self.info(options, full = false)
  options.merge!({:projection => 'FULL'}) if full
  options.merge!({:key => self.apiKey}) if !!self.apiKey
  response = get(relative_path, get_params(options))
  OpenStruct.new(response)
end
relative_path() click to toggle source
# File lib/shortly/clients/googl.rb, line 56
def self.relative_path
  "/urlshortener/v1/url"
end
relative_path_with_key(options) click to toggle source
# File lib/shortly/clients/googl.rb, line 60
def self.relative_path_with_key(options)
  self.apiKey ? [relative_path, {:key => self.apiKey}.to_params].join("?") : relative_path
end