Class: QueryInterface::Client::API
- Inherits:
-
Object
- Object
- QueryInterface::Client::API
- Defined in:
- lib/query-interface-client/api.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#options ⇒ Object
Returns the value of attribute options.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ API
constructor
A new instance of API.
- #request(options = {}) ⇒ Object
- #setup_connection(&faraday_block) ⇒ Object
Constructor Details
#initialize(options) ⇒ API
Returns a new instance of API.
13 14 15 16 17 18 |
# File 'lib/query-interface-client/api.rb', line 13 def initialize() if .include?(:url) self.url = .delete(:url) end self. = end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
6 7 8 |
# File 'lib/query-interface-client/api.rb', line 6 def connection @connection end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/query-interface-client/api.rb', line 6 def @options end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/query-interface-client/api.rb', line 6 def url @url end |
Class Method Details
.setup(options = {}, &faraday_block) ⇒ Object
8 9 10 11 |
# File 'lib/query-interface-client/api.rb', line 8 def self.setup(={}, &faraday_block) @default_api = self.new() @default_api.setup_connection(&faraday_block) end |
Instance Method Details
#request(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/query-interface-client/api.rb', line 28 def request(={}) method = .delete(:_method) path = .delete(:_path) headers = .delete(:_headers) response = self.connection.send method do |request| request.headers.merge!(headers) if headers if method == :get # For GET requests, treat additional parameters as querystring data request.url path, else # For POST, PUT and DELETE requests, treat additional parameters as request body request.url path request.body = end end {parsed_data: response.env[:body], response: response} end |
#setup_connection(&faraday_block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/query-interface-client/api.rb', line 20 def setup_connection(&faraday_block) Faraday.new do |connection| self.connection = connection yield connection if block_given? end self end |