class Googl::ClientLogin

Attributes

code[RW]
items[RW]

Public Class Methods

new(email, passwd) click to toggle source

The Google URL Shortener API ClientLogin authentication. See Googl.client

# File lib/googl/client_login.rb, line 11
def initialize(email, passwd)
  modify_headers('Content-Type' => 'application/x-www-form-urlencoded')
  resp = post(API_CLIENT_LOGIN_URL, :body => params.merge!('Email' => email, 'Passwd' => passwd))
  self.code = resp.code
  if resp.code == 200
    token = resp.split('=').last.gsub(/\n/, '')
    modify_headers("Authorization" => "GoogleLogin auth=#{token}")
  else
    raise exception("#{resp.code} #{resp.parsed_response}")
  end
end

Public Instance Methods

history(options={}) click to toggle source

Gets a user’s history of shortened URLs. (Authenticated)

client = Googl.client('user@gmail.com', 'my_valid_password')

history = client.history
history.total_items
=> 19

A list of URL.

history.items

Analytics details for all items

history = client.history(:projection => :analytics_clicks)
# File lib/googl/client_login.rb, line 47
def history(options={})
  resp = (options.nil? || options.empty?) ? get(Googl::Utils::API_HISTORY_URL) : get(Googl::Utils::API_HISTORY_URL, :query => options)
  case resp.code
  when 200
    self.items = resp.parsed_response.to_openstruct
  else
    raise exception("#{resp.code} #{resp.parsed_response}")
  end
end
shorten(url) click to toggle source

Creates a new short URL and thus will gather unique click statistics. It shows up on the user’s dashboard at goo.gl.

See Googl.client

# File lib/googl/client_login.rb, line 27
def shorten(url)
  Googl.shorten(url)
end

Private Instance Methods

params() click to toggle source
# File lib/googl/client_login.rb, line 59
def params
  {'accountType' => 'HOSTED_OR_GOOGLE', 'service' => 'urlshortener', 'source' => 'gem-googl-ruby'}
end