Class: Luma::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/luma/connection.rb

Constant Summary collapse

DEFAULT_ENDPOINT =
'/endpoint'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(email: nil, password: nil, headers: {}) ⇒ Connection

Returns a new instance of Connection.



13
14
15
16
17
18
# File 'lib/luma/connection.rb', line 13

def initialize(email: nil, password: nil, headers: {})
  @email = email
  @password = password
  @headers = headers
  @body = nil
end

Instance Method Details

#add_headerObject



27
28
29
# File 'lib/luma/connection.rb', line 27

def add_header
  @headers["Content-Type"] = 'application/json'
end

#luma_request(auth:, body:, endpoint:, verb:, identifier: nil) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/luma/connection.rb', line 31

def luma_request(auth:, body:, endpoint:, verb:, identifier: nil)
  @body = body
  self.add_header if auth

  endpoint = "#{endpoint}/#{identifier}" unless identifier.nil?

  Luma::ResponseData.new(response: self.request(endpoint: endpoint, body: @body, headers: @headers, auth: auth, verb: verb))
end

#request(endpoint: DEFAULT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post) ⇒ Object



20
21
22
23
24
25
# File 'lib/luma/connection.rb', line 20

def request(endpoint: DEFAULT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post)
  body    = body.to_json if body.is_a?(Hash)
  headers = auth_header.merge(headers) if auth

  self.class.send("#{verb}", endpoint, body: body, headers: headers)
end