pokitdok-ruby 0.7.1 → 0.7.2

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
  SHA1:
3
- metadata.gz: ca5d31a1c7e95167bd3ed9f12e4aba0c624c686c
4
- data.tar.gz: f9e90f70867044ab5e21e368af36be2a3a74c746
3
+ metadata.gz: d8d295a4e720cbc16c0760e1bd39f0458d2dbff0
4
+ data.tar.gz: 35fd84a68b5c6dd2e9e17d0e3afc3c02668679ab
5
5
  SHA512:
6
- metadata.gz: 9e93d53e3ce03a1b21456c9415d2367899dd7f94f8b144a247dfa3d14ab3625540d5858eded8776ce7186c94879e73920d713a71d5d64d4d3176a82c8e2c8cba
7
- data.tar.gz: 68a3519c467121ca748435a8e712231193436ab66fef7ff38fb56d234225b15f51b1a0be91f04ab53036cd2f007f82910b42c738d65db65c5ec2180d49ee4a05
6
+ metadata.gz: d167b436927487759778b7a40f43595ea29f06386389ad9f721a76e8f50bdff1cc53f99e6b663c844d2c916e9d76443af5fa02144fc28778590c60e797499133
7
+ data.tar.gz: 07387fa5e0f1959879ec98219c709b49073808dc7483eacfd5fe576aa616aa26e20fee638c14a90562dcfee2c5bb72df9bfa86c3c737aba5c1b8a9979ed86f7e
data/Gemfile CHANGED
@@ -16,6 +16,7 @@ group :development do
16
16
  gem 'webmock', '~> 1.17'
17
17
  gem 'guard', '~> 2.6'
18
18
  gem 'guard-minitest', '~> 2.2'
19
+ gem 'terminal-notifier'
19
20
  gem 'terminal-notifier-guard', '~> 1.5'
20
21
  gem 'guard-rubocop', '~> 1.0'
21
22
  gem 'coveralls', require: false
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.3.6)
5
- ansi (1.4.3)
4
+ addressable (2.3.8)
5
+ ansi (1.5.0)
6
6
  ast (2.0.0)
7
7
  astrolabe (1.3.0)
8
8
  parser (>= 2.2.0.pre.3, < 3.0)
@@ -10,45 +10,53 @@ GEM
10
10
  celluloid (0.16.0)
11
11
  timers (~> 4.0.0)
12
12
  coderay (1.1.0)
13
- coveralls (0.7.1)
14
- multi_json (~> 1.3)
15
- rest-client
16
- simplecov (>= 0.7)
17
- term-ansicolor
18
- thor
13
+ coveralls (0.8.1)
14
+ json (~> 1.8)
15
+ rest-client (>= 1.6.8, < 2)
16
+ simplecov (~> 0.10.0)
17
+ term-ansicolor (~> 1.3)
18
+ thor (~> 0.19.1)
19
19
  crack (0.4.2)
20
20
  safe_yaml (~> 1.0.0)
21
21
  descendants_tracker (0.0.4)
22
22
  thread_safe (~> 0.3, >= 0.3.1)
23
23
  docile (1.1.5)
24
- faraday (0.9.0)
24
+ domain_name (0.5.24)
25
+ unf (>= 0.0.5, < 1.0.0)
26
+ faraday (0.9.1)
25
27
  multipart-post (>= 1.2, < 3)
26
- ffi (1.9.6)
28
+ ffi (1.9.8)
27
29
  formatador (0.2.5)
28
- git (1.2.8)
29
- github_api (0.12.1)
30
+ git (1.2.9.1)
31
+ github_api (0.12.3)
30
32
  addressable (~> 2.3)
31
33
  descendants_tracker (~> 0.0.4)
32
34
  faraday (~> 0.8, < 0.10)
33
- hashie (>= 3.2)
35
+ hashie (>= 3.3)
34
36
  multi_json (>= 1.7.5, < 2.0)
35
37
  nokogiri (~> 1.6.3)
36
38
  oauth2
37
- guard (2.6.1)
39
+ guard (2.12.5)
38
40
  formatador (>= 0.2.4)
39
41
  listen (~> 2.7)
40
42
  lumberjack (~> 1.0)
43
+ nenv (~> 0.1)
44
+ notiffany (~> 0.0)
41
45
  pry (>= 0.9.12)
46
+ shellany (~> 0.0)
42
47
  thor (>= 0.18.1)
43
- guard-minitest (2.3.2)
44
- guard (~> 2.0)
48
+ guard-compat (1.2.1)
49
+ guard-minitest (2.4.4)
50
+ guard-compat (~> 1.2)
45
51
  minitest (>= 3.0)
46
- guard-rubocop (1.1.0)
52
+ guard-rubocop (1.2.0)
47
53
  guard (~> 2.0)
48
54
  rubocop (~> 0.20)
49
- hashie (3.3.1)
50
- highline (1.6.21)
55
+ hashie (3.4.1)
56
+ highline (1.7.2)
51
57
  hitimes (1.2.2)
58
+ http-cookie (1.0.2)
59
+ domain_name (~> 0.5)
52
60
  jeweler (2.0.1)
53
61
  builder
54
62
  bundler (>= 1.0)
@@ -58,80 +66,89 @@ GEM
58
66
  nokogiri (>= 1.5.10)
59
67
  rake
60
68
  rdoc
61
- json (1.8.1)
62
- jwt (1.0.0)
63
- listen (2.7.11)
64
- celluloid (>= 0.15.2)
69
+ json (1.8.2)
70
+ jwt (1.5.0)
71
+ listen (2.10.0)
72
+ celluloid (~> 0.16.0)
65
73
  rb-fsevent (>= 0.9.3)
66
74
  rb-inotify (>= 0.9)
67
75
  lumberjack (1.0.9)
68
76
  metaclass (0.0.4)
69
77
  method_source (0.8.2)
70
- mime-types (2.4.3)
71
- mini_portile (0.6.0)
72
- minitest (5.4.2)
73
- minitest-reporters (1.0.6)
78
+ mime-types (2.5)
79
+ mini_portile (0.6.2)
80
+ minitest (5.6.1)
81
+ minitest-reporters (1.0.16)
74
82
  ansi
75
83
  builder
76
84
  minitest (>= 5.0)
77
85
  ruby-progressbar
78
86
  mocha (1.1.0)
79
87
  metaclass (~> 0.0.1)
80
- multi_json (1.10.1)
88
+ multi_json (1.11.0)
81
89
  multi_xml (0.5.5)
82
90
  multipart-post (2.0.0)
83
- netrc (0.8.0)
84
- nokogiri (1.6.3.1)
85
- mini_portile (= 0.6.0)
91
+ nenv (0.2.0)
92
+ netrc (0.10.3)
93
+ nokogiri (1.6.6.2)
94
+ mini_portile (~> 0.6.0)
95
+ notiffany (0.0.6)
96
+ nenv (~> 0.1)
97
+ shellany (~> 0.0)
86
98
  oauth2 (0.9.4)
87
99
  faraday (>= 0.8, < 0.10)
88
100
  jwt (~> 1.0)
89
101
  multi_json (~> 1.3)
90
102
  multi_xml (~> 0.5)
91
103
  rack (~> 1.2)
92
- parser (2.2.0.pre.5)
104
+ parser (2.2.2.3)
93
105
  ast (>= 1.1, < 3.0)
94
- slop (~> 3.4, >= 3.4.5)
95
- powerpack (0.0.9)
106
+ powerpack (0.1.1)
96
107
  pry (0.10.1)
97
108
  coderay (~> 1.1.0)
98
109
  method_source (~> 0.8.1)
99
110
  slop (~> 3.4)
100
- rack (1.5.2)
111
+ rack (1.6.1)
101
112
  rainbow (2.0.0)
102
- rake (10.3.2)
103
- rb-fsevent (0.9.4)
113
+ rake (10.4.2)
114
+ rb-fsevent (0.9.5)
104
115
  rb-inotify (0.9.5)
105
116
  ffi (>= 0.5.0)
106
- rdoc (4.1.2)
117
+ rdoc (4.2.0)
107
118
  json (~> 1.4)
108
- rest-client (1.7.2)
119
+ rest-client (1.8.0)
120
+ http-cookie (>= 1.0.2, < 2.0)
109
121
  mime-types (>= 1.16, < 3.0)
110
122
  netrc (~> 0.7)
111
- rubocop (0.26.1)
123
+ rubocop (0.31.0)
112
124
  astrolabe (~> 1.3)
113
- parser (>= 2.2.0.pre.4, < 3.0)
114
- powerpack (~> 0.0.6)
125
+ parser (>= 2.2.2.1, < 3.0)
126
+ powerpack (~> 0.1)
115
127
  rainbow (>= 1.99.1, < 3.0)
116
128
  ruby-progressbar (~> 1.4)
117
- ruby-progressbar (1.6.0)
129
+ ruby-progressbar (1.7.5)
118
130
  safe_yaml (1.0.4)
119
- simplecov (0.9.1)
131
+ shellany (0.0.1)
132
+ simplecov (0.10.0)
120
133
  docile (~> 1.1.0)
121
- multi_json (~> 1.0)
122
- simplecov-html (~> 0.8.0)
123
- simplecov-html (0.8.0)
134
+ json (~> 1.8)
135
+ simplecov-html (~> 0.10.0)
136
+ simplecov-html (0.10.0)
124
137
  slop (3.6.0)
125
138
  term-ansicolor (1.3.0)
126
139
  tins (~> 1.0)
127
- terminal-notifier-guard (1.6.0)
140
+ terminal-notifier (1.6.3)
141
+ terminal-notifier-guard (1.6.4)
128
142
  thor (0.19.1)
129
- thread_safe (0.3.4)
143
+ thread_safe (0.3.5)
130
144
  timers (4.0.1)
131
145
  hitimes
132
- tins (1.3.3)
146
+ tins (1.5.1)
147
+ unf (0.1.4)
148
+ unf_ext
149
+ unf_ext (0.0.7.1)
133
150
  vcr (2.9.3)
134
- webmock (1.20.0)
151
+ webmock (1.21.0)
135
152
  addressable (>= 2.3.6)
136
153
  crack (>= 0.3.2)
137
154
 
@@ -154,6 +171,7 @@ DEPENDENCIES
154
171
  rdoc (~> 4.1)
155
172
  rubocop (~> 0.20)
156
173
  simplecov (~> 0.8)
174
+ terminal-notifier
157
175
  terminal-notifier-guard (~> 1.5)
158
176
  vcr (~> 2.9)
159
177
  webmock (~> 1.17)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 PokitDok, Inc.
3
+ Copyright (c) 2015 PokitDok, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
data/lib/pokitdok.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2014, All Rights Reserved, PokitDok, Inc.
3
+ # Copyright (C) 2014-2015, All Rights Reserved, PokitDok, Inc.
4
4
  # https://www.pokitdok.com
5
5
  #
6
6
  # Please see the LICENSE.txt file for more information.
@@ -20,7 +20,6 @@ module PokitDok
20
20
  POKITDOK_URL_BASE = 'https://platform.pokitdok.com' # :nodoc:
21
21
 
22
22
  attr_reader :client # :nodoc:
23
- attr_reader :token # :nodoc:
24
23
  attr_reader :api_url
25
24
  attr_reader :version
26
25
 
@@ -37,123 +36,109 @@ module PokitDok
37
36
  @version = version
38
37
 
39
38
  @api_url = "#{url_base}/api/#{version}"
40
-
41
39
  @client = OAuth2::Client.new(@client_id, @client_secret,
42
40
  site: @api_url, token_url: '/oauth2/token')
43
- refresh_token
44
- end
45
41
 
46
- def url_base
47
- POKITDOK_URL_BASE
48
- end
49
42
 
50
- def user_agent
51
- "pokitdok-ruby 0.7.1 #{RUBY_DESCRIPTION}"
43
+ @scopes = {}
44
+ @scopes['default'] = { scope: refresh_token }
45
+ scope 'default'
52
46
  end
53
47
 
54
- # returns a standard set of headers to be passed along with all requests
55
- def headers
56
- { 'User-Agent' => user_agent }
48
+ # Accessor for the PokitDok Platform URL, overridable for testing.
49
+ def url_base
50
+ POKITDOK_URL_BASE
57
51
  end
58
52
 
59
- # Refreshes the client token associated with this PokitDok connection
53
+ # Adds an authorization code for a given OAuth2 scope.
54
+ #
55
+ # +name+ the scope name
56
+ # +code+ the authorization code
60
57
  #
61
- # FIXME: automatic refresh on expiration
62
- def refresh_token
63
- @token = client.client_credentials.get_token(
64
- headers: { 'Authorization' => 'Basic' })
58
+ def scope_code(name, code)
59
+ @scopes[name] = { code: code }
65
60
  end
66
61
 
67
- # Invokes the activities endpoint, with an optional Hash of parameters.
62
+ # Invokes the appointments endpoint, to query for open appointment slots
63
+ # (using pd_provider_uuid and location) or booked appointments (using
64
+ # patient_uuid).
65
+ #
66
+ # +params+ an optional Hash of parameters
67
+ #
68
68
  def activities(params = {})
69
- response = @token.get('activities/',
70
- headers: headers,
71
- params: params)
72
- JSON.parse(response.body)
69
+ scope 'default'
70
+ get('activities/', params)
73
71
  end
74
72
 
75
- # Invokes the authorizations endpoint, with an optional Hash of parameters.
73
+ # Invokes the authorizations endpoint.
74
+ #
75
+ # +params+ an optional hash of parameters that will be sent in the POST body
76
+ #
76
77
  def authorizations(params = {})
77
- response = @token.post('authorizations/',
78
- headers: headers,
79
- body: params.to_json) do |request|
80
- request.headers['Content-Type'] = 'application/json'
81
- end
82
- JSON.parse(response.body)
78
+ scope 'default'
79
+ post('authorizations/', params)
83
80
  end
84
81
 
85
- # Invokes the cash prices endpoint, with an optional Hash of parameters.
82
+ # Invokes the cash prices endpoint.
83
+ #
84
+ # +params+ an optional hash of parameters that will be sent in the POST body
85
+ #
86
86
  def cash_prices(params = {})
87
- response = @token.get('prices/cash',
88
- headers: headers,
89
- params: params)
90
- JSON.parse(response.body)
87
+ scope 'default'
88
+ get('prices/cash', params)
91
89
  end
92
90
 
93
- # Invokes the insurance prices endpoint, with an optional Hash of parameters.
94
- def insurance_prices(params = {})
95
- response = @token.get('prices/insurance',
96
- headers: headers,
97
- params: params)
98
- JSON.parse(response.body)
99
- end
100
-
101
- # Invokes the claims endpoint, with an optional Hash of parameters.
91
+ # Invokes the claims endpoint.
92
+ #
93
+ # +params+ an optional hash of parameters that will be sent in the POST body
94
+ #
102
95
  def claims(params = {})
103
- response = @token.post('claims/',
104
- headers: headers,
105
- body: params.to_json) do |request|
106
- request.headers['Content-Type'] = 'application/json'
107
- end
108
- JSON.parse(response.body)
96
+ scope 'default'
97
+ post('claims/', params)
109
98
  end
110
99
 
111
- # Invokes the claims status endpoint, with an optional Hash of parameters.
100
+ # Invokes the claims status endpoint.
101
+ #
102
+ # +params+ an optional hash of parameters that will be sent in the POST body
103
+ #
112
104
  def claims_status(params = {})
113
- response = @token.post('claims/status',
114
- headers: headers,
115
- body: params.to_json) do |request|
116
- request.headers['Content-Type'] = 'application/json'
117
- end
118
- JSON.parse(response.body)
105
+ scope 'default'
106
+ post('claims/status', params)
119
107
  end
120
108
 
121
-
122
- # Invokes the eligibility endpoint, with an optional Hash of parameters.
109
+ # Invokes the eligibility endpoint.
110
+ #
111
+ # +params+ an optional hash of parameters that will be sent in the POST body
112
+ #
123
113
  def eligibility(params = {})
124
- response = @token.post('eligibility/',
125
- headers: headers,
126
- body: params.to_json) do |request|
127
- request.headers['Content-Type'] = 'application/json'
128
- end
129
- JSON.parse(response.body)
114
+ scope 'default'
115
+ post('eligibility/', params)
130
116
  end
131
117
 
132
- # Invokes the enrollment endpoint, with an optional Hash of parameters.
118
+ # Invokes the enrollment endpoint.
119
+ #
120
+ # +params+ an optional hash of parameters that will be sent in the POST body
121
+ #
133
122
  def enrollment(params = {})
134
- response = @token.post('enrollment/',
135
- headers: headers,
136
- body: params.to_json) do |request|
137
- request.headers['Content-Type'] = 'application/json'
138
- end
139
- JSON.parse(response.body)
123
+ scope 'default'
124
+ post('enrollment/', params)
140
125
  end
141
126
 
142
127
  # Uploads an EDI file to the files endpoint.
143
128
  # Uses the multipart-post gem, since oauth2 doesn't support multipart.
144
129
  #
145
130
  # +trading_partner_id+ the trading partner to transmit to
146
- #
147
131
  # +filename+ the path to the file to transmit
148
132
  #
149
133
  def files(trading_partner_id, filename)
134
+ scope 'default'
150
135
  url = URI.parse(@api_url + '/files/')
151
136
 
152
137
  File.open(filename) do |f|
153
138
  req = Net::HTTP::Post::Multipart.new url.path,
154
139
  'file' => UploadIO.new(f, 'application/EDI-X12', filename),
155
140
  'trading_partner_id' => trading_partner_id
156
- req['Authorization'] = "Bearer #{@token.token}"
141
+ req['Authorization'] = "Bearer #{default_scope.token}"
157
142
  req['User-Agent'] = user_agent
158
143
 
159
144
  @response = Net::HTTP.start(url.host, url.port) do |http|
@@ -164,54 +149,305 @@ module PokitDok
164
149
  JSON.parse(@response.body)
165
150
  end
166
151
 
167
- # Invokes the payers endpoint, with an optional Hash of parameters.
152
+ # Invokes the insurance prices endpoint.
153
+ #
154
+ # +params+ an optional hash of parameters
155
+ #
156
+ def insurance_prices(params = {})
157
+ scope 'default'
158
+ get('prices/insurance', params)
159
+ end
160
+
161
+ # Invokes the payers endpoint.
162
+ #
163
+ # +params+ an optional hash of parameters
164
+ #
168
165
  def payers(params = {})
169
- response = @token.get('payers/', headers: headers, params: params)
170
- JSON.parse(response.body)
166
+ scope 'default'
167
+ get('payers/', params)
171
168
  end
172
169
 
173
- # Invokes the plans endpoint, with an optional Hash of parameters.
170
+ # Invokes the plans endpoint.
171
+ #
172
+ # +params+ an optional Hash of parameters
173
+ #
174
174
  def plans(params = {})
175
- response = @token.get('plans/', headers: headers, params: params)
176
- JSON.parse(response.body)
175
+ scope 'default'
176
+ get('plans/', params)
177
177
  end
178
178
 
179
- # Invokes the providers endpoint, with an optional Hash of parameters.
179
+ # Invokes the providers endpoint.
180
+ #
181
+ # +params+ an optional Hash of parameters
182
+ #
180
183
  def providers(params = {})
181
- response = @token.get('providers/') do |request|
184
+ response = default_scope.get('providers/') do |request|
182
185
  request.params = params
183
186
  end
184
187
  JSON.parse(response.body)
185
188
  end
186
189
 
187
- # Invokes the referrals endpoint, with an optional Hash of parameters.
190
+ # Invokes the referrals endpoint.
191
+ #
192
+ # +params+ an optional Hash of parameters
193
+ #
188
194
  def referrals(params = {})
189
- response = @token.post('referrals/',
190
- headers: headers,
191
- body: params.to_json) do |request|
192
- request.headers['Content-Type'] = 'application/json'
193
- end
194
- JSON.parse(response.body)
195
+ scope 'default'
196
+ post('referrals/', params)
195
197
  end
196
198
 
197
- # Invokes the trading partners endpoint, with an optional Hash of
198
- # parameters.
199
+ # Invokes the trading partners endpoint.
200
+ #
201
+ # +params+ an optional Hash of parameters
202
+ #
199
203
  def trading_partners(params = {})
200
204
  trading_partner_id = params.delete :trading_partner_id
201
205
 
202
206
  response =
203
- @token.get("tradingpartners/#{trading_partner_id}") do |request|
204
- request.params = params
205
- end
207
+ default_scope.get("tradingpartners/#{trading_partner_id}") do |request|
208
+ request.params = params
209
+ end
206
210
  JSON.parse(response.body)
207
211
  end
208
212
 
209
- # Invokes the plans endpoint, with a hash of parameters
210
- def plans(params = {})
211
- response = @token.get('plans/', headers: headers, params: params) do |request|
213
+ # Scheduling endpoints
214
+
215
+ # Invokes the appointments endpoint to query for an open appointment
216
+ # slot or a booked appointment given a specific pd_appointment_uuid,
217
+ # the PokitDok unique appointment identifier.
218
+ #
219
+ # +params+ an optional Hash of parameters
220
+ #
221
+ def appointment(params = {})
222
+ @appointment_id = params.delete :appointment_id
223
+ scope 'user_schedule'
224
+
225
+ get_one('schedule/appointmenttypes/', @appointment_id, params)
226
+ end
227
+
228
+ # Invokes the activities endpoint.
229
+ #
230
+ # This endpoint uses the user_schedule OAuth2 scope. You'll need to
231
+ # get the user's authorization via our OAuth2 provider, and pass the
232
+ # authorization code you received into
233
+ # scope_code('user_schedule', '(the authorization code)')
234
+ #
235
+ # +params+ an optional Hash of parameters
236
+ #
237
+ def appointments(params = {})
238
+ scope 'user_schedule'
239
+ get('schedule/appointments/', params)
240
+ end
241
+
242
+ # Invokes the appointment_types endpoint, to get information on a specific
243
+ # appointment type.
244
+ #
245
+ # +params+ an optional Hash of parameters
246
+ #
247
+ def appointment_type(params = {})
248
+ appointment_type = params.delete :uuid
249
+
250
+ response =
251
+ default_scope.get("schedule/appointmenttypes/#{appointment_type}") do |request|
212
252
  request.params = params
213
253
  end
254
+
255
+ JSON.parse(response.body)
256
+ end
257
+
258
+ # Invokes the appointment_types endpoint.
259
+ #
260
+ # +params+ an optional hash of parameters
261
+ #
262
+ def appointment_types(params = {})
263
+ scope 'default'
264
+ get('schedule/appointmenttypes/', params)
265
+ end
266
+
267
+ # Books an appointment.
268
+ #
269
+ # This endpoint uses the user_schedule OAuth2 scope. You'll need to
270
+ # get the user's authorization via our OAuth2 provider, and pass the
271
+ # authorization code you received into
272
+ # scope_code('user_schedule', '(the authorization code)')
273
+ #
274
+ # +params+ an optional hash of parameters that will be sent in the POST body
275
+ #
276
+ def book_appointment(appointment_uuid, params = {})
277
+ scope 'user_schedule'
278
+
279
+ put_one("schedule/appointments", appointment_uuid, params)
280
+ end
281
+
282
+ # Cancels the specified appointment.
283
+ #
284
+ # This endpoint uses the user_schedule OAuth2 scope. You'll need to
285
+ # get the user's authorization via our OAuth2 provider, and pass the
286
+ # authorization code you received into
287
+ # scope_code('user_schedule', '(the authorization code)')
288
+ #
289
+ # +params+ an optional Hash of parameters
290
+ #
291
+ def cancel_appointment(appointment_uuid, params={})
292
+ scope 'user_schedule'
293
+
294
+ delete_one("schedule/appointments", appointment_uuid, params)
295
+ end
296
+
297
+ # Invokes the schedule/appointments endpoint.
298
+ #
299
+ # This endpoint uses the user_schedule OAuth2 scope. You'll need to
300
+ # get the user's authorization via our OAuth2 provider, and pass the
301
+ # authorization code you received into
302
+ # scope_code('user_schedule', '(the authorization code)')
303
+ #
304
+ # +params+ an optional hash of parameters
305
+ #
306
+ def open_appointment_slots(params = {})
307
+ scope 'user_schedule'
308
+ get('schedule/appointments', params)
309
+ end
310
+
311
+ # Invokes the schedulers endpoint.
312
+ #
313
+ # +params an optional Hash of parameters
314
+ #
315
+ def schedulers(params = {})
316
+ scope 'default'
317
+ get('schedule/schedulers/', params)
318
+ end
319
+
320
+ # Invokes the schedulers endpoint, to get information about a specific
321
+ # scheduler.
322
+ #
323
+ # +params+ an optional Hash of parameters
324
+ #
325
+ def scheduler(params = {})
326
+ scheduler_id = params.delete :uuid
327
+
328
+ response =
329
+ default_scope.get("schedule/schedulers/#{scheduler_id}") do |request|
330
+ request.params = params
331
+ end
214
332
  JSON.parse(response.body)
215
333
  end
334
+
335
+ # Invokes the slots endpoint.
336
+ #
337
+ # This endpoint uses the user_schedule OAuth2 scope. You'll need to
338
+ # get the user's authorization via our OAuth2 provider, and pass the
339
+ # authorization code you received into
340
+ # scope_code('user_schedule', '(the authorization code)')
341
+ #
342
+ # +params+ an optional Hash of parameters
343
+ #
344
+ def slots(params = {})
345
+ scope 'user_schedule'
346
+ end
347
+
348
+ # Updates the specified appointment.
349
+ #
350
+ # This endpoint uses the user_schedule OAuth2 scope. You'll need to
351
+ # get the user's authorization via our OAuth2 provider, and pass the
352
+ # authorization code you received into
353
+ # scope_code('user_schedule', '(the authorization code)')
354
+ #
355
+ # +params+ an optional Hash of parameters
356
+ #
357
+ def update_appointment(appointment_uuid, params={})
358
+ scope 'user_schedule'
359
+
360
+ put_one("schedule/appointments", appointment_uuid, params)
361
+ end
362
+
363
+ private
364
+ # Returns a standard User-Agent string to be passed along with all requests
365
+ def user_agent
366
+ "pokitdok-ruby 0.8 #{RUBY_DESCRIPTION}"
367
+ end
368
+
369
+ # Returns a standard set of headers to be passed along with all requests
370
+ def headers
371
+ { 'User-Agent' => user_agent }
372
+ end
373
+
374
+ def get(endpoint, params = {})
375
+ response = current_scope.get(endpoint, headers: headers, params: params)
376
+
377
+ JSON.parse(response.body)
378
+ end
379
+
380
+ def get_one(endpoint, id, params = {})
381
+ response = current_scope.get("#{endpoint}/#{id}", headers: headers,
382
+ body: params.to_json) do |request|
383
+ request.headers['Content-Type'] = 'application/json'
384
+ end
385
+
386
+ JSON.parse(response.body)
387
+ end
388
+
389
+ def post(endpoint, params = {})
390
+ response = current_scope.post(endpoint, headers: headers,
391
+ body: params.to_json) do |request|
392
+ request.headers['Content-Type'] = 'application/json'
393
+ end
394
+
395
+ JSON.parse(response.body)
396
+ end
397
+
398
+ def put_one(endpoint, id, params = {})
399
+ response = current_scope.put("#{endpoint}/#{id}", headers: headers,
400
+ body: params.to_json) do |request|
401
+ request.headers['Content-Type'] = 'application/json'
402
+ end
403
+
404
+ JSON.parse(response.body)
405
+ end
406
+
407
+ def delete_one(endpoint, id, params = {})
408
+ response = current_scope.delete("#{endpoint}/#{id}", headers: headers,
409
+ body: params.to_json) do |request|
410
+ request.headers['Content-Type'] = 'application/json'
411
+ end
412
+
413
+ if response.body.empty?
414
+ response.status == 204
415
+ else
416
+ JSON.parse(response.body)
417
+ end
418
+ end
419
+
420
+ # Refreshes the client token associated with this PokitDok connection
421
+ #
422
+ # FIXME: automatic refresh on expiration
423
+ #
424
+ def refresh_token(code=nil)
425
+ body = {}
426
+ body[:code] = code unless code.nil?
427
+
428
+ @client.client_credentials.get_token(
429
+ headers: { 'Authorization' => 'Basic' })
430
+ end
431
+
432
+ def scope(name)
433
+ raise ArgumentError, "You need to provide an authorization code for " \
434
+ "the scope #{name} with the scope_code method" if @scopes[name].nil?
435
+
436
+ @current_scope = name
437
+
438
+ if @scopes[name][:scope].nil?
439
+ @scopes[name][:scope] = refresh_token(@scopes[name][:code])
440
+ end
441
+
442
+ @scopes[name][:scope]
443
+ end
444
+
445
+ def current_scope
446
+ @scopes[@current_scope][:scope]
447
+ end
448
+
449
+ def default_scope
450
+ @scopes['default'][:scope]
451
+ end
216
452
  end
217
453
  end