Class: Flydata::ApiClient
- Inherits:
-
Object
- Object
- Flydata::ApiClient
- Includes:
- Singleton
- Defined in:
- lib/flydata/api_client.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize ⇒ ApiClient
constructor
A new instance of ApiClient.
-
#method_missing(cls_name, *args, &block) ⇒ Object
high level api.
-
#post(path, headers = nil, params = nil) ⇒ Object
row level api.
- #put(path, params = nil) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ ApiClient
Returns a new instance of ApiClient.
12 13 14 |
# File 'lib/flydata/api_client.rb', line 12 def initialize @credentials = Flydata::Credentials.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(cls_name, *args, &block) ⇒ Object
high level api
37 38 39 40 41 |
# File 'lib/flydata/api_client.rb', line 37 def method_missing(cls_name, *args, &block) method_name = args.shift.to_s api_cls = "Flydata::Api::#{cls_name.to_s.camelize}".constantize api_cls.new(self) end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
10 11 12 |
# File 'lib/flydata/api_client.rb', line 10 def credentials @credentials end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/flydata/api_client.rb', line 9 def response @response end |
Instance Method Details
#get(path) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/flydata/api_client.rb', line 29 def get(path) uri = generate_auth_url(path) resource = RestClient::Resource.new(uri, resource_opts) @response = resource.get(:accept => :json) handle_response response end |
#post(path, headers = nil, params = nil) ⇒ Object
row level api
17 18 19 20 21 22 |
# File 'lib/flydata/api_client.rb', line 17 def post(path, headers = nil, params=nil) uri = generate_auth_url(path) resource = RestClient::Resource.new(uri, resource_opts(headers)) @response = resource.post(params, :accept => :json) handle_response response end |
#put(path, params = nil) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/flydata/api_client.rb', line 23 def put(path, params=nil) uri = generate_auth_url(path) resource = RestClient::Resource.new(uri, resource_opts) @response = resource.put(params, :accept => :json) handle_response response end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
42 |
# File 'lib/flydata/api_client.rb', line 42 def respond_to_missing?(method_name, include_private=false); true end |