Class: Luma::Connection
- Inherits:
-
Object
- Object
- Luma::Connection
- Includes:
- HTTParty
- Defined in:
- lib/luma/connection.rb
Direct Known Subclasses
Appointment, AppointmentType, Authentication, Facilities, Patient, Provider
Constant Summary collapse
- DEFAULT_ENDPOINT =
'/endpoint'.freeze
Instance Method Summary collapse
- #add_headers_and_body ⇒ Object
-
#initialize(email: nil, password: nil, headers: {}) ⇒ Connection
constructor
A new instance of Connection.
- #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 = headers @body = nil end |
Instance Method Details
#add_headers_and_body ⇒ Object
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 |