redox-engine 0.1.3
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 +7 -0
- data/.circleci/config.yml +26 -0
- data/.editorconfig +10 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +33 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +4 -0
- data/README.md +114 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/core_ext/hash.rb +53 -0
- data/lib/redox-engine.rb +24 -0
- data/lib/redox-engine/client.rb +154 -0
- data/lib/redox-engine/exceptions.rb +9 -0
- data/lib/redox-engine/patient.rb +9 -0
- data/lib/redox-engine/request_helpers.rb +91 -0
- data/lib/redox-engine/util.rb +13 -0
- data/lib/redox-engine/version.rb +3 -0
- data/lib/redox-engine/visit.rb +9 -0
- data/redox-engine.gemspec +37 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2bf921674c782a330ae80681707ab75dcea8d1ce33b64377972b6ba65dcd12f2
|
4
|
+
data.tar.gz: e118094c8e31bff0d0df9fcfe8e3b7e7dfd01a3571624a49cdbf485815b639ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 330cbf17a9e11f0b0d24aafef2f5c88cdeec00c7699e49c68c49e8f460a4134562cc4cc1f1da24e6ac70f4c5985f5a52e7e71f6802b73fa3afbefbac5e653483
|
7
|
+
data.tar.gz: 79a90d76cb1d26cab2737baa26dd609e9113841587aae749f34692babf6970e0b9cbaca630c78c15d2ea31d909ab0b85359477dd6f723a55e74ccf6c64b3d061
|
@@ -0,0 +1,26 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
working_directory: ~/weinfuse_api
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.4
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- type: restore-cache
|
10
|
+
key: redox_{{ checksum "Gemfile.lock" }}
|
11
|
+
key: redox
|
12
|
+
- run: bundle install --path vendor/bundle --jobs 20 --retry 5
|
13
|
+
- type: cache-save
|
14
|
+
key: redox_{{ checksum "Gemfile.lock" }}
|
15
|
+
key: redox
|
16
|
+
paths:
|
17
|
+
- vendor/bundle
|
18
|
+
- type: shell
|
19
|
+
command: |
|
20
|
+
bundle exec rubocop
|
21
|
+
- type: shell
|
22
|
+
command: |
|
23
|
+
bundle exec rake test
|
24
|
+
- type: store_test_results
|
25
|
+
path: /tmp/test-results
|
26
|
+
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Common configuration.
|
2
|
+
AllCops:
|
3
|
+
# Include gemspec and Rakefile
|
4
|
+
Exclude:
|
5
|
+
- '**/*.gemspec'
|
6
|
+
- '**/*.podspec'
|
7
|
+
- '**/*.jbuilder'
|
8
|
+
- '**/*.rake'
|
9
|
+
- '**/*.opal'
|
10
|
+
- '**/Gemfile'
|
11
|
+
- '**/Rakefile'
|
12
|
+
- '**/Capfile'
|
13
|
+
- '**/Guardfile'
|
14
|
+
- '**/Podfile'
|
15
|
+
- '**/Thorfile'
|
16
|
+
- '**/Vagrantfile'
|
17
|
+
- '**/Berksfile'
|
18
|
+
- '**/Cheffile'
|
19
|
+
- '**/Vagabondfile'
|
20
|
+
- 'vendor/**/*'
|
21
|
+
- 'test/test_helper_methods.rb'
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Exclude:
|
25
|
+
- 'test/**/*'
|
26
|
+
|
27
|
+
Metrics/ClassLength:
|
28
|
+
Exclude:
|
29
|
+
- 'test/**/*'
|
30
|
+
|
31
|
+
Style/RescueModifier:
|
32
|
+
Exclude:
|
33
|
+
- 'lib/core_ext/hash.rb'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.1.3] - 2018-04-04
|
8
|
+
- Change RedoxEngine::RedoxEngine to RedoxEngine::Client
|
9
|
+
- Refactor Module to accept configuration
|
10
|
+
- Refactor Client to pass Rubocop linting
|
11
|
+
- Refactor Client to accept stored token/refresh token
|
12
|
+
- Refactor/add tests
|
13
|
+
- Add methods:
|
14
|
+
- client.update_patient
|
15
|
+
- client.get_booked_slots
|
16
|
+
- client.search_patient
|
17
|
+
- client.get_summary_for_patient
|
18
|
+
- Add classes:
|
19
|
+
- Patient
|
20
|
+
- Visit
|
21
|
+
|
22
|
+
# [0.1.2] - 2018-03-08
|
23
|
+
### Added
|
24
|
+
- CircleCI config
|
25
|
+
- .editorconfig
|
26
|
+
- Added rubocop as dev dependency
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
- Corrected author email
|
30
|
+
- Tweaks to pass rubocop
|
31
|
+
|
32
|
+
# [0.1.1] - 2017-10-12
|
33
|
+
### Removed
|
34
|
+
- Redundant .gem file
|
35
|
+
- Fix WeInfuse capitalization
|
36
|
+
|
37
|
+
## 0.1.0 - 2017-10-12
|
38
|
+
### Added
|
39
|
+
- Initial Release
|
40
|
+
|
41
|
+
[Unreleased]: https://github.com/WeInfuse/redox/compare/0.1.2...HEAD
|
42
|
+
[0.1.2]: https://github.com/WeInfuse/redox/compare/0.1.1...0.1.2
|
43
|
+
[0.1.1]: https://github.com/WeInfuse/redox/compare/0.1.0...0.1.1
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# RedoxEngine
|
2
|
+
Ruby API wrapper for [RedoxEngine Engine](https://www.redoxengine.com)
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'redox'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install redox
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
In an initializer file:
|
23
|
+
```ruby
|
24
|
+
RedoxEngine.configure do |redox|
|
25
|
+
redox.api_key = #{Your API Key}
|
26
|
+
redox.secret = #{Your secret}
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
source = {
|
32
|
+
Name: 'RedoxEngine Dev Tools',
|
33
|
+
ID: ENV['REDOX_SRC_ID']
|
34
|
+
}
|
35
|
+
|
36
|
+
destinations = [
|
37
|
+
{
|
38
|
+
Name: 'RedoxEngine EMR',
|
39
|
+
ID: ENV['REDOX_DEST_ID']
|
40
|
+
}
|
41
|
+
]
|
42
|
+
|
43
|
+
redox = RedoxEngine::Client.new(
|
44
|
+
source: source,
|
45
|
+
destinations: destinations,
|
46
|
+
test: true
|
47
|
+
)
|
48
|
+
|
49
|
+
redox.add_patient(
|
50
|
+
Identifiers: [...],
|
51
|
+
Demographics: {
|
52
|
+
FirstName: 'Joe'
|
53
|
+
...
|
54
|
+
}
|
55
|
+
)
|
56
|
+
```
|
57
|
+
|
58
|
+
Initializing with a persisted access token (check if it's expired, client will load naively)
|
59
|
+
```ruby
|
60
|
+
c = RedoxEngine::Client.new(
|
61
|
+
source: source,
|
62
|
+
destinations: destinations,
|
63
|
+
test: true,
|
64
|
+
token: <Existing access token>
|
65
|
+
)
|
66
|
+
```
|
67
|
+
|
68
|
+
Initializing with a persisted refresh token (client will get a new access token)
|
69
|
+
```ruby
|
70
|
+
c = RedoxEngine::Client.new(
|
71
|
+
source: source,
|
72
|
+
destinations: destinations,
|
73
|
+
test: true,
|
74
|
+
refresh_token: <Existing refresh token>
|
75
|
+
)
|
76
|
+
c.access_token # => returns new token
|
77
|
+
```
|
78
|
+
|
79
|
+
## Testing
|
80
|
+
To run the test suite, save the following in redox_keys.yml in the test/directory (already in the .gitignore for your convenience):
|
81
|
+
|
82
|
+
```yaml
|
83
|
+
api_key: <Your RedoxEngine API Key>
|
84
|
+
secret: <Your RedoxEngine API Secret>
|
85
|
+
|
86
|
+
source_data:
|
87
|
+
Name: <RedoxEngine Source Name>
|
88
|
+
ID: <RedoxEngine Source ID>
|
89
|
+
|
90
|
+
destinations_data:
|
91
|
+
ClinicalSummary:
|
92
|
+
Name: <Destination Name>
|
93
|
+
ID: <Destination ID>
|
94
|
+
PatientAdmin:
|
95
|
+
Name: <Destination Name>
|
96
|
+
ID: <Destination ID>
|
97
|
+
Scheduling:
|
98
|
+
Name: <Destination Name>
|
99
|
+
ID: <Destination ID>
|
100
|
+
PatientSearch:
|
101
|
+
Name: <Destination Name>
|
102
|
+
ID: <Destination ID>
|
103
|
+
|
104
|
+
```
|
105
|
+
|
106
|
+
## Development
|
107
|
+
|
108
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
109
|
+
|
110
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/WeInfuse/redox.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'redox'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Help us deal with hashes with various key shapes/types
|
2
|
+
class Hash
|
3
|
+
# recursively transform keys/values according to a given block
|
4
|
+
def transform_keys(&block)
|
5
|
+
map do |key, value|
|
6
|
+
[
|
7
|
+
yield(key),
|
8
|
+
transform_value(value, &block)
|
9
|
+
]
|
10
|
+
end.to_h
|
11
|
+
end
|
12
|
+
|
13
|
+
# recursively transform values that contain a data structure,
|
14
|
+
# return the value if it isn't a hash
|
15
|
+
def transform_value(value, &block)
|
16
|
+
if value.respond_to?(:each_index)
|
17
|
+
value.map do |elem|
|
18
|
+
elem.transform_keys(&block) rescue elem
|
19
|
+
end
|
20
|
+
else
|
21
|
+
value.transform_keys(&block) rescue value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Rails method, find at
|
26
|
+
# activesupport/lib/active_support/core_ext/hash/keys.rb, line 50
|
27
|
+
def symbolize_keys
|
28
|
+
transform_keys { |key| key.to_sym rescue key }
|
29
|
+
end
|
30
|
+
|
31
|
+
# transform camel_case (symbol) keys to RedoxCase string keys
|
32
|
+
def redoxify_keys
|
33
|
+
transform_keys do |key|
|
34
|
+
key = key[0..-1]
|
35
|
+
next 'IDType' if %w[id_type IDType].include? key
|
36
|
+
next key if key =~ /^([A-Z]{1}[a-z]+)+/
|
37
|
+
next key.upcase if key =~ /^[A-Za-z]{2,3}$/
|
38
|
+
key.split('_').map(&:capitalize).join
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# transform RedoxCase string keys to ruby symbol keys
|
43
|
+
def rubyize_keys
|
44
|
+
transform_keys do |key|
|
45
|
+
key
|
46
|
+
.to_s
|
47
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
48
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
49
|
+
.downcase
|
50
|
+
.to_sym
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/redox-engine.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'core_ext/hash'
|
2
|
+
require 'redox-engine/version'
|
3
|
+
require 'redox-engine/util'
|
4
|
+
require 'redox-engine/request_helpers'
|
5
|
+
require 'redox-engine/exceptions'
|
6
|
+
require 'redox-engine/client'
|
7
|
+
require 'redox-engine/patient'
|
8
|
+
require 'redox-engine/visit'
|
9
|
+
require 'json'
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
|
13
|
+
# a set of Ruby classes for RedoxEngine HTTP API interactions
|
14
|
+
module RedoxEngine
|
15
|
+
API_URL = URI.parse('https://api.redoxengine.com/')
|
16
|
+
class << self
|
17
|
+
attr_accessor :api_key, :secret
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
yield self
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module RedoxEngine
|
2
|
+
# RedoxEngine API client
|
3
|
+
class Client
|
4
|
+
include RequestHelpers
|
5
|
+
|
6
|
+
attr_reader(
|
7
|
+
:source, :destinations, :test,
|
8
|
+
:access_token, :refresh_token, :response
|
9
|
+
)
|
10
|
+
# Instantiates a new RedoxEngine Client object
|
11
|
+
#
|
12
|
+
# @param [Hash] source source information
|
13
|
+
# @param [Array<Hash>] destinations list of destinations
|
14
|
+
# @param [Boolean] test_mode whether to use test mode
|
15
|
+
# @param [String] access_token Optional param to provide an existing Access
|
16
|
+
# Token
|
17
|
+
# @param [String] refresh_token Optional param to provide an existing
|
18
|
+
# Refresh Token
|
19
|
+
# @example
|
20
|
+
# redox = RedoxEngine::Client.new(
|
21
|
+
# source: source,
|
22
|
+
# destinations: destinations,
|
23
|
+
# test_mode: true,
|
24
|
+
# OPTIONAL: (If tokens/refresh_tokens are being persisted elsewhere)
|
25
|
+
# token: (existing access token),
|
26
|
+
# refresh_token: (existing refresh token)
|
27
|
+
# )
|
28
|
+
def initialize(
|
29
|
+
source:, destinations:, test_mode: true, token: nil, refresh_token: nil
|
30
|
+
)
|
31
|
+
raise APIKeyError if [RedoxEngine.api_key, RedoxEngine.secret].any?(&:nil?)
|
32
|
+
@refresh_token = refresh_token
|
33
|
+
@access_token = token || fetch_access_token
|
34
|
+
|
35
|
+
@source = source
|
36
|
+
@destinations = destinations
|
37
|
+
@test = test_mode
|
38
|
+
end
|
39
|
+
|
40
|
+
# Send PatientAdmin#NewPatient message
|
41
|
+
#
|
42
|
+
# @param [Hash] patient_params data to send in the Patient JSON object
|
43
|
+
# @return [Hash] parsed response object
|
44
|
+
# @example
|
45
|
+
# RedoxEngine::Client.new(*connection_params).add_patient(
|
46
|
+
# Identifiers: [],
|
47
|
+
# Demographics: {
|
48
|
+
# FirstName: 'Joe'
|
49
|
+
# }
|
50
|
+
# )
|
51
|
+
def add_patient(patient_params)
|
52
|
+
request_body = request_meta(
|
53
|
+
data_model: 'PatientAdmin',
|
54
|
+
event_type: 'NewPatient'
|
55
|
+
).merge(Patient: patient_params.redoxify_keys)
|
56
|
+
handle_request(request_body, 'Error in Patient New.')
|
57
|
+
end
|
58
|
+
|
59
|
+
# Send PatientAdmin#PatientUpdate message
|
60
|
+
#
|
61
|
+
# @param [Hash] patient_params data to send in the Patient JSON object
|
62
|
+
# @return [Hash] parsed response object
|
63
|
+
# @example
|
64
|
+
# RedoxEngine::Client.new(*connection_params).update_patient(
|
65
|
+
# Identifiers: [],
|
66
|
+
# Demographics: {
|
67
|
+
# FirstName: 'Joe'
|
68
|
+
# }
|
69
|
+
# )
|
70
|
+
def update_patient(patient_params)
|
71
|
+
request_body = request_meta(
|
72
|
+
data_model: 'PatientAdmin',
|
73
|
+
event_type: 'PatientUpdate'
|
74
|
+
).merge(Patient: patient_params.redoxify_keys)
|
75
|
+
handle_request(request_body, 'Error updating Patient.')
|
76
|
+
end
|
77
|
+
|
78
|
+
# Send PatientSearch#Query message
|
79
|
+
#
|
80
|
+
# @param [Hash] patient_params data to send in the Patient JSON object
|
81
|
+
# @return [Hash] parsed response object
|
82
|
+
# @example
|
83
|
+
# RedoxEngine::Client.new(*connection_params).search_patient(
|
84
|
+
# demographics: {
|
85
|
+
# FirstName: 'Joe'
|
86
|
+
# ...
|
87
|
+
# }
|
88
|
+
# )
|
89
|
+
def search_patient(patient_params)
|
90
|
+
request_body = request_meta(
|
91
|
+
data_model: 'PatientSearch',
|
92
|
+
event_type: 'Query'
|
93
|
+
).merge(Patient: patient_params.redoxify_keys)
|
94
|
+
handle_request(request_body, 'Error in Patient Search.')
|
95
|
+
end
|
96
|
+
|
97
|
+
# Send ClinicalSummary#PatientQuery message
|
98
|
+
#
|
99
|
+
# @param [Hash] patient_params data to send in the Patient JSON object
|
100
|
+
# @return [Hash] parsed response object
|
101
|
+
# @example
|
102
|
+
# RedoxEngine::Client.new(*connection_params).search_patient(
|
103
|
+
# identifiers: [
|
104
|
+
# {
|
105
|
+
# id: '4681'
|
106
|
+
# id_type: 'AthenaNet Enterprise ID'
|
107
|
+
# }
|
108
|
+
# ]
|
109
|
+
# )
|
110
|
+
def get_summary_for_patient(patient_params)
|
111
|
+
request_body = request_meta(
|
112
|
+
data_model: 'Clinical Summary',
|
113
|
+
event_type: 'PatientQuery'
|
114
|
+
).merge(Patient: patient_params.redoxify_keys)
|
115
|
+
handle_request(
|
116
|
+
request_body,
|
117
|
+
'Error fetching Patient Clinical Summary'
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Send Scheduling#BookedSlots message
|
122
|
+
#
|
123
|
+
# @param [Hash] visit data to send in the Visit JSON object
|
124
|
+
# @param [String|Time] start_time datetime to search from
|
125
|
+
# @params [String|Time] end_time datetime to search until
|
126
|
+
# @return [Hash] parsed response object
|
127
|
+
# @example
|
128
|
+
# RedoxEngine::Client.new(*connection_params).get_booked_slots(
|
129
|
+
# visit: {
|
130
|
+
# reason?: string
|
131
|
+
# attending_providers: Provider[]
|
132
|
+
# location: {
|
133
|
+
# type: string
|
134
|
+
# facility: string
|
135
|
+
# department: string | number
|
136
|
+
# room: string | number
|
137
|
+
# }
|
138
|
+
# }
|
139
|
+
# start_time?: Time | String (ISO-8601 Time String)
|
140
|
+
# end_time?: Time | String (ISO-8601 Time String)
|
141
|
+
# )
|
142
|
+
def get_booked_slots(visit:, start_time: nil, end_time: nil)
|
143
|
+
request_body = scheduling_query(
|
144
|
+
visit: visit,
|
145
|
+
start_time: start_time,
|
146
|
+
end_time: end_time
|
147
|
+
)
|
148
|
+
handle_request(
|
149
|
+
request_body,
|
150
|
+
'Error fetching Booked Slots'
|
151
|
+
)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module RedoxEngine
|
2
|
+
# Exceptions used in this gem will be defined here
|
3
|
+
|
4
|
+
# raise this on errors obtaining an access token
|
5
|
+
class TokenError < StandardError; end
|
6
|
+
|
7
|
+
# raise this on RedoxEngine::Client.new without setting api_key/secret
|
8
|
+
class APIKeyError < StandardError; end
|
9
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module RedoxEngine
|
2
|
+
# module to abstract request helper methods out of the client class
|
3
|
+
module RequestHelpers
|
4
|
+
private
|
5
|
+
|
6
|
+
def handle_request(request_body, error_message)
|
7
|
+
request = Net::HTTP::Post.new('/endpoint', auth_header)
|
8
|
+
request.body = request_body.to_json
|
9
|
+
@response = connection.request(request)
|
10
|
+
body = JSON.parse(response.body).rubyize_keys
|
11
|
+
if @response.code == '400'
|
12
|
+
$stdout.print error_message
|
13
|
+
return body[:meta]
|
14
|
+
end
|
15
|
+
|
16
|
+
body
|
17
|
+
end
|
18
|
+
|
19
|
+
def auth_header
|
20
|
+
{
|
21
|
+
'Authorization' => "Bearer #{access_token}",
|
22
|
+
'Content-Type' => 'application/json'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def request_meta(data_model:, event_type:)
|
27
|
+
{
|
28
|
+
meta: {
|
29
|
+
data_model: data_model,
|
30
|
+
event_type: event_type,
|
31
|
+
event_date_time: Time.now.iso8601,
|
32
|
+
test: @test,
|
33
|
+
source: @source,
|
34
|
+
destinations: find_destination(data_model)
|
35
|
+
}
|
36
|
+
}.redoxify_keys
|
37
|
+
end
|
38
|
+
|
39
|
+
def scheduling_query(visit:, start_time: nil, end_time: nil)
|
40
|
+
start_time = start_time ? Time.parse(start_time.to_s) : Time.now
|
41
|
+
end_time = end_time ? Time.parse(end_time.to_s) : start_time + 864_000
|
42
|
+
request_meta(data_model: 'Scheduling', event_type: 'Booked')
|
43
|
+
.merge(
|
44
|
+
visit: visit,
|
45
|
+
start_date_time: start_time.iso8601,
|
46
|
+
end_date_time: end_time.iso8601
|
47
|
+
)
|
48
|
+
.redoxify_keys
|
49
|
+
end
|
50
|
+
|
51
|
+
def login_request(refresh_token = nil)
|
52
|
+
req_url = refresh_token ? '/auth/refreshToken' : '/auth/authenticate'
|
53
|
+
req = Net::HTTP::Post.new(req_url, 'Content-Type' => 'application/json')
|
54
|
+
req_body = { apiKey: RedoxEngine.api_key }
|
55
|
+
if refresh_token
|
56
|
+
req_body[:refreshToken] = refresh_token
|
57
|
+
else
|
58
|
+
req_body[:secret] = RedoxEngine.secret
|
59
|
+
end
|
60
|
+
req.body = req_body.to_json
|
61
|
+
req
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch_access_token
|
65
|
+
return @access_token if defined? @access_token
|
66
|
+
|
67
|
+
response = connection.request(login_request(@refresh_token))
|
68
|
+
code = response.code.to_i
|
69
|
+
raise TokenError, 'Error obtaining token' unless code >= 200 && code < 400
|
70
|
+
body = JSON.parse(response.body)
|
71
|
+
@refresh_token = body['refreshToken']
|
72
|
+
|
73
|
+
body['accessToken']
|
74
|
+
end
|
75
|
+
|
76
|
+
def connection
|
77
|
+
return @connection if defined? @connection
|
78
|
+
|
79
|
+
http = Net::HTTP.new(API_URL.host, API_URL.port)
|
80
|
+
http.use_ssl = true
|
81
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
82
|
+
http.verify_depth = 5
|
83
|
+
|
84
|
+
@connection = http
|
85
|
+
end
|
86
|
+
|
87
|
+
def find_destination(destination_name)
|
88
|
+
[@destinations[destination_name.split(' ').join.to_sym]]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RedoxEngine
|
2
|
+
# utility methods for serializing responses
|
3
|
+
module Util
|
4
|
+
def map_hash_to_attributes(hash)
|
5
|
+
hash.map do |key, val|
|
6
|
+
define_singleton_method(key.to_sym) do
|
7
|
+
val
|
8
|
+
end
|
9
|
+
map_hash_to_attributes(val) if val.respond_to? :each_key
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'redox-engine/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'redox-engine'
|
7
|
+
spec.version = RedoxEngine::VERSION
|
8
|
+
spec.authors = ['Alexander Clark (forked from)', 'Pedro De Ona']
|
9
|
+
spec.email = ['p.deona2005@gmail.com']
|
10
|
+
spec.licenses = ['MIT']
|
11
|
+
spec.summary = 'Ruby wrapper for the RedoxEngine Engine API'
|
12
|
+
spec.homepage = 'https://github.com/pdeona/redox'
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org.
|
15
|
+
if spec.respond_to?(:metadata)
|
16
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
17
|
+
else
|
18
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
19
|
+
'public gem pushes.'
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.required_ruby_version = '~> 2.1'
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
31
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.5'
|
34
|
+
spec.add_development_dependency 'vcr', '~> 4.0'
|
35
|
+
spec.add_development_dependency 'webmock', '~> 3.1'
|
36
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redox-engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Clark (forked from)
|
8
|
+
- Pedro De Ona
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.13'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.13'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '5.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '5.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubocop
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.5'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.5'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: vcr
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '4.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '4.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: webmock
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '3.1'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '3.1'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: yard
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.9'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.9'
|
112
|
+
description:
|
113
|
+
email:
|
114
|
+
- p.deona2005@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".circleci/config.yml"
|
120
|
+
- ".editorconfig"
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- CHANGELOG.md
|
124
|
+
- Gemfile
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/core_ext/hash.rb
|
130
|
+
- lib/redox-engine.rb
|
131
|
+
- lib/redox-engine/client.rb
|
132
|
+
- lib/redox-engine/exceptions.rb
|
133
|
+
- lib/redox-engine/patient.rb
|
134
|
+
- lib/redox-engine/request_helpers.rb
|
135
|
+
- lib/redox-engine/util.rb
|
136
|
+
- lib/redox-engine/version.rb
|
137
|
+
- lib/redox-engine/visit.rb
|
138
|
+
- redox-engine.gemspec
|
139
|
+
homepage: https://github.com/pdeona/redox
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata:
|
143
|
+
allowed_push_host: https://rubygems.org
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '2.1'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.7.4
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Ruby wrapper for the RedoxEngine Engine API
|
164
|
+
test_files: []
|