Class: Googl::ClientLogin

Inherits:
Object show all
Includes:
Utils
Defined in:
lib/googl/client_login.rb

Constant Summary

Constants included from Utils

Utils::API_CLIENT_LOGIN_URL, Utils::API_HISTORY_URL, Utils::API_URL, Utils::SCOPE_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, passwd) ⇒ ClientLogin

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



11
12
13
14
15
16
17
18
19
20
21
# 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

Instance Attribute Details

#codeObject

Returns the value of attribute code



7
8
9
# File 'lib/googl/client_login.rb', line 7

def code
  @code
end

#itemsObject

Returns the value of attribute items



7
8
9
# File 'lib/googl/client_login.rb', line 7

def items
  @items
end

Instance Method Details

#history(options = {}) ⇒ Object

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)


47
48
49
50
51
52
53
54
55
# 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) ⇒ Object

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



27
28
29
# File 'lib/googl/client_login.rb', line 27

def shorten(url)
  Googl.shorten(url)
end