Class: Glomper::Client
- Inherits:
-
Object
- Object
- Glomper::Client
- Extended by:
- Forwardable
- Defined in:
- lib/glomper/client.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
include Users include Places.
-
#client_secret ⇒ Object
readonly
include Users include Places.
-
#oauth_token ⇒ Object
readonly
include Users include Places.
Instance Method Summary collapse
- #api_url ⇒ Object
- #connection ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(meth, *args, &block) ⇒ Object
- #return_error_or_body(response, response_body) ⇒ Object
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(={}) @client_id = [:client_id] @client_secret = [:client_secret] @oauth_token = [:oauth_token] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#client_id ⇒ Object (readonly)
include Users include Places
10 11 12 |
# File 'lib/glomper/client.rb', line 10 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
include Users include Places
10 11 12 |
# File 'lib/glomper/client.rb', line 10 def client_secret @client_secret end |
#oauth_token ⇒ Object (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_url ⇒ Object
27 28 29 |
# File 'lib/glomper/client.rb', line 27 def api_url "http://glomper.com/api" end |
#connection ⇒ Object
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..code == 200 ? response_body : response.body end |