Class: Googl::ClientLogin
- 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
-
#code ⇒ Object
Returns the value of attribute code.
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
-
#history(options = {}) ⇒ Object
Gets a user’s history of shortened URLs.
-
#initialize(email, passwd) ⇒ ClientLogin
constructor
The Google URL Shortener API ClientLogin authentication.
-
#shorten(url) ⇒ Object
Creates a new short URL and thus will gather unique click statistics.
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
#code ⇒ Object
Returns the value of attribute code.
7 8 9 |
# File 'lib/googl/client_login.rb', line 7 def code @code end |
#items ⇒ Object
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('[email protected]', '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(={}) resp = (.nil? || .empty?) ? get(Googl::Utils::API_HISTORY_URL) : get(Googl::Utils::API_HISTORY_URL, :query => ) case resp.code when 200 self.items = resp.parsed_response.to_openstruct else raise exception("#{resp.code} #{resp.parsed_response}") end end |