Class: Chaplin::ApiEndpoint
- Inherits:
-
Struct
- Object
- Struct
- Chaplin::ApiEndpoint
- Defined in:
- lib/chaplin/api_endpoint.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(http_method, path, params, headers = {}) ⇒ ApiEndpoint
constructor
A new instance of ApiEndpoint.
- #render(chaplin_request_params) ⇒ Object
Constructor Details
#initialize(http_method, path, params, headers = {}) ⇒ ApiEndpoint
Returns a new instance of ApiEndpoint.
11 12 13 |
# File 'lib/chaplin/api_endpoint.rb', line 11 def initialize(http_method, path, params, headers = {}) super(http_method, path, params || {}, headers) end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers
9 10 11 |
# File 'lib/chaplin/api_endpoint.rb', line 9 def headers @headers end |
#http_method ⇒ Object
Returns the value of attribute http_method
9 10 11 |
# File 'lib/chaplin/api_endpoint.rb', line 9 def http_method @http_method end |
#params ⇒ Object
Returns the value of attribute params
9 10 11 |
# File 'lib/chaplin/api_endpoint.rb', line 9 def params @params end |
#path ⇒ Object
Returns the value of attribute path
9 10 11 |
# File 'lib/chaplin/api_endpoint.rb', line 9 def path @path end |
Class Method Details
.configure(api_url, default_headers, basic_auth) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/chaplin/api_endpoint.rb', line 15 def self.configure(api_url, default_headers, basic_auth) @@client = Faraday.new(url: api_url) do |client| client.adapter Faraday.default_adapter if basic_auth client.basic_auth(basic_auth['user'], basic_auth['password']) end end @@default_headers = default_headers || {} end |
Instance Method Details
#render(chaplin_request_params) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/chaplin/api_endpoint.rb', line 25 def render(chaplin_request_params) full_params = chaplin_request_params.merge(env: ENV) response_body = api_response(full_params).body return nil if (response_body == 'null' or response_body == '') JSON.parse(response_body) end |