luma 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f722a4bfdbfbdc81d2e9b85e52c8dd78aef2fdd64df668be3424bcbec766876d
4
- data.tar.gz: 21be1a31248e6787d5b2b6a272a5d0ef424dcc01564a5a6e2942a880a4108014
3
+ metadata.gz: 3d3915bbf6dc23b7c8cd06e63ac1e36c6b3a3930f654c9307920dd55077f15b0
4
+ data.tar.gz: 8852faa9418bbbe6fb3e2b5b8cd9ecfdc91a6349ce298060642667d545ed7473
5
5
  SHA512:
6
- metadata.gz: 6cfc178b60a519cfe2fec7d61c0aa26e410e5a47dc2c743239cfeb275f97548366ea7e61961cad3d1495df2696e6c66421126f1a98200963c855291cf1653fe1
7
- data.tar.gz: d39c57e2e8c78fe22f425fdbf560691907f308b4ae2e4e4553f5f4b362dbc4fc07e1f83ea4d42bc452adfb95e9b5af3470343073e83d6f6b618917ec7fc084c5
6
+ metadata.gz: 8f5724cf37277996895d9646d4c8e6b5a46411668034b788078e829583781c13742687bf877d6d33808b6d21fe79fe826260adf64a1c8299070f224ccd4f6c43
7
+ data.tar.gz: 901b3c31e7e98a055136a9ed8d88674735a5a2d92b42e3d49b5c8ebd99491e43b4ee14716b6e6fdcce69c79c4a85b492b0e3b9529df0f4974d4a32971f5b5fdc
data/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.1] - 2022-05-17
8
+
9
+ ### Changed
10
+
11
+ - Removed default value for the property active on contact model
12
+
13
+ ## [0.2.0] - 2022-05-04
14
+
15
+ ### Added
16
+ - Luma::ResponseData object with recommend_retry? method
17
+
18
+ ### Changed
19
+ - Updated requests to return Luma::ResponseData object
20
+
21
+ ## [0.1.4] - 2022-02-15
22
+
23
+ ### Changed
24
+
25
+ - Authentication accounts for token expiration
26
+ - Connection memoizes authentication
27
+
6
28
  ## [0.1.3] - 2022-02-10
7
29
 
8
30
  ### Changed
@@ -80,6 +102,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
80
102
 
81
103
  - Initial Create
82
104
 
105
+ [0.2.1]: https://github.com/WeInfuse/luma/compare/v0.2.0...v0.2.1
106
+ [0.2.0]: https://github.com/WeInfuse/luma/compare/v0.1.4...v0.2.0
107
+ [0.1.4]: https://github.com/WeInfuse/luma/compare/v0.1.3...v0.1.4
83
108
  [0.1.3]: https://github.com/WeInfuse/luma/compare/v0.1.2...v0.1.3
84
109
  [0.1.2]: https://github.com/WeInfuse/luma/compare/v0.1.1...v0.1.2
85
110
  [0.1.1]: https://github.com/WeInfuse/luma/compare/v0.1.0...v0.1.1
@@ -1,23 +1,15 @@
1
1
  module Luma
2
2
  class Appointment < Connection
3
- APPOINTMENT_ENDPOINT = '/api/appointments'.freeze
3
+ APPOINTMENT_ENDPOINT = '/api/appointments'.freeze
4
4
 
5
- base_uri 'https://api.lumahealth.io/'.freeze
5
+ base_uri 'https://api.lumahealth.io/'.freeze
6
6
 
7
- def create_appointment(endpoint: APPOINTMENT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
8
- @body = body
9
- self.add_headers_and_body if auth
7
+ def create_appointment(endpoint: APPOINTMENT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
8
+ luma_request(auth: auth, body: body, endpoint: endpoint, verb: verb)
9
+ end
10
10
 
11
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers)
12
- end
13
-
14
- def update_appointment(appt_identifier, endpoint: APPOINTMENT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :put, debug_output: $stdout)
15
- @body = body
16
- self.add_headers_and_body if auth
17
-
18
- endpoint = "#{endpoint}/#{appt_identifier}"
19
-
20
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers)
21
- end
11
+ def update_appointment(appt_identifier, endpoint: APPOINTMENT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :put, debug_output: $stdout)
12
+ luma_request(auth: auth, body: body, endpoint: endpoint, identifier: appt_identifier, verb: :put)
13
+ end
22
14
  end
23
15
  end
@@ -1,23 +1,20 @@
1
1
  module Luma
2
- class AppointmentType < Connection
3
- APPOINTMENT_TYPE_ENDPOINT = '/api/appointmentTypes'.freeze
2
+ class AppointmentType < Connection
3
+ APPOINTMENT_TYPE_ENDPOINT = '/api/appointmentTypes'.freeze
4
4
 
5
- base_uri 'https://api.lumahealth.io/'.freeze
5
+ base_uri 'https://api.lumahealth.io/'.freeze
6
6
 
7
- def view_appointment_types(endpoint: APPOINTMENT_TYPE_ENDPOINT, auth: true, name: nil, description: nil, debug_output: $stdout)
8
- self.add_headers_and_body if auth
7
+ def view_appointment_types(endpoint: APPOINTMENT_TYPE_ENDPOINT, auth: true, name: nil, description: nil, debug_output: $stdout)
8
+ self.add_header if auth
9
9
 
10
- url = "api/appointmentTypes?name=#{name}&description=#{description}"
11
- full_url = "https://api.lumahealth.io/" + url
10
+ url = "api/appointmentTypes?name=#{name}&description=#{description}"
11
+ full_url = "https://api.lumahealth.io/" + url
12
12
 
13
- HTTParty.get(full_url.to_str, headers: @headers, debug_output: $stdout)
14
- end
13
+ HTTParty.get(full_url.to_str, headers: @headers, debug_output: $stdout)
14
+ end
15
15
 
16
- def create_appointment_type(endpoint: APPOINTMENT_TYPE_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
17
- @body = body
18
- self.add_headers_and_body if auth
19
-
20
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers, debug_output: $stdout)
21
- end
22
- end
16
+ def create_appointment_type(endpoint: APPOINTMENT_TYPE_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
17
+ luma_request(auth: auth, body: body, endpoint: endpoint, verb: verb)
18
+ end
19
+ end
23
20
  end
@@ -14,18 +14,21 @@ module Luma
14
14
  end
15
15
 
16
16
  def authenticate
17
- request = {
18
- body: { email: email, password: password },
19
- endpoint: AUTH_ENDPOINT
20
- }
17
+ if (self.expires?)
18
+ request = {
19
+ body: { email: email, password: password },
20
+ endpoint: AUTH_ENDPOINT
21
+ }
21
22
 
22
- response = self.request(**request, auth: false)
23
+ response = self.request(**request, auth: false)
23
24
 
24
- if (false == response.ok?)
25
- @response = nil
26
- raise LumaException.from_response(response, msg: 'Authentication')
27
- else
28
- @response = response
25
+ if (false == response.ok?)
26
+ @response = nil
27
+ raise LumaException.from_response(response, msg: 'Authentication')
28
+ else
29
+ @response = response
30
+ validate
31
+ end
29
32
  end
30
33
 
31
34
  return self
@@ -51,6 +54,18 @@ module Luma
51
54
  return @response['token'] if @response
52
55
  end
53
56
 
57
+ def expiry
58
+ return @validation_response['exp'] if @validation_response
59
+ end
60
+
61
+ def expires?
62
+ if (self.expiry)
63
+ return (self.expiry / 1000) <= Time.now.to_f.floor
64
+ else
65
+ return true
66
+ end
67
+ end
68
+
54
69
  def access_header
55
70
  return {
56
71
  'X-Access-Token' => self.access_token,
@@ -24,17 +24,23 @@ module Luma
24
24
  self.class.send("#{verb}", endpoint, body: body, headers: headers)
25
25
  end
26
26
 
27
- def add_headers_and_body
28
- @body = @body.to_json
29
- @headers = auth_header.merge(@headers)
27
+ def add_header
30
28
  @headers["Content-Type"] = 'application/json'
31
29
  end
32
30
 
31
+ def luma_request(auth:, body:, endpoint:, verb:, identifier: nil)
32
+ @body = body
33
+ self.add_header if auth
34
+
35
+ endpoint = "#{endpoint}/#{identifier}" unless identifier.nil?
36
+
37
+ Luma::ResponseData.new(response: self.request(endpoint: endpoint, body: @body, headers: @headers, auth: auth, verb: verb))
38
+ end
39
+
33
40
  private
34
41
 
35
42
  def auth_header
36
- @auth = Authentication.new(email: @email, password: @password)
37
-
43
+ @auth ||= Authentication.new(email: @email, password: @password)
38
44
  return @auth.authenticate.access_header
39
45
  end
40
46
  end
@@ -1,14 +1,11 @@
1
1
  module Luma
2
- class Facilities < Connection
3
- FACILITY_ENDPOINT = '/api/facilities'.freeze
2
+ class Facilities < Connection
3
+ FACILITY_ENDPOINT = '/api/facilities'.freeze
4
4
 
5
- base_uri 'https://api.lumahealth.io/'.freeze
5
+ base_uri 'https://api.lumahealth.io/'.freeze
6
6
 
7
- def create_facility(endpoint: FACILITY_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
8
- @body = body
9
- self.add_headers_and_body if auth
10
-
11
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers)
12
- end
13
- end
7
+ def create_facility(endpoint: FACILITY_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
8
+ luma_request(auth: auth, body: body, endpoint: endpoint, verb: verb)
9
+ end
10
+ end
14
11
  end
@@ -12,7 +12,7 @@ module Luma
12
12
 
13
13
  property :type, required: false
14
14
  property :value, required: false
15
- property :active, required: false, default: false
15
+ property :active, required: false
16
16
  end
17
17
  end
18
18
  end
data/lib/luma/patient.rb CHANGED
@@ -5,28 +5,19 @@ module Luma
5
5
  base_uri 'https://api.lumahealth.io/'.freeze
6
6
 
7
7
  def create_patient(endpoint: PATIENT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post, debug_output: $stdout)
8
- @body = body
9
- self.add_headers_and_body if auth
10
-
11
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers)
8
+ luma_request(auth: auth, body: body, endpoint: endpoint, verb: verb)
12
9
  end
13
10
 
14
11
  def update_patient(identifier:, endpoint: PATIENT_ENDPOINT, body: nil, headers: {}, auth: true, verb: :put, debug_output: $stdout)
15
- @body = body
16
- self.add_headers_and_body if auth
17
-
18
- endpoint = "#{endpoint}/#{identifier}"
19
-
20
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers)
12
+ luma_request(auth: auth, body: body, endpoint: endpoint, identifier: identifier, verb: verb)
21
13
  end
22
14
 
23
15
  def get_patient(identifier:, endpoint: PATIENT_ENDPOINT, headers: {}, auth: true, verb: :get, debug_output: $stdout)
24
- self.add_headers_and_body if auth
16
+ self.add_header if auth
25
17
 
26
18
  endpoint = "#{endpoint}/#{identifier}"
27
19
 
28
- response = self.class.send(verb.to_s, endpoint, headers: @headers)
29
-
20
+ response = self.request(endpoint: endpoint, headers: @headers, auth: auth, verb: verb)
30
21
  Luma::Models::PatientResponse.new(response: response)
31
22
  end
32
23
  end
data/lib/luma/provider.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  module Luma
2
- class Provider < Connection
3
- PROVIDER_ENDPOINT = '/api/providers'.freeze
2
+ class Provider < Connection
3
+ PROVIDER_ENDPOINT = '/api/providers'.freeze
4
4
 
5
- base_uri 'https://api.lumahealth.io/'.freeze
5
+ base_uri 'https://api.lumahealth.io/'.freeze
6
6
 
7
- def create_provider(endpoint: PROVIDER_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post)
8
- @body = body
9
-
10
- self.add_headers_and_body if auth
11
-
12
- self.class.send(verb.to_s, endpoint, body: @body, headers: @headers, debug_output: $stdout)
13
- end
14
- end
7
+ def create_provider(endpoint: PROVIDER_ENDPOINT, body: nil, headers: {}, auth: true, verb: :post)
8
+ luma_request(auth: auth, body: body, endpoint: endpoint, verb: verb)
9
+ end
10
+ end
15
11
  end
@@ -0,0 +1,23 @@
1
+ module Luma
2
+ class ResponseData
3
+ attr_reader :response, :raw
4
+
5
+ BAD_GATEWAY_CODE = 502.freeze
6
+ RETRYABLE_CODES = [BAD_GATEWAY_CODE].freeze
7
+
8
+ def initialize(response: nil)
9
+ @response = response
10
+
11
+ begin
12
+ @raw ||= response&.parsed_response
13
+ rescue JSON::ParserError
14
+ end
15
+
16
+ @raw ||= {}
17
+ end
18
+
19
+ def recommend_retry?
20
+ return true if RETRYABLE_CODES.include? response.code
21
+ end
22
+ end
23
+ end
data/lib/luma/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Luma
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
data/lib/luma.rb CHANGED
@@ -14,6 +14,7 @@ require 'luma/models/patient_response'
14
14
  require 'luma/models/patient'
15
15
  require 'luma/appointment'
16
16
  require 'luma/models/appointment'
17
+ require 'luma/response_data'
17
18
 
18
19
  module Luma
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angela Rodriguez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -168,6 +168,7 @@ files:
168
168
  - lib/luma/models/patient_response.rb
169
169
  - lib/luma/patient.rb
170
170
  - lib/luma/provider.rb
171
+ - lib/luma/response_data.rb
171
172
  - lib/luma/version.rb
172
173
  - luma.gemspec
173
174
  homepage: https://github.com/WeInfuse/luma