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_headers_and_bodyObject



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

def add_headers_and_body
  @body = @body.to_json
  @headers = auth_header.merge(@headers)
  @headers["Content-Type"] = 'application/json'
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