redox-client 0.4.0 → 0.5.0

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: 2f0d83a6d33710574c0f6155a7a255baec5d3ad2c63ccd53640814002b9dc39e
4
- data.tar.gz: 973b6a299bad59fdb9dd0ae0341e241bdfa377963642312e3cea67e24e7e923b
3
+ metadata.gz: 7e25af2125fc17dda61023bc6513a886a24fe2e3b6fe9fae958ba6c43edb351b
4
+ data.tar.gz: 33b595b60b546ae11e18c54b6db60cdfb0c6d21681c0f69d8f1d8d9d3afea1ca
5
5
  SHA512:
6
- metadata.gz: b83d9b7c136ed63c448c993c269a20e2ab4ab6819e588a67c32c7ae81ae6f446a79ca33468b8af1b3f74f4cc3e9786f637aee37dd25ee034b65a16fb2f9be1bd
7
- data.tar.gz: 30b26d98cc7dadc1498a00a7e128ee4493f1d68c23f17f1ba7722fe7408530550d1f67305985942f1b52950acbb40086447ef296d6ca25e439425089f7a25b32
6
+ metadata.gz: bdc40d505021f48100f7a2f176e4a0811611b90de70cf9caee2fdb489d707f1266a815564dbf36567bab0de64ad79642b65914169ec76b7c42218d8212118271
7
+ data.tar.gz: 23c892f9c708256e3ed4d6f83158501daef2f3ee155dfde99938ef4bc5de2071f27850d1e036604556ca6527a5ec468e388bff38b7c33ba66732073ac56184de
@@ -7,6 +7,17 @@
7
7
 
8
8
  ### Removed
9
9
 
10
+ ## [0.5.0] - 2020-10-29
11
+ ### Added
12
+ - File Upload
13
+ - Media.New
14
+
15
+ ### Changed
16
+ - fixed: source was re-authenticating every request (DateTime math was incorrect)
17
+
18
+ ### Removed
19
+ - remove SchedulingBooked.Query Patient property. It is not present on the corresponding redox model and was never used.
20
+
10
21
  ## [0.4.0] - 2020-09-04
11
22
  ### Added
12
23
  - add email and phone to demographics
@@ -32,4 +43,5 @@
32
43
  [0.2.0]: https://github.com/patient-discovery/redox-client/releases/tag/v0.2.0
33
44
  [0.3.0]: https://github.com/patient-discovery/redox-client/releases/tag/v0.3.0
34
45
  [0.4.0]: https://github.com/patient-discovery/redox-client/releases/tag/v0.4.0
35
- [Unreleased]: https://github.com/patient-discovery/redox-client/compare/v0.4.0...HEAD
46
+ [0.5.0]: https://github.com/patient-discovery/redox-client/releases/tag/v0.5.0
47
+ [Unreleased]: https://github.com/patient-discovery/redox-client/compare/v0.5.0...HEAD
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redox-client (0.4.0)
4
+ redox-client (0.5.0)
5
5
  faraday (~> 1.0, >= 1.0.1)
6
6
  hashie (~> 4.1)
7
7
 
data/README.md CHANGED
@@ -79,6 +79,8 @@ Since `Redox::Source` has shared state, i.e., the access token and its expiratio
79
79
 
80
80
  - PatientSearch.Query
81
81
  - Scheduling.Booked
82
+ - Media.New
83
+ - File Upload
82
84
 
83
85
  ## Development
84
86
  ***Nota Bene**: This project uses [VCR](https://relishapp.com/vcr/vcr/docs) to record HTTP requests and responses and play them back during tests. Do NOT use Redox production credentials when developing tests.*
@@ -91,12 +93,27 @@ This project uses `rspec` and [VCR](https://relishapp.com/vcr/vcr/docs). VCR pro
91
93
 
92
94
  Some effort has been made to filter credentials from recorded HTTP interactions, but you should always carefully review all your changes before pushing them to avoid credential exposure.
93
95
 
94
- To make a new test with a new recording:
96
+ ### Recording and Playing Back Cassettes
97
+ The `VCR_MODE` environment variable controls whether VCR is recording cassettes or playing them back. When recoding cassettes the following environment variables are used to call Redox APIs:
98
+
99
+ - `REDOX_ENDPOINT`: base URL of Redox API endpoint (e.g., https://api.redoxengine.com/)
100
+ - `REDOX_API_KEY`: Redox `apiKey` used by /auth/authenticate
101
+ - `REDOX_SECRET`: Redox `secret` used by /auth/authenticate
102
+
103
+ Set these to the credentials for the Redox environment you are using for testing.
104
+
105
+ When playing back cassettes these environment variables are ignored and no API requests are made to Redox.
106
+
107
+ To make a new test with a new recording, set environment variables above then:
95
108
 
96
109
  ```bash
97
- env REDOX_API_KEY=my-key REDOX_SECRET=my-secret rspec
110
+ env VCR_MODE=record rspec spec/my_new_spec.rb
98
111
  ```
99
112
 
113
+ This will record all API requests made by the test. Be **careful**: if you run all the tests with `VCR_MODE=record` it will re-record all the cassettes.
114
+
115
+ The default mode is playback, so to playback cassettes just run `rspec`.
116
+
100
117
  ### Coding Style
101
118
  This project adheres to [StandardRB](https://github.com/testdouble/standard/blob/master/README.md). Additionally
102
119
  [# frozen_string_literal](https://bugs.ruby-lang.org/issues/8976#note-30) is required in Ruby source files, and is enforced by Rubocop.
@@ -9,6 +9,7 @@ require_relative "redox/models/demographics"
9
9
  require_relative "redox/models/destination"
10
10
  require_relative "redox/models/error"
11
11
  require_relative "redox/models/location"
12
+ require_relative "redox/models/media"
12
13
  require_relative "redox/models/message"
13
14
  require_relative "redox/models/meta"
14
15
  require_relative "redox/models/patient_identifier"
@@ -17,10 +18,13 @@ require_relative "redox/models/phone_number"
17
18
  require_relative "redox/models/provider"
18
19
  require_relative "redox/models/visit"
19
20
 
20
- require_relative "redox/query"
21
21
  require_relative "redox/source"
22
+ require_relative "redox/query"
23
+ require_relative "redox/file_upload"
24
+
22
25
  require_relative "redox/patient_search/query.rb"
23
26
  require_relative "redox/scheduling/booked.rb"
27
+ require_relative "redox/media/new.rb"
24
28
 
25
29
  module Redox
26
30
  class Error < StandardError
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Redox
4
+ class FileUpload
5
+ ENDPOINT = "https://blob.redoxengine.com/upload"
6
+
7
+ # Create a multipart file upload.
8
+ #
9
+ # @param filename_or_io [String, IO] Either a String filename of a local file
10
+ # or an open IO object
11
+ # @param content_type [String] String content type of the file data
12
+ # @param upload_as_filename [String] (optional) Name to use for uploaded file
13
+ def initialize(filename_or_io, content_type, upload_as_filename = nil)
14
+ @file_part = Faraday::FilePart.new(filename_or_io, content_type, upload_as_filename)
15
+ end
16
+
17
+ # Upload the file.
18
+ #
19
+ # @param [Redox::Source] source to use for authentication
20
+ def perform(source)
21
+ source.ensure_access_token
22
+
23
+ connection = Faraday.new { |f|
24
+ f.authorization :Bearer, source.access_token
25
+ f.request :multipart
26
+ f.headers[:accept] = "application/json"
27
+ }
28
+ res = connection.post ENDPOINT, {file: @file_part}
29
+
30
+ raise Redox::Error.new(status: res.status, body: res.body) unless res.success?
31
+
32
+ uri =
33
+ begin
34
+ JSON.parse(res.body)["URI"]
35
+ rescue
36
+ end
37
+ raise Redox::Error.new(status: res.status, body: res.body) unless uri
38
+
39
+ uri
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redox"
4
+
5
+ module Redox
6
+ module Media
7
+ class New < Redox::Query
8
+ redox_property :Patient, coerce: Models::Patient
9
+ redox_property :Visit, coerce: Models::Visit
10
+ redox_property :Media, coerce: Models::Media
11
+
12
+ def response_type
13
+ NewResponse
14
+ end
15
+ end
16
+
17
+ class NewResponse < Models::Message
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "provider"
4
+
5
+ module Redox
6
+ module Models
7
+ class Media < Redox::Model
8
+ redox_property :FileType
9
+ redox_property :FileName
10
+ redox_property :FileContents
11
+ redox_property :DocumentType
12
+ redox_property :DocumentID
13
+ redox_property :DocumentDescription
14
+ redox_property :CreationDateTime
15
+ redox_property :ServiceDateTime
16
+ redox_property :Provider, coerce: Provider
17
+ redox_property :Authenticated
18
+ redox_property :Authenticator, coerce: Provider
19
+ redox_property :Availability
20
+ redox_property :Notifications, coerce: Array[Provider]
21
+ end
22
+ end
23
+ end
@@ -4,12 +4,17 @@ require_relative "destination"
4
4
 
5
5
  module Redox
6
6
  module Models
7
+ # Redox::Message is already taken: it refers to an entire response
8
+ class MetaMessage < Redox::Model
9
+ redox_property :ID
10
+ end
7
11
  class Meta < Redox::Model
8
12
  redox_property :DataModel
9
13
  redox_property :EventType
10
14
  redox_property :EventDateTime
11
15
  redox_property :Test
12
16
  redox_property :Destinations, coerce: Array[Redox::Models::Destination]
17
+ redox_property :Message, coerce: MetaMessage
13
18
  redox_property :Errors, coerce: Array[Redox::Models::Error]
14
19
  end
15
20
  end
@@ -12,8 +12,6 @@ module Redox
12
12
  v.respond_to?(:iso8601) ? v.iso8601 : v.to_s
13
13
  }
14
14
 
15
- redox_property :Patient, coerce: Models::Patient
16
-
17
15
  def response_type
18
16
  BookedResponse
19
17
  end
@@ -7,7 +7,8 @@ require "faraday"
7
7
  class Redox::Source
8
8
  include MonitorMixin
9
9
 
10
- ACCESS_TOKEN_EXPIRATION_BUFFER_SECONDS = 300
10
+ SECONDS_PER_DAY = 60 * 60 * 24
11
+ ACCESS_TOKEN_EXPIRATION_BUFFER = Rational(300, SECONDS_PER_DAY)
11
12
 
12
13
  attr_reader :access_token_expires_at
13
14
 
@@ -63,12 +64,12 @@ class Redox::Source
63
64
  end
64
65
  end
65
66
 
66
- private
67
-
68
67
  def token_expiring_soon?
69
- DateTime.now > @access_token_expires_at - ACCESS_TOKEN_EXPIRATION_BUFFER_SECONDS
68
+ DateTime.now > @access_token_expires_at - ACCESS_TOKEN_EXPIRATION_BUFFER
70
69
  end
71
70
 
71
+ private
72
+
72
73
  def authenticate
73
74
  self.access_token = nil
74
75
  res = @connection.post("/auth/authenticate", {apiKey: @api_key, secret: @secret}.to_json)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Redox
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redox-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Keirnan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -142,6 +142,8 @@ files:
142
142
  - README.md
143
143
  - Rakefile
144
144
  - lib/redox.rb
145
+ - lib/redox/file_upload.rb
146
+ - lib/redox/media/new.rb
145
147
  - lib/redox/model.rb
146
148
  - lib/redox/models/address.rb
147
149
  - lib/redox/models/contact.rb
@@ -149,6 +151,7 @@ files:
149
151
  - lib/redox/models/destination.rb
150
152
  - lib/redox/models/error.rb
151
153
  - lib/redox/models/location.rb
154
+ - lib/redox/models/media.rb
152
155
  - lib/redox/models/message.rb
153
156
  - lib/redox/models/meta.rb
154
157
  - lib/redox/models/patient.rb