smartwaiver-sdk 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7db8097383e5239cf525bdf325c02b7115a2154
4
+ data.tar.gz: de13abd5f6f4a0a9c9ada27ebdf613433c8e0b74
5
+ SHA512:
6
+ metadata.gz: 478a58a44cca53de3bc84cfd123cabb198fe17c4605018db4c963ffd1f3163984e0e79f9af168c8d22ac888ea45ca519172d8c99724058e4740c76f115fcbcdf
7
+ data.tar.gz: f0e8475bbb8a6b3668447b2e0d230f5ef1e074ca1d751f5e76b20d0f4909317d46329c021a66ad19ed4c747e511de918971490c2f1983a7f513db5a3edba23cf
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+
4
+ group :test, :development do
5
+ gem 'rspec'
6
+ gem 'rr'
7
+ gem 'fakeweb'
8
+ end
@@ -0,0 +1,402 @@
1
+ ![](https://d362q4tvy1elxj.cloudfront.net/header_logoheader.png)
2
+ RUBY-SDK
3
+ ==========
4
+
5
+ Table of Contents
6
+ =================
7
+
8
+ * [Table of contents](#table-of-contents)
9
+ * [Installation](#installation)
10
+ * [Getting Started](#getting-started)
11
+ * [Retrieve a Specific Template](#retrieve-a-specific-template)
12
+ * [List all Signed Waivers](#list-all-signed-waivers)
13
+ * [Retrieve a Specific Waiver](#retrieve-a-specific-waiver)
14
+ * [Retrieve/Set Webhook Config](#retrieveset-webhook-configuration)
15
+ * [Exception Handling](#exception-handling)
16
+ * [Status Codes](#status-codes)
17
+ * [Advanced](#advanced)
18
+ * [Authentication](#authentication)
19
+
20
+ Installation
21
+ ==========
22
+
23
+ gem install smartwaiver-sdk
24
+
25
+ Alternatively, you may install the SDK from the github repo:
26
+
27
+ git clone https://www.github.com/smartwaivercom/ruby-sdk
28
+
29
+ Getting Started
30
+ ==========
31
+
32
+ All that is required to start using the SDK is a Smartwaiver account and the API Key for that account.
33
+ In all of the examples you will need to put the API Key into the code wherever it says: `[INSERT API KEY]`
34
+
35
+ If running the examples from the project without installing the gem, you will need to set the RUBYLIB path.
36
+
37
+ export RUBYLIB=/Users/<user_name>/workspace/ruby-sdk/lib/smartwaiver-sdk
38
+
39
+
40
+ It's time to start making requests.
41
+ A good first request is to list all waiver templates for your account.
42
+ Here is the code to do that:
43
+
44
+ ```ruby
45
+ require 'smartwaiver-sdk/template_client'
46
+ # The API Key for your account
47
+ api_key = '[INSERT API KEY]'
48
+
49
+ # Set up your Smartwaiver client using your API Key
50
+ client = SmartwaiverTemplateClient.new(api_key)
51
+
52
+ # Now request a list of all the waiver templates
53
+ results = client.list
54
+ ```
55
+
56
+ That's it! You've just requested all waiver templates in your account.
57
+ But, now it's time to do something with them.
58
+ Let's loop through those templates and print out the ID and Title of each template:
59
+
60
+ ```ruby
61
+ result[:templates].each do |template|
62
+ puts "#{template[:templateId]}: #{template[:title]}"
63
+ end
64
+ ```
65
+
66
+ Awesome! For more details on all the different properties a waiver template has, check out [template_properties.rb](examples/templates/template_properties.rb)
67
+
68
+ Now that you've got your first request, check out the sections below to accomplish specific actions.
69
+
70
+ Retrieve a Specific Template
71
+ ---------
72
+
73
+ First let's set up the template client.
74
+ Make sure to put in your account's API Key where it says `[INSERT API KEY]`
75
+
76
+ ```ruby
77
+ require 'smartwaiver-sdk/template_client'
78
+ # The API Key for your account
79
+ api_key = '[INSERT API KEY]'
80
+
81
+ # Set up your Smartwaiver client using your API Key
82
+ client = SmartwaiverTemplateClient.new(api_key)
83
+ ```
84
+
85
+ Now we can request information about a specific template.
86
+ To do this we need the template ID.
87
+ If you don't know a template ID for your account, try listing all waiver templates for you account, as shown [here](#getting-started), and copying one of the ID's that is printed out.
88
+ Once we have a template ID we can execute a request to get the information about the template:
89
+
90
+ ```ruby
91
+ # The unique ID of the template to be retrieved
92
+ template_id = '[INSERT TEMPLATE ID]'
93
+
94
+ # Retrieve a specific template (SmartwaiverTemplate object)
95
+ template = client.get(template_id)
96
+ ```
97
+
98
+ Now let's print out some information about this template.
99
+
100
+ ```ruby
101
+ # Access properties of the template
102
+ puts "List single template:"
103
+ puts "#{template[:templateId]}: #{template[:title]}"
104
+ ```
105
+
106
+ To see all the different properties a waiver template has, check out [template_properties.rb](examples/templates/template_properties.rb)
107
+
108
+ List All Signed Waivers
109
+ ----------
110
+
111
+ First let's set up the basic Smartwaiver waiver client. Make sure to put in your account's API Key where it says `[INSERT API KEY]`
112
+
113
+ ```ruby
114
+ require 'smartwaiver-sdk/waiver_client'
115
+ # The API Key for your account
116
+ api_key = '[INSERT API KEY]'
117
+
118
+ # Set up your Smartwaiver client using your API Key
119
+ client = SmartwaiverWaiverClient.new(api_key)
120
+ ```
121
+
122
+ Now we can request signed waivers from your account.
123
+
124
+ ```ruby
125
+ # Get a list of summaries of waivers
126
+ waiver_summaries = client.list
127
+ ```
128
+
129
+ With this done, we can iterate over the returned summaries to see what is stored.
130
+ The default limit is 20, which means if you have more than 20 in your account, only the most recent 20 will be returned
131
+
132
+ ```ruby
133
+ puts "List all waivers:"
134
+ waiver_summaries[:waivers].each do |waiver|
135
+ puts "#{waiver[:waiverId]}: #{waiver[:title]}"
136
+ end
137
+ ```
138
+
139
+ To see all the different properties a waiver summary has, check out [waiver_summary_properties.rb](examples/waivers/waiver_summary_properties.rb)
140
+
141
+ Once we have a waiver summary, we can access all the detailed information about the waiver. To do that look [here](#retrieve-a-specific-waiver).
142
+
143
+ But, we can also restrict our query with some parameters.
144
+ For example, what if we only want to return 5 waivers, (the default is 20).
145
+ Here is the code to do that:
146
+
147
+ ```ruby
148
+ # Set the limit
149
+ limit = 5
150
+
151
+ # Get a list of summaries of waivers
152
+ waiver_summaries = client.list(limit)
153
+ ```
154
+
155
+ Or what if we only want any waivers that have not been verified (either by email or at the kiosk)?
156
+
157
+ ```ruby
158
+ # Set the limit
159
+ limit = 5
160
+
161
+ # Set the verified parameter
162
+ verified = false
163
+
164
+ # Get a list of summaries of waivers
165
+ waiver_summaries = client.list(limit, verified)
166
+ ```
167
+
168
+ What other parameters can you use? Here is an example using all of them:
169
+
170
+ ```ruby
171
+ # An example limiting the parameters
172
+ limit = 5 # Limit number returned to 5
173
+ verified = true # Limit only to waivers that were signed at a kiosk or verified over email
174
+ template_id = '[INSERT TEMPLATE ID]' # Limit query to waivers of this template ID
175
+ from_dts = '2016-11-01T00:00:00' # Limit to waivers signed in November of 2016
176
+ to_dts = '2016-12-01T00:00:00'
177
+
178
+ # Get a list of summaries of waivers
179
+ waiver_summaries = client.list(limit, verified, template_id, from_dts, to_dts)
180
+ ```
181
+
182
+ These examples are also available in [list_all_waivers.rb](examples/waivers/list_all_waivers.rb)
183
+
184
+ ###Parameter Options
185
+
186
+ | Parameter Name | Default Value | Accepted Values | Notes |
187
+ | -------------- | ------------- | ----------------- | ------------------------------------------------------------------------------------- |
188
+ | limit | 20 | 1 - 100 | Limit number of returned waivers |
189
+ | verified | null | true/false/null | Limit selection to waiver that have been verified (true), not (false), or both (null) |
190
+ | templateId | | Valid Template ID | Limit signed waivers to only this template |
191
+ | fromDts | | ISO 8601 Date | Limit to signed waivers between from and to dates (requires toDts) |
192
+ | toDts | | ISO 8601 Date | Limit to signed waivers between from and to dates (requires fromDts) |
193
+
194
+ Retrieve a Specific Waiver
195
+ ----------
196
+
197
+ What if we want to retrieve a specific waiver?
198
+ All we need for that is a waiver ID.
199
+ If you don't have a waiver ID to use, you can get a list of signed waivers in your account [here](#list-all-signed-waivers)
200
+
201
+ First let's set up the basic Smartwaiver object. Make sure to put in your account's API Key where it says `[INSERT API KEY]`
202
+
203
+ ```ruby
204
+ require 'smartwaiver-sdk/waiver_client'
205
+ # The API Key for your account
206
+ api_key = '[INSERT API KEY]'
207
+
208
+ # Set up your Smartwaiver client using your API Key
209
+ client = SmartwaiverWaiverClient.new(api_key)
210
+ ```
211
+
212
+ Now, we can request the information about a specific waiver.
213
+ Make sure to put your waiver ID in where it says `[INSERT WAIVER ID]`
214
+
215
+ ```ruby
216
+ # The unique ID of the signed waiver to be retrieved
217
+ waiver_id = '[INSERT WAIVER ID]'
218
+
219
+ # Get a specific waiver
220
+ result = client.get(waiver_id)
221
+ ```
222
+
223
+ The waiver object has many different properties that can be accessed.
224
+ For example, we can print out the waiver ID and title of the waiver.
225
+
226
+ ```ruby
227
+ # Access properties of waiver
228
+ waiver = result[:waiver]
229
+ puts "List single waiver:"
230
+ puts "#{waiver[:waiverId]}: #{waiver[:title]}"
231
+ ```
232
+
233
+ To see a full list of all properties that a waiver object contains, check out [waiver_properties.rb](examples/waivers/waiver_properties.rb)
234
+
235
+ We can also request that the PDF of the signed waiver as a Base 64 Encoded string be included. Here is the request to do that:
236
+
237
+ ```ruby
238
+ # The unique ID of the signed waiver to be retrieved
239
+ waiver_id = '[INSERT WAIVER ID]'
240
+
241
+ pdf = true
242
+
243
+ # Get the waiver object
244
+ result = client.get(waiver_id, pdf)
245
+ ```
246
+
247
+ The code provided here is also combined in to one example in [retrieve_single_waiver.rb](examples/waivers/retrieve_single_waiver.rb)
248
+
249
+ Retrieve/Set Webhook Configuration
250
+ ----------
251
+
252
+ You can both retrieve and set your account's webhook configuration through this SDK with a couple simple calls.
253
+ To view your current webhook settings, we first need to set a Smartwaiver object.
254
+ Make sure to put in your account's API Key where it says `[INSERT API KEY]`
255
+
256
+ ```ruby
257
+ require 'smartwaiver-sdk/webhook_client'
258
+ # The API Key for your account
259
+ api_key = '[INSERT API KEY]'
260
+
261
+ # Set up your Smartwaiver client using your API Key
262
+ client = SmartwaiverWebhookClient.new(api_key)
263
+ ```
264
+
265
+ Now, it's easy to request the webhook configuration:
266
+
267
+ ```ruby
268
+ # Get the current webhook settings
269
+ result = client.configuration
270
+ ```
271
+
272
+ And, now we can print out the information:
273
+
274
+ ```ruby
275
+ # Access the webhook config
276
+ puts "Endpoint: #{result[:webhooks][:endpoint]}"
277
+ puts "EmailValidationRequired: #{result[:webhooks][:emailValidationRequired]}"
278
+ ```
279
+
280
+ The Email Validation Required is whether the webhook will fire before, after, or before and after a waiver is verified.
281
+ The endpoint is simply the endpoint URL for the webhook.
282
+
283
+ And changing your webhook configuration is just as easy.
284
+ The new configuration will be returned from the request and can be access just like the read request above.
285
+
286
+ ```ruby
287
+ # The new values to set
288
+ endpoint = 'http://endpoint.example.org'
289
+ email_validation_required = SmartwaiverWebhookClient::WEBHOOK_AFTER_EMAIL_ONLY
290
+
291
+ # Set the webhook to new values
292
+ result = client.configure(end_point, send_after_email_only)
293
+
294
+ # Access the new webhook config
295
+ webhook = result[:webhooks]
296
+ puts "Successfully set new configuration."
297
+ puts "Endpoint: #{webhook[:endpoint]}"
298
+ puts "EmailValidationRequired: #{webhook[:emailValidationRequired]}"
299
+ ```
300
+
301
+ This code is also provided in [retrieve_webhooks.rb](examples/webhooks/retrieve_webhooks.rb)
302
+ and [set_webhooks.rb](examples/webhooks/set_webhooks.rb)
303
+
304
+ Exception Handling
305
+ ==========
306
+
307
+ There are three types of exceptions int the SDK:
308
+ * A <b>BadAPIKeyError</b> occurs if the API key is incorrect or missing.
309
+ * A <b>BadFormatError</b> occurs when trying to update the webhook configuration with incorrect data.
310
+ * All other types of errors will be a <b>RemoteServerError</b> which is thrown by the API server. The message returned explains the problem.
311
+
312
+ Here is an example of catching an HTTP exception. First we set up the Smartwaiver account:
313
+
314
+ ```ruby
315
+ require 'waiver_client'
316
+
317
+ # The API Key for your account
318
+ api_key='[INSERT API KEY]'
319
+
320
+ # The unique ID of the signed waiver to be retrieved
321
+
322
+ client = SmartwaiverWaiverClient.new(api_key)
323
+ ```
324
+
325
+ Next, we attempt to get a waiver that does not exist:
326
+
327
+ ```ruby
328
+ # The Waiver ID to access
329
+ waiver_id='InvalidWaiverId'
330
+
331
+ # Try to get the waiver object
332
+ result = client.get(waiver_id)
333
+ ```
334
+
335
+ This will throw an exception because a waiver with that ID does not exist. So let's change the code to catch that exception:
336
+
337
+ ```ruby
338
+ begin
339
+ # use default parameters
340
+ result = client.get(waiver_id)
341
+
342
+ waiver = result[:waiver]
343
+ puts "List single waiver:"
344
+ puts "#{waiver[:waiverId]}: #{waiver[:title]}"
345
+
346
+ result = client.get(waiver_id, true)
347
+
348
+ waiver = result[:waiver]
349
+ puts "PDF:"
350
+ puts "#{waiver[:pdf]}"
351
+
352
+ rescue SmartwaiverSDK::BadAPIKeyError=>bad
353
+ puts "API Key error: #{bad.message}"
354
+ rescue Exception=>e
355
+ puts "Exception thrown. Error during waiver retrieval: #{e.message}"
356
+ end
357
+ ```
358
+
359
+ But there is lot's of useful information in the exception object. Let's print some of that out too:
360
+
361
+ ```ruby
362
+ # The code will be the HTTP Status Code returned
363
+ puts "Error Message: #{e.message}"
364
+
365
+ # Also included in the exception is the header information returned about
366
+ # the response.
367
+ puts "API Version: #{e.result[:version]}"
368
+ puts "UUID: #{e.result[:id]}"
369
+ puts "Timestamp: #{e.result[:ts]}"
370
+ ```
371
+
372
+ Status Codes
373
+ ----------
374
+
375
+ The code of the exception will match the HTTP Status Code of the response and the message will be an informative string informing on what exactly was wrong with the request.
376
+
377
+ Possible status codes and their meanings:
378
+
379
+ | Status Code | Error Name | Description |
380
+ | ----------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
381
+ | 400 | Parameter Error | Indicates that something was wrong with the parameters of the request (e.g. extra parameters, missing required parameters, etc.). |
382
+ | 401 | Unauthorized | Indicates the request was missing an API Key or contained an invalid API Key. |
383
+ | 402 | Data Error | Indicates that the parameters of the request was valid, but the data in those parameters was not. |
384
+ | 404 | Not Found | Indicates that whatever was being searched for (specific waiver, etc.) could not be found. |
385
+ | 406 | Wrong Content Type | Indicates that the Content Type of the request is inappropriate for the request. |
386
+ | 500 | Internal Server Error | Indicates that the server encountered an internal error while processing the request. |
387
+
388
+ Advanced
389
+ ==========
390
+
391
+ This section contains notes about several more ways to use the SDK that are slightly more low level.
392
+
393
+
394
+ Authentication
395
+ ----------
396
+
397
+ If you are making custom requests you must include the proper authentication.
398
+ The Smartwaiver API expects a header called 'sw-api-key' to contain the API for the account you are accessing.
399
+
400
+ sw-api-key: [INSERT API KEY]
401
+
402
+ If you do not have a Smartwaiver API key go [here](https://www.smartwaiver.com/p/API) to find out how to create one.
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |task|
6
+ task.rspec_opts = '-c -f d'
7
+ end
8
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+
2
+ dir = File.dirname(__FILE__)
3
+
4
+ require 'net/https'
5
+ require 'uri'
6
+ require 'cgi'
7
+
8
+ require "#{dir}/smartwaiver-sdk/smartwaiver_errors"
9
+ require "#{dir}/smartwaiver-sdk/smartwaiver_base"
10
+ require "#{dir}/smartwaiver-sdk/smartwaiver_version"
@@ -0,0 +1,125 @@
1
+ #
2
+ # Copyright 2017 Smartwaiver
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+ # not use this file except in compliance with the License. You may obtain
6
+ # a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ require 'json'
17
+ require 'net/http'
18
+ require 'smartwaiver-sdk/smartwaiver_version'
19
+ require 'smartwaiver-sdk/smartwaiver_errors'
20
+
21
+ module SmartwaiverSDK
22
+
23
+ class SmartwaiverBase
24
+ DEFAULT_API_ENDPOINT = 'https://api.smartwaiver.com'
25
+ HEADER_API_KEY = 'sw-api-key'
26
+ HTTP_READ_TIMEOUT = 60
27
+
28
+ HTTP_GET = "GET"
29
+ HTTP_POST = "POST"
30
+ HTTP_PUT = "PUT"
31
+
32
+ def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
33
+ @api_endpoint = api_endpoint
34
+ @api_key = api_key
35
+ @http = nil
36
+ @http_read_timeout = HTTP_READ_TIMEOUT
37
+ init_http_connection(@api_endpoint)
38
+ end
39
+
40
+ def api_version
41
+ make_api_request("/version")
42
+ end
43
+
44
+ def format_iso_time(time)
45
+ time.strftime("%Y-%m-%dT%H:%M:%SZ")
46
+ end
47
+
48
+ def read_timeout(s)
49
+ if s > 0 and s < 600
50
+ @http_read_timeout = s
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def init_http_connection(target_server)
57
+ if (@http and @http.started?)
58
+ @http.finish
59
+ end
60
+ @last_init_time = Time.now.utc
61
+ endpoint_url = URI.parse(target_server)
62
+ @http = Net::HTTP.start(endpoint_url.host, endpoint_url.port, {:use_ssl => true, :read_timeout => @http_read_timeout})
63
+ @http
64
+ end
65
+
66
+ def common_http_headers
67
+ {'User-Agent' => SmartwaiverSDK::Info.get_user_agent, HEADER_API_KEY => @api_key}
68
+ end
69
+
70
+ def rest_post_headers
71
+ {"Content-Type" => "application/json"}
72
+ end
73
+
74
+ def make_api_request(path, request_type=HTTP_GET, data='')
75
+ if (@last_init_time < Time.now.utc - 60)
76
+ init_http_connection(@api_endpoint)
77
+ end
78
+
79
+ headers = common_http_headers
80
+ case request_type
81
+ when HTTP_GET
82
+ response = @http.request_get(path, headers)
83
+ when HTTP_PUT
84
+ headers = common_http_headers.merge(rest_post_headers)
85
+ response = @http.request_put(path, data, headers)
86
+ when HTTP_POST
87
+ headers = common_http_headers.merge(rest_post_headers)
88
+ response = @http.request_post(path, data, headers)
89
+ end
90
+ check_response(response)
91
+ end
92
+
93
+ def check_response(response)
94
+ response_data = parse_response_body(response.body)
95
+ case response
96
+ when Net::HTTPSuccess
97
+ return response_data
98
+ when Net::HTTPUnauthorized
99
+ raise SmartwaiverSDK::BadAPIKeyError.new("#{response.code.to_s}:#{response_data[:message]}", response_data)
100
+ when Net::HTTPNotAcceptable
101
+ raise SmartwaiverSDK::BadFormatError.new("#{response.code.to_s}:#{response_data[:message]}", response_data)
102
+ when Net::HTTPClientError, Net::HTTPServerError
103
+ raise SmartwaiverSDK::RemoteServerError.new("#{response.code.to_s}:#{response_data[:message]}", response_data)
104
+ else
105
+ raise SmartwaiverSDK::RemoteServerError.new("#{response_data[:message]}", response_data)
106
+ end
107
+ end
108
+
109
+ def parse_response_body(body)
110
+ begin
111
+ return JSON.parse(body, :symbolize_names => :symbolize_names)
112
+ rescue JSON::ParserError => e
113
+ return base_response_params.merge!({:message => e.message})
114
+ end
115
+ end
116
+
117
+ def base_response_params
118
+ {:version => 0,
119
+ :id => "",
120
+ :ts => "1970-01-01T00:00:00+00:00",
121
+ :type => ""
122
+ }
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,35 @@
1
+ #
2
+ # Copyright 2017 Smartwaiver
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+ # not use this file except in compliance with the License. You may obtain
6
+ # a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ module SmartwaiverSDK
17
+
18
+ class SmartwaiverError < StandardError
19
+ attr_reader :result
20
+ def initialize(message, result={})
21
+ super(message)
22
+ @result = result
23
+ end
24
+ end
25
+
26
+ class BadAPIKeyError < SmartwaiverError
27
+ end
28
+
29
+ class BadFormatError < SmartwaiverError
30
+ end
31
+
32
+ class RemoteServerError < SmartwaiverError
33
+ end
34
+
35
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ # Copyright 2017 Smartwaiver
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+ # not use this file except in compliance with the License. You may obtain
6
+ # a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ module SmartwaiverSDK
17
+ VERSION = "4.0.0"
18
+
19
+ class Info
20
+ @@ClientVersion = SmartwaiverSDK::VERSION
21
+ @@RubyVersion = RUBY_VERSION
22
+ @@UserAgent = "SmartwaiverAPI:#{@@ClientVersion}-Ruby:#{@@RubyVersion}";
23
+
24
+ def self.get_user_agent
25
+ return @@UserAgent
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright 2017 Smartwaiver
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+ # not use this file except in compliance with the License. You may obtain
6
+ # a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ require 'smartwaiver-sdk/smartwaiver_base'
17
+
18
+ class SmartwaiverTemplateClient < SmartwaiverSDK::SmartwaiverBase
19
+
20
+ def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
21
+ super(api_key, api_endpoint)
22
+ @rest_endpoints = define_rest_endpoints
23
+ end
24
+
25
+ def list
26
+ path = @rest_endpoints[:configure]
27
+ make_api_request(path, HTTP_GET)
28
+ end
29
+
30
+ def get(template_id)
31
+ path = "#{@rest_endpoints[:configure]}/#{template_id}"
32
+ make_api_request(path, HTTP_GET)
33
+ end
34
+
35
+ private
36
+
37
+ def define_rest_endpoints
38
+ {
39
+ :configure => "/v4/templates"
40
+ }
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # Copyright 2017 Smartwaiver
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+ # not use this file except in compliance with the License. You may obtain
6
+ # a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ require 'smartwaiver-sdk/smartwaiver_base'
17
+
18
+ class SmartwaiverWaiverClient < SmartwaiverSDK::SmartwaiverBase
19
+
20
+ def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
21
+ super(api_key, api_endpoint)
22
+ @rest_endpoints = define_rest_endpoints
23
+ end
24
+
25
+ def list(limit = 20, verified = nil, template_id = '', from_dts = '', to_dts = '')
26
+ path = "#{@rest_endpoints[:waivers]}?limit=#{limit}"
27
+ if !verified.nil?
28
+ path = "#{path}&verified=" + (verified ? 'true' : 'false')
29
+ end
30
+ if !template_id.empty?
31
+ path = "#{path}&templateId=#{template_id}"
32
+ end
33
+ if !from_dts.empty?
34
+ path = "#{path}&fromDts=#{from_dts}"
35
+ end
36
+ if !to_dts.empty?
37
+ path = "#{path}&toDts=#{to_dts}"
38
+ end
39
+ make_api_request(path, HTTP_GET)
40
+ end
41
+
42
+ def get(waiver_id, pdf=false)
43
+ path = "#{@rest_endpoints[:waivers]}/#{waiver_id}?pdf=" + (pdf ? 'true' : 'false')
44
+ make_api_request(path, HTTP_GET)
45
+ end
46
+
47
+ private
48
+
49
+ def define_rest_endpoints
50
+ {
51
+ :waivers => "/v4/waivers"
52
+ }
53
+ end
54
+ end
55
+
@@ -0,0 +1,47 @@
1
+ #
2
+ # Copyright 2017 Smartwaiver
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+ # not use this file except in compliance with the License. You may obtain
6
+ # a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ require 'smartwaiver-sdk/smartwaiver_base'
17
+
18
+ class SmartwaiverWebhookClient < SmartwaiverSDK::SmartwaiverBase
19
+
20
+ WEBHOOK_AFTER_EMAIL_ONLY = 'yes'
21
+ WEBHOOK_BEFORE_EMAIL_ONLY = 'no'
22
+ WEBHOOK_BEFORE_AND_AFTER_EMAIL = 'both'
23
+
24
+ def initialize(api_key, api_endpoint = DEFAULT_API_ENDPOINT)
25
+ super(api_key, api_endpoint)
26
+ @rest_endpoints = define_rest_endpoints
27
+ end
28
+
29
+ def configuration
30
+ path = @rest_endpoints[:configure]
31
+ make_api_request(path, HTTP_GET)
32
+ end
33
+
34
+ def configure(endpoint, email_validation_required)
35
+ path = @rest_endpoints[:configure]
36
+ json = {:endpoint => endpoint, :emailValidationRequired => email_validation_required}.to_json
37
+ make_api_request(path, HTTP_PUT, json)
38
+ end
39
+
40
+ private
41
+
42
+ def define_rest_endpoints
43
+ {
44
+ :configure => "/v4/webhooks/configure"
45
+ }
46
+ end
47
+ end
@@ -0,0 +1,203 @@
1
+
2
+ dir = File.dirname(__FILE__)
3
+ require "#{dir}/../spec_helper"
4
+ require "#{dir}/../../lib/smartwaiver-sdk/smartwaiver_base"
5
+
6
+ class SmartwaiverTest < SmartwaiverSDK::SmartwaiverBase
7
+ def get_test(path)
8
+ make_api_request(path, HTTP_GET)
9
+ end
10
+
11
+ def post_test(path, data)
12
+ make_api_request(path, HTTP_POST, data)
13
+ end
14
+
15
+ def put_test(path, data)
16
+ make_api_request(path, HTTP_PUT, data)
17
+ end
18
+
19
+ def parse_response_body_test(data)
20
+ parse_response_body(data)
21
+ end
22
+
23
+ def check_response_test(response)
24
+ check_response(response)
25
+ end
26
+
27
+ end
28
+
29
+ describe SmartwaiverSDK::SmartwaiverBase do
30
+
31
+ before do
32
+ FakeWeb.allow_net_connect = false
33
+ @api_key = "apikey"
34
+ end
35
+
36
+ describe "smartwaiver base object set up correctly" do
37
+ it "has correct headers and accepts a custom endpoint" do
38
+ test_endpoint = 'https://testapi.smartwaiver.com'
39
+ client = SmartwaiverSDK::SmartwaiverBase.new(@api_key, test_endpoint)
40
+ expect(client.instance_eval('@http').address).to eq("testapi.smartwaiver.com")
41
+ end
42
+ end
43
+
44
+ describe "#version" do
45
+ it "retrieves the current version of the API" do
46
+ FakeWeb.register_uri(:get, "https://api.smartwaiver.com/version", :body => json_api_version_results)
47
+ client = SmartwaiverSDK::SmartwaiverBase.new(@api_key)
48
+ version = client.api_version
49
+
50
+ expect(version[:version]).to eq(SmartwaiverSDK::VERSION)
51
+ end
52
+ end
53
+
54
+ describe "#make_api_request" do
55
+ before do
56
+ @client = SmartwaiverTest.new(@api_key)
57
+ end
58
+
59
+ it "GET" do
60
+ path = "#{API_URL}/get_test"
61
+ FakeWeb.register_uri(:get, path, :body => json_base_results)
62
+ @client.get_test(path)
63
+
64
+ request = FakeWeb.last_request
65
+ expect(request.method).to eq("GET")
66
+ expect(request.body).to eq(nil)
67
+ request.each_header do |key, value|
68
+ case key
69
+ when "user-agent"
70
+ expect(value).to match(/^SmartwaiverAPI*/)
71
+ when "sw-api-key"
72
+ expect(value).to eq(@api_key)
73
+ end
74
+ end
75
+ end
76
+
77
+ it "POST" do
78
+ path = "#{API_URL}/post_test"
79
+ data = "{\"json\":\"data\"}"
80
+ FakeWeb.register_uri(:post, path, :body => json_base_results)
81
+ @client.post_test(path, data)
82
+
83
+ request = FakeWeb.last_request
84
+ expect(request.method).to eq("POST")
85
+ expect(request.body).to eq(data)
86
+ request.each_header do |key, value|
87
+ case key
88
+ when "user-agent"
89
+ expect(value).to match(/^SmartwaiverAPI*/)
90
+ when "sw-api-key"
91
+ expect(value).to eq(@api_key)
92
+ when "content-type"
93
+ expect(value).to eq("application/json")
94
+ end
95
+ end
96
+ end
97
+
98
+ it "PUT" do
99
+ path = "#{API_URL}/put_test"
100
+ data = "{\"json\":\"data\"}"
101
+ FakeWeb.register_uri(:put, path, :body => json_base_results)
102
+ @client.put_test(path, data)
103
+
104
+ request = FakeWeb.last_request
105
+ expect(request.method).to eq("PUT")
106
+ expect(request.body).to eq(data)
107
+ request.each_header do |key, value|
108
+ case key
109
+ when "user-agent"
110
+ expect(value).to match(/^SmartwaiverAPI*/)
111
+ when "sw-api-key"
112
+ expect(value).to eq(@api_key)
113
+ when "content-type"
114
+ expect(value).to eq("application/json")
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ describe "#parse_response_body" do
121
+ before do
122
+ @client = SmartwaiverTest.new(@api_key)
123
+ end
124
+
125
+ it "parses valid json" do
126
+ json = '{"version":4, "id":"8e82fa534da14b76a05013644ee735d2", "ts":"2017-01-17T15:46:58+00:00", "type":"test"}'
127
+ data = @client.parse_response_body_test(json)
128
+
129
+ expect(data[:version]).to eq(4)
130
+ expect(data[:id]).to eq("8e82fa534da14b76a05013644ee735d2")
131
+ expect(data[:ts]).to eq("2017-01-17T15:46:58+00:00")
132
+ expect(data[:type]).to eq("test")
133
+ end
134
+
135
+ it "returns base parameters if json is invalid" do
136
+ json = 'bad-json'
137
+ data = @client.parse_response_body_test(json)
138
+
139
+ expect(data[:version]).to eq(0)
140
+ expect(data[:id]).to eq("")
141
+ expect(data[:ts]).to eq("1970-01-01T00:00:00+00:00")
142
+ expect(data[:type]).to eq("")
143
+ end
144
+ end
145
+
146
+ describe "#check_response" do
147
+ it "HTTP 200" do
148
+ path = "#{API_URL}/get_test"
149
+ FakeWeb.register_uri(:get, path, :body => json_base_results)
150
+ uri = URI.parse(path)
151
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |req|
152
+ response = req.get('/get_test')
153
+ @client = SmartwaiverTest.new(@api_key)
154
+ expect {@client.check_response_test(response)}.to_not raise_error
155
+ end
156
+ end
157
+
158
+ it "HTTP Unauthorized" do
159
+ path = "#{API_URL}/error_test"
160
+ FakeWeb.register_uri(:get, path, :body => json_base_results, :status => ["401", "Unauthorized"])
161
+ uri = URI.parse(path)
162
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |req|
163
+ response = req.get('/error_test')
164
+ @client = SmartwaiverTest.new(@api_key)
165
+ expect {@client.check_response_test(response)}.to raise_error(SmartwaiverSDK::BadAPIKeyError)
166
+ end
167
+
168
+ end
169
+
170
+ it "HTTP NotAcceptable" do
171
+ path = "#{API_URL}/error_test"
172
+ FakeWeb.register_uri(:get, path, :body => json_base_results, :status => ["406", "Not Acceptable"])
173
+ uri = URI.parse(path)
174
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |req|
175
+ response = req.get('/error_test')
176
+ @client = SmartwaiverTest.new(@api_key)
177
+ expect {@client.check_response_test(response)}.to raise_error(SmartwaiverSDK::BadFormatError)
178
+ end
179
+ end
180
+
181
+ it "HTTP Client Error" do
182
+ path = "#{API_URL}/error_test"
183
+ FakeWeb.register_uri(:get, path, :body => json_base_results, :status => ["404", "Not Found"])
184
+ uri = URI.parse(path)
185
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |req|
186
+ response = req.get('/error_test')
187
+ @client = SmartwaiverTest.new(@api_key)
188
+ expect {@client.check_response_test(response)}.to raise_error(SmartwaiverSDK::RemoteServerError)
189
+ end
190
+ end
191
+
192
+ it "HTTP Server Error" do
193
+ path = "#{API_URL}/error_test"
194
+ FakeWeb.register_uri(:get, path, :body => json_base_results, :status => ["500", "Internal Server Error"])
195
+ uri = URI.parse(path)
196
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |req|
197
+ response = req.get('/error_test')
198
+ @client = SmartwaiverTest.new(@api_key)
199
+ expect {@client.check_response_test(response)}.to raise_error(SmartwaiverSDK::RemoteServerError)
200
+ end
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,35 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../spec_helper"
3
+ require "#{dir}/../../lib/smartwaiver-sdk/template_client"
4
+
5
+ describe SmartwaiverTemplateClient do
6
+ attr_reader :client, :api_key
7
+
8
+ before do
9
+ FakeWeb.allow_net_connect = false
10
+ @api_key = "apikey"
11
+ @client = SmartwaiverTemplateClient.new(@api_key)
12
+ end
13
+
14
+ describe "templates" do
15
+ it "#initialize" do
16
+ expect(@client).to be_kind_of(SmartwaiverTemplateClient)
17
+ end
18
+
19
+ it "#list" do
20
+ path = "#{API_URL}/v4/templates"
21
+ FakeWeb.register_uri(:get, path, :body => json_template_list_results)
22
+ result = @client.list
23
+
24
+ expect(result[:templates].length).to eq(3)
25
+ end
26
+
27
+ it "#get" do
28
+ template_id = "586ffe15134bc"
29
+ path = "#{API_URL}/v4/templates/#{template_id}"
30
+ FakeWeb.register_uri(:get, path, :body => json_template_single_results)
31
+ result = @client.get(template_id)
32
+ expect(result[:template][:templateId]).to eq(template_id)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../spec_helper"
3
+ require "#{dir}/../../lib/smartwaiver-sdk/waiver_client"
4
+
5
+ describe SmartwaiverWaiverClient do
6
+ attr_reader :client, :api_key
7
+
8
+ before do
9
+ FakeWeb.allow_net_connect = false
10
+ @api_key = "apikey"
11
+ @client = SmartwaiverWaiverClient.new(@api_key)
12
+ end
13
+
14
+ describe "waivers" do
15
+ it "#initialize" do
16
+ expect(@client).to be_kind_of(SmartwaiverWaiverClient)
17
+ end
18
+
19
+ it "#list all default values" do
20
+ path = "#{API_URL}/v4/waivers?limit=20"
21
+ FakeWeb.register_uri(:get, path, :body => json_waiver_list_results)
22
+ result = @client.list
23
+ expect(result[:waivers].length).to eq(3)
24
+ end
25
+
26
+ it "#list with all values specified" do
27
+ limit = 3
28
+ verified = true
29
+ template_id = "586ffe15134bd"
30
+ from_dts = '2017-01-01T00:00:00Z'
31
+ to_dts = '2017-02-01T00:00:00Z'
32
+
33
+ path = "#{API_URL}/v4/waivers?limit=#{limit}&verified=#{verified}&templateId=#{template_id}&fromDts=#{from_dts}&toDts=#{to_dts}"
34
+ FakeWeb.register_uri(:get, path, :body => json_waiver_list_results)
35
+ @client.list(limit, verified, template_id, from_dts, to_dts)
36
+ end
37
+
38
+ it "#get without pdf" do
39
+ waiver_id = "Vzy8f6gnCWVcQBURdydwPT"
40
+ path = "#{API_URL}/v4/waivers/#{waiver_id}?pdf=false"
41
+ FakeWeb.register_uri(:get, path, :body => json_waiver_single_results)
42
+ result = @client.get(waiver_id)
43
+
44
+ expect(result[:waiver][:waiverId]).to eq(waiver_id)
45
+ expect(result[:waiver][:participants].length).to eq(2)
46
+ expect(result[:waiver][:customWaiverFields][:"58458759da897"][:value]).to eq ("Testing")
47
+ end
48
+
49
+ it "#get with pdf" do
50
+ waiver_id = "Vzy8f6gnCWVcQBURdydwPT"
51
+ path = "#{API_URL}/v4/waivers/#{waiver_id}?pdf=true"
52
+ FakeWeb.register_uri(:get, path, :body => json_waiver_single_results)
53
+ @client.get(waiver_id, true)
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,40 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../spec_helper"
3
+ require "#{dir}/../../lib/smartwaiver-sdk/webhook_client"
4
+
5
+ describe SmartwaiverWebhookClient do
6
+ attr_reader :client, :api_key
7
+
8
+ before do
9
+ FakeWeb.allow_net_connect = false
10
+ @api_key = "apikey"
11
+ @client = SmartwaiverWebhookClient.new(@api_key)
12
+ end
13
+
14
+ describe "webhooks" do
15
+ it "#initialize" do
16
+ expect(@client).to be_kind_of(SmartwaiverWebhookClient)
17
+ end
18
+
19
+ it "#configuration" do
20
+ path="#{API_URL}/v4/webhooks/configure"
21
+ FakeWeb.register_uri(:get, path, :body => json_webhook_configuration_results)
22
+
23
+ response = @client.configuration
24
+ expect(response[:webhooks].length).to eq(2)
25
+ end
26
+
27
+ it "#configure" do
28
+ endpoint="http://requestb.in/1ajthro1"
29
+ email_validation_required="yes"
30
+
31
+ path="#{API_URL}/v4/webhooks/configure"
32
+ FakeWeb.register_uri(:put, path, :body => json_webhook_configuration_results)
33
+
34
+ response = @client.configure(endpoint, email_validation_required)
35
+ expect(response[:webhooks][:endpoint]).to eq(endpoint)
36
+ expect(response[:webhooks][:emailValidationRequired]).to eq(email_validation_required)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,129 @@
1
+ dir = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'fakeweb'
5
+ require 'rr'
6
+ require 'json'
7
+
8
+ $LOAD_PATH << "#{dir}/../lib/smartwaiver-sdk"
9
+ require 'smartwaiver_base'
10
+ require 'smartwaiver_errors'
11
+
12
+ API_URL = 'https://api.smartwaiver.com'
13
+
14
+ def json_parse(data)
15
+ JSON.parse(data, :symbolize_names => true)
16
+ end
17
+
18
+ def json_api_version_results
19
+ json = <<JAVASCRIPT
20
+ {"version": "4.0.0"}
21
+ JAVASCRIPT
22
+ json
23
+ end
24
+
25
+ def json_base_results
26
+ json = <<JAVASCRIPT
27
+ {"version":4, "id":"8e82fa534da14b76a05013644ee735d2", "ts":"2017-01-17T15:46:58+00:00", "type":""}
28
+ JAVASCRIPT
29
+ end
30
+
31
+ def json_webhook_configuration_results
32
+ json = <<JAVASCRIPT
33
+ {"version":4, "id":"8e82fa534da14b76a05013644ee735d2", "ts":"2017-01-17T15:46:58+00:00", "type":"webhooks", "webhooks":{"endpoint":"http://requestb.in/1ajthro1", "emailValidationRequired":"yes"}}
34
+ JAVASCRIPT
35
+ end
36
+
37
+ def json_webhook_configure_results
38
+ json = <<JAVASCRIPT
39
+ {"version":4, "id":"8e82fa534da14b76a05013644ee735d2", "ts":"2017-01-17T15:46:58+00:00", "type":"webhooks", "webhooks":{"endpoint":"http://requestb.in/1ajthro2", "emailValidationRequired":"yes"}}
40
+ JAVASCRIPT
41
+ end
42
+
43
+
44
+ def json_template_list_results
45
+ json = <<JAVASCRIPT
46
+ {"version":4,"id":"05928f4b1b3849c9a73aca257808f1d5","ts":"2017-01-17T22:33:56+00:00","type":"templates","templates":
47
+ [{"templateId":"586ffe15134bc","title":"Template 1","publishedVersion":1,"publishedOn":"2017-01-06 20:33:35","webUrl":"https:\/\/www.smartwaiver.com\/w\/586ffe15134bc\/web\/","kioskUrl":"https:\/\/www.smartwaiver.com\/w\/586ffe15134bc\/kiosk\/"},
48
+ {"templateId":"5845e3a0add4d","title":"Template 2","publishedVersion":3,"publishedOn":"2017-01-05 20:33:35","webUrl":"https:\/\/www.smartwaiver.com\/w\/5845e3a0add4d\/web\/","kioskUrl":"https:\/\/www.smartwaiver.com\/w\/5845e3a0add4d\/kiosk\/"},
49
+ {"templateId":"56ce3bb69c748","title":"Template 3","publishedVersion":4,"publishedOn":"2016-02-24 23:34:37","webUrl":"https:\/\/www.smartwaiver.com\/w\/56ce3bb69c748\/web\/","kioskUrl":"https:\/\/www.smartwaiver.com\/w\/56ce3bb69c748\/kiosk\/"}
50
+ ]
51
+ }
52
+ JAVASCRIPT
53
+ end
54
+
55
+ def json_template_single_results
56
+ json = <<JAVASCRIPT
57
+ {"version":4,"id":"81b24d6b6c364ead9af037c5652b897e","ts":"2017-01-19T01:02:36+00:00","type":"template","template":{"templateId":"586ffe15134bc","title":"Template 1","publishedVersion":1,"publishedOn":"2017-01-06 20:33:35","webUrl":"https:\/\/www.smartwaiver.com\/w\/586ffe15134bc\/web\/","kioskUrl":"https:\/\/www.smartwaiver.com\/w\/586ffe15134bc\/kiosk\/"}}
58
+ JAVASCRIPT
59
+ end
60
+
61
+ def json_waiver_list_results
62
+ json = <<JAVASCRIPT
63
+ {"version":4,"id":"f73838873a6b470d804ff2cfe002e0de","ts":"2017-01-19T01:18:42+00:00","type":"waivers","waivers":
64
+ [{"waiverId":"Vzy8f6gnCWVcQBURdydwPT","templateId":"586ffe15134bc","title":"Template 1","createdOn":"2017-01-06 21:28:13","expirationDate":"","expired":false,"verified":true,"kiosk":true,"firstName":"John","middleName":"","lastName":"Doe","dob":"1987-06-09","isMinor":false,"tags":[]},
65
+ {"waiverId":"ko4C4rcUvHe3VnfKJ2Cmr6","templateId":"586ffe15134bc","title":"Template 1","createdOn":"2017-01-06 21:25:26","expirationDate":"","expired":false,"verified":true,"kiosk":true,"firstName":"Jane","middleName":"","lastName":"Doe","dob":"1983-07-01","isMinor":false,"tags":[]},
66
+ {"waiverId":"VUey8JHxC4ED2r7jiWszNE","templateId":"586ffe15134bc","title":"Template 1","createdOn":"2017-01-06 20:39:03","expirationDate":"","expired":false,"verified":true,"kiosk":true,"firstName":"Jimmy","middleName":"","lastName":"Smith","dob":"1980-03-07","isMinor":false,"tags":[]}
67
+ ]}
68
+ JAVASCRIPT
69
+ end
70
+
71
+ def json_waiver_single_results
72
+ json = <<JAVASCRIPT
73
+ {"version":4,"id":"7730a96154874baca44ec7ac3444ebee","ts":"2017-01-19T01:22:50+00:00","type":"waiver","waiver":
74
+ {"waiverId":"Vzy8f6gnCWVcQBURdydwPT",
75
+ "templateId":"586ffe15134bc",
76
+ "title":"Template 1",
77
+ "createdOn":"2016-12-05 19:58:42",
78
+ "expirationDate":"",
79
+ "expired":false,
80
+ "verified":true,
81
+ "kiosk":false,
82
+ "firstName":"Jane",
83
+ "middleName":"L",
84
+ "lastName":"Smith",
85
+ "dob":"2004-07-01",
86
+ "isMinor":true,
87
+ "tags":[],
88
+ "participants":[
89
+ {"firstName":"Jane",
90
+ "middleName":"L",
91
+ "lastName":"Smith",
92
+ "dob":"2004-07-01",
93
+ "isMinor":true,
94
+ "gender":"Female",
95
+ "phone":"888-555-1214",
96
+ "tags":[],
97
+ "customParticipantFields":{"58458713a384a":{"value":"Short","displayText":"Custom text for minor"}}
98
+ },
99
+ {"firstName":"Joe",
100
+ "middleName":"",
101
+ "lastName":"Smith",
102
+ "dob":"1969-02-02",
103
+ "isMinor":false,
104
+ "gender":"Male",
105
+ "phone":"888-555-1213",
106
+ "tags":[],
107
+ "customParticipantFields":{"58458713a384a":{"value":"Hello World","displayText":"Custom text for minor"}}}
108
+ ],
109
+ "customWaiverFields":{"58458759da897":{"value":"Testing","displayText":"Question at waiver fields"}},
110
+ "guardian":null,
111
+ "email":"cs@smartwaiver.com",
112
+ "marketingAllowed":true,
113
+ "addressLineOne":"123 Main St",
114
+ "addressLineTwo":"",
115
+ "addressCity":"Bend",
116
+ "addressState":"OR",
117
+ "addressZip":"97703",
118
+ "addressCountry":"US",
119
+ "emergencyContactName":"John Doe",
120
+ "emergencyContactPhone":"888-555-1212",
121
+ "insuranceCarrier":"BlueCross",
122
+ "insurancePolicyNumber":"X001234",
123
+ "driversLicenseNumber":"C1234324",
124
+ "driversLicenseState":"CA",
125
+ "clientIP":"127.0.0.1",
126
+ "pdf":""}
127
+ }
128
+ JAVASCRIPT
129
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartwaiver-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Smartwaiver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The Smartwaiver SDK uses version 4 of the Smartwaiver API
14
+ email:
15
+ - cs@smartwaiver.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - README.md
22
+ - Rakefile
23
+ - lib/smartwaiver-sdk.rb
24
+ - lib/smartwaiver-sdk/smartwaiver_base.rb
25
+ - lib/smartwaiver-sdk/smartwaiver_errors.rb
26
+ - lib/smartwaiver-sdk/smartwaiver_version.rb
27
+ - lib/smartwaiver-sdk/template_client.rb
28
+ - lib/smartwaiver-sdk/waiver_client.rb
29
+ - lib/smartwaiver-sdk/webhook_client.rb
30
+ - spec/smartwaiver-sdk/base_spec.rb
31
+ - spec/smartwaiver-sdk/template_client_spec.rb
32
+ - spec/smartwaiver-sdk/waiver_client_spec.rb
33
+ - spec/smartwaiver-sdk/webhook_client_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage: https://github.com/smartwaivercom/ruby-sdk
36
+ licenses:
37
+ - Apache-2.0
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ - lib/smartwaiver-sdk
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project: smartwaiver-sdk
56
+ rubygems_version: 2.6.8
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Smartwaiver SDK for version 4 of the API
60
+ test_files:
61
+ - spec/smartwaiver-sdk/base_spec.rb
62
+ - spec/smartwaiver-sdk/template_client_spec.rb
63
+ - spec/smartwaiver-sdk/waiver_client_spec.rb
64
+ - spec/smartwaiver-sdk/webhook_client_spec.rb
65
+ - spec/spec_helper.rb