Class: Glomper::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/glomper/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# File 'lib/glomper/client.rb', line 12

def initialize(options={})
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @oauth_token = options[:oauth_token]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/glomper/client.rb', line 18

def method_missing(meth, *args, &block)
  m = meth.to_s.capitalize.to_sym
  if Glomper::API[m]
    Glomper::Request.new(self, Glomper::API[m], *args, &block)
  else
    super
  end
end

Instance Attribute Details

#client_idObject (readonly)

include Users include Places



10
11
12
# File 'lib/glomper/client.rb', line 10

def client_id
  @client_id
end

#client_secretObject (readonly)

include Users include Places



10
11
12
# File 'lib/glomper/client.rb', line 10

def client_secret
  @client_secret
end

#oauth_tokenObject (readonly)

include Users include Places



10
11
12
# File 'lib/glomper/client.rb', line 10

def oauth_token
  @oauth_token
end

Instance Method Details

#api_urlObject



27
28
29
# File 'lib/glomper/client.rb', line 27

def api_url
  "http://glomper.com/api"
end

#connectionObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/glomper/client.rb', line 35

def connection
  params = {}
  params[:client_id] = @client_id if @client_id
  params[:client_secret] = @client_secret if @client_secret
  params[:access_token] = @oauth_token if @oauth_token
  @connection ||= Faraday::Connection.new(:url => api_url, :params => params, :headers => default_headers) do |builder|
    builder.adapter Faraday.default_adapter
    builder.use Faraday::Response::Mashify
    builder.use Faraday::Response::ParseJson
  end
end

#return_error_or_body(response, response_body) ⇒ Object



31
32
33
# File 'lib/glomper/client.rb', line 31

def return_error_or_body(response, response_body)
  response.body.meta.code == 200 ? response_body : response.body
end