Class: GooglApi::Client
- Inherits:
-
Object
- Object
- GooglApi::Client
- Includes:
- HTTParty
- Defined in:
- lib/googl-api/client.rb
Instance Method Summary collapse
- #analytics(url, projection = "FULL") ⇒ Object
- #expand(url) ⇒ Object
- #history ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #shorten(url) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 |
# File 'lib/googl-api/client.rb', line 17 def initialize( = {}) # set api key if provided @api_key = { :key => [:api_key] } if .has_key?(:api_key) # set auth token for client login if provided if [:email] && [:password] && @token = ClientLogin.authenticate([:email], [:password]) self.class.headers.merge!("Authorization" => "GoogleLogin auth=#{@token}") end end |
Instance Method Details
#analytics(url, projection = "FULL") ⇒ Object
37 38 39 40 |
# File 'lib/googl-api/client.rb', line 37 def analytics(url, projection = "FULL") raise ArgumentError.new("A URL to check analytics on is required") if url.blank? load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url, :projection => projection }))) end |
#expand(url) ⇒ Object
32 33 34 35 |
# File 'lib/googl-api/client.rb', line 32 def (url) raise ArgumentError.new("A URL to expand is required") if url.blank? load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url }))) end |
#history ⇒ Object
42 43 44 45 |
# File 'lib/googl-api/client.rb', line 42 def history raise ArgumentError.new("Doing a history search requires a Client Login (or eventually OAuth to be set)") unless @token self.class.get('/url/history') end |
#shorten(url) ⇒ Object
27 28 29 30 |
# File 'lib/googl-api/client.rb', line 27 def shorten(url) raise ArgumentError.new("A URL to shorten is required") if url.blank? load_respose(self.class.post('/url', :query => @api_key, :body => "{ \"longUrl\": \"#{url}\" }")) end |