Class: Chaplin::ApiEndpoint

Inherits:
Struct
  • Object
show all
Defined in:
lib/chaplin/api_endpoint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



9
10
11
# File 'lib/chaplin/api_endpoint.rb', line 9

def headers
  @headers
end

#http_methodObject

Returns the value of attribute http_method

Returns:

  • (Object)

    the current value of http_method



9
10
11
# File 'lib/chaplin/api_endpoint.rb', line 9

def http_method
  @http_method
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



9
10
11
# File 'lib/chaplin/api_endpoint.rb', line 9

def params
  @params
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of 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