Class: Luma::Connection
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/luma/connection.rb
Constant Summary
collapse
- DEFAULT_ENDPOINT =
'/endpoint'.freeze
Instance Method Summary
collapse
-
#add_header ⇒ Object
-
#initialize(email: nil, password: nil, headers: {}) ⇒ Connection
constructor
A new instance of Connection.
-
#luma_request(auth:, body:, endpoint:, verb:, identifier: nil) ⇒ Object
-
#request(endpoint: DEFAULT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post) ⇒ Object
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 =
@body = nil
end
|
Instance Method Details
27
28
29
|
# File 'lib/luma/connection.rb', line 27
def
@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. 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)
= .merge() if auth
self.class.send("#{verb}", endpoint, body: body, headers: )
end
|