class GoogleShortLinks::Client

Client for Google Short Links.

Examples

client = GoogleShortLinks::Client.new :server => 'short.example.com', :secret => 'abcdef1234567890', :email => 'ben@example.com'
link = client.get_or_create_hash 'http://example.com/parent/child/long_document_name.html', :is_public => true
link # => {"status"=>"ok", "url"=>"http://example.com/parent/child/long_document_name.html", "estimated_api_calls_remaining"=>98, "shortcut"=>"abc12", "usage_count"=>0, "owner"=>"ben@example.com", "is_public"=>true, "is_hash"=>true}

Attributes

email[RW]

The email for the account under which the links will be created.

secret[RW]

Your HMAC-SHA1 secret.

server[RW]

The domain name where Google Short Links is hosted.

Public Class Methods

new(options={}) click to toggle source

Initializes a new Client.

Parameters

options

Optional Hash containing configuration values.

Options

:server

The domain name where Google Short Links is hosted.

:secret

Your HMAC-SHA1 secret.

:email

The email for the account under which the links will be created.

# File lib/google_short_links/client.rb, line 44
def initialize options={}
  self.server = options[:server]
  self.secret = options[:secret]
  self.email = options[:email]
end

Public Instance Methods

get_details(shortcut, params={}) click to toggle source

Gets details about a link from its shortcut.

Parameters

shortcut

Required String containing the URL to be shortened.

params

Optional Hash that will add or override GET parameters in the URL.

Examples

link = client.get_details 'example'
link # => {"status"=>"ok", "url"=>"http://example.com/parent/child/long_document_name.html", "estimated_api_calls_remaining"=>100, "shortcut"=>"example", "usage_count"=>0, "owner"=>"ben@example.com", "is_public"=>true, "is_hash"=>false}
# File lib/google_short_links/client.rb, line 170
def get_details shortcut, params={}
  self.class.get(get_details_url(shortcut, params)).parsed_response
end
get_details_url(shortcut, params={}) click to toggle source

Creates a URL that is used to get details about a link from its shortcut.

Parameters

shortcut

Required String containing the URL to be shortened.

params

Optional Hash that will add or override GET parameters in the URL.

Examples

link_url = client.get_details_url 'example'
link_url # => "http://short.example.com/js/get_details?oauth_signature_method=HMAC-SHA1&shortcut=example&timestamp=1321663629.0&user=ben%40example.com&oauth_signature=p8XqzF0lITupKN3Ta0qu2E8hqBI%3D"
# File lib/google_short_links/client.rb, line 110
def get_details_url shortcut, params={}
  request_path = request_path(:get_details)

  query = params_to_query(base_params.merge(:shortcut => shortcut).merge(params))

  digest_url(request_path, query)
end
get_or_create_hash(url, params={}) click to toggle source

Shortens a URL.

Parameters

url

Required String containing the URL to be shortened.

params

Optional Hash that will add or override GET parameters in the URL.

Parameters

:is_public

Boolean for whether or not the short link can be accessed without logging in to Google Apps.

Examples

link = client.get_or_create_hash 'http://example.com/parent/child/long_document_name.html', :is_public => true
link # => {"status"=>"ok", "url"=>"http://example.com/parent/child/long_document_name.html", "estimated_api_calls_remaining"=>98, "shortcut"=>"abc12", "usage_count"=>0, "owner"=>"ben@example.com", "is_public"=>true, "is_hash"=>true}
# File lib/google_short_links/client.rb, line 134
def get_or_create_hash url, params={}
  self.class.get(get_or_create_hash_url(url, params)).parsed_response
end
get_or_create_hash_url(url, params={}) click to toggle source

Creates a URL that is used to create a hash.

Parameters

url

Required String containing the URL to be shortened.

params

Optional Hash that will add or override GET parameters in the URL.

Parameters

:is_public

Boolean for whether or not the short link can be accessed without logging in to Google Apps.

Examples

link_url = client.get_or_create_hash_url 'http://example.com/parent/child/long_document_name.html', :is_public => true
link_url # => "http://short.example.com/js/get_or_create_hash?is_public=true&oauth_signature_method=HMAC-SHA1&timestamp=1321663459.0&url=http%3A%2F%2Fexample.com%2Fparent%2Fchild%2Flong_document_name.html&user=ben%40example.com&oauth_signature=JElQ0Oq59q%2BOsinYuMzGX%2F8Tn2U%3D"
# File lib/google_short_links/client.rb, line 66
def get_or_create_hash_url url, params={}
  request_path = request_path(:get_or_create_hash)

  query = params_to_query(base_params.merge(:url => url).merge(params))

  digest_url(request_path, query)
end