Class: GooglApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/googl-api/client.rb

Instance Method Summary collapse

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(options = {})
  # set api key if provided
  @api_key = { :key => options[:api_key] } if options.has_key?(:api_key)

  # set auth token for client login if provided
  if options[:email] && options[:password] && @token = ClientLogin.authenticate(options[:email], options[:password])
    self.class.headers.merge!("Authorization" => "GoogleLogin auth=#{@token}")
  end
end

Instance Method Details

#analytics(url, projection = "FULL") ⇒ Object

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


32
33
34
35
# File 'lib/googl-api/client.rb', line 32

def expand(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

#historyObject

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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