touchpass 0.1.1 → 0.1.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- touchpass (0.0.8.18)
4
+ touchpass (0.1.0)
5
5
  geocoder (~> 1.1.0)
6
6
  httparty (~> 0.8.0)
7
7
  json (~> 1.6.5)
@@ -18,7 +18,7 @@ GEM
18
18
  hashie
19
19
  diff-lcs (1.1.3)
20
20
  ffi (1.0.11)
21
- geocoder (1.1.2)
21
+ geocoder (1.1.4)
22
22
  growl (1.0.3)
23
23
  guard (1.0.2)
24
24
  ffi (>= 0.5.0)
@@ -41,7 +41,7 @@ GEM
41
41
  diff-lcs (~> 1.1.3)
42
42
  rspec-mocks (2.10.1)
43
43
  thor (0.14.6)
44
- xml-simple (1.1.1)
44
+ xml-simple (1.1.2)
45
45
  yamler (0.1.0)
46
46
 
47
47
  PLATFORMS
data/bin/touchpass CHANGED
@@ -270,7 +270,7 @@ class TpCLI < Thor
270
270
  when :xml
271
271
  puts XmlSimple.xml_out(response, 'NoAttr' => true, 'RootName' => 'response')
272
272
  when :json
273
- puts JSON.pretty_generate(response)
273
+ puts JSON.pretty_generate(response.to_h)
274
274
  end
275
275
  end
276
276
 
@@ -69,7 +69,7 @@ module Touchpass
69
69
  response
70
70
  end
71
71
 
72
- # Get details for a party
72
+ # Get details for a party (by party id)
73
73
  def get_party_by_id(party_id, options = {})
74
74
  require_api_key
75
75
  require_param(party_id, "party id")
@@ -78,6 +78,7 @@ module Touchpass
78
78
  submit_request("get", party_url_id(party_id), http_options)
79
79
  end
80
80
 
81
+ # Get details for a party (by username)
81
82
  def get_party(username, options = {})
82
83
  require_api_key
83
84
  require_param(username, "username")
@@ -87,7 +88,7 @@ module Touchpass
87
88
  end
88
89
 
89
90
  # Update details for a party
90
- # uses options: :email, :first_name, :last_name
91
+ # options: :email, :first_name, :last_name, :username
91
92
  def update_party_by_id(party_id, options = {})
92
93
  require_api_key
93
94
  require_param(party_id, "party id")
@@ -96,6 +97,8 @@ module Touchpass
96
97
  submit_request("put", party_url_id(party_id), http_options)
97
98
  end
98
99
 
100
+ # Update details for a party
101
+ # options: :email, :first_name, :last_name, :username
99
102
  def update_party(username, options = {})
100
103
  require_api_key
101
104
  require_param(username, "username")
@@ -105,7 +108,7 @@ module Touchpass
105
108
  end
106
109
 
107
110
  # Register a new device for a party
108
- # uses: :messaging_type, :messaging_value
111
+ # options: :messaging_type, :messaging_value
109
112
  def register_device(username, udid, name, app_id, options = {})
110
113
  require_api_key
111
114
  require_param(username, "username")
@@ -156,7 +159,6 @@ module Touchpass
156
159
  end
157
160
 
158
161
  # Get all devices for a party
159
- # needs: :username
160
162
  def get_devices(username, options = {})
161
163
  require_api_key
162
164
  require_param(username, "username")
@@ -174,8 +176,7 @@ module Touchpass
174
176
  end
175
177
  end
176
178
 
177
- # Get details for a specific device, returns an 'errors' hash if
178
- # the device cannot be found
179
+ # Get details for a specific device
179
180
  def get_device(username, device_id, options = {})
180
181
  require_api_key
181
182
  require_param(username, "username")
@@ -187,8 +188,8 @@ module Touchpass
187
188
  submit_request("get", url, http_options)
188
189
  end
189
190
 
190
- # Update details of a device, returns an 'errors' hash if the device cannot be found
191
- # uses options: :name, :messaging_type, :messaging_value, :update_pub_key
191
+ # Update details of a device
192
+ # options: :name, :messaging_type, :messaging_value, :update_pub_key
192
193
  def update_device(username, device_id, options = {})
193
194
  require_api_key
194
195
  require_param(username, "username")
@@ -201,7 +202,7 @@ module Touchpass
201
202
  submit_request("put", url, http_options)
202
203
  end
203
204
 
204
- # Remove device, returns an 'errors' hash if the device cannot be found
205
+ # Remove device
205
206
  def remove_device(username, device_id, options = {})
206
207
  require_api_key
207
208
  require_param(username, "username")
@@ -225,7 +226,9 @@ module Touchpass
225
226
  # them using each device's public key.
226
227
  http_options = standard_http_options(options)
227
228
  response = submit_request("get", "#{@hostname}/#{to_party}/devices", http_options)
228
- vp_devices = response["devices"]
229
+
230
+ vp_devices = response["devices"] || []
231
+ raise "VP has no registered devices" if vp_devices.empty?
229
232
 
230
233
  # create a verification object
231
234
  options = options.merge(:to_party => to_party)
@@ -233,7 +236,10 @@ module Touchpass
233
236
  http_options = standard_http_options(options, %W{to_party to_device_id to_app_id})
234
237
  http_options[:body].merge!(verification.http_params)
235
238
 
236
- submit_request("post", "#{@hostname}/verifications", http_options)
239
+ response = submit_request("post", "#{@hostname}/verifications", http_options)
240
+
241
+ verification.attributes = response
242
+ verification
237
243
  end
238
244
 
239
245
  # Get a page of verifications for a particular party id
@@ -267,8 +273,25 @@ module Touchpass
267
273
  submit_request("get", url, http_options)
268
274
  end
269
275
 
276
+ # fetch verification until state is not 'created'
277
+ def poll_verification(verification_id, options = {})
278
+ http_options = standard_http_options(options)
279
+ timeout = options[:timeout] || 60 # default poll for 60 seconds
280
+ sleep_time = 5
281
+ response = nil
282
+
283
+ while timeout > 0
284
+ response = get_verification(verification_id)
285
+ break if response['state'] != Verification::STATE_CREATED
286
+ sleep sleep_time
287
+ timeout -= sleep_time
288
+ end
289
+
290
+ response
291
+ end
292
+
270
293
  # Update Verification
271
- # uses: options[:address]
294
+ # options: :address
272
295
  def update_verification(verification_id, device_id, options = {})
273
296
  require_api_key
274
297
  require_param(verification_id, "verification id")
@@ -318,7 +341,6 @@ module Touchpass
318
341
  end
319
342
 
320
343
  # Reject a verification
321
- # needs: :id
322
344
  def reject_verification(verification_id, device_id, options = {})
323
345
  require_api_key
324
346
  require_param(verification_id, "verification id")
@@ -372,9 +394,13 @@ module Touchpass
372
394
  msg = ""
373
395
  if response['error']
374
396
  msg = response['error']
375
- elsif response['errors'].kind_of(Array)
376
- # TODO
377
- msg = response['errors'].inspect
397
+ elsif response['errors'].kind_of?(Array)
398
+ list = []
399
+ response['errors'].each do |error|
400
+ err = error['field'] && error['field'] != 'base' ? error['field'] + " " + error['message'] : error['message']
401
+ list.push(err) if err
402
+ end
403
+ msg = list.join(", ")
378
404
  end
379
405
  msg
380
406
  end
@@ -407,7 +433,8 @@ module Touchpass
407
433
  raise "#{name} required" unless value && value.to_s.length > 0
408
434
  end
409
435
 
410
- # Submit the request to the server and process the response (for errors)
436
+ # Submit the request to the server and process the response (for errors).
437
+ # raises an exception if errors are received in the response.
411
438
  def submit_request(http_verb, request, options)
412
439
 
413
440
  request = request + "." + REQUEST_FORMAT
@@ -436,7 +463,9 @@ module Touchpass
436
463
  puts "DEBUG: "
437
464
  end
438
465
 
439
- response.to_hash
466
+ response = response.to_hash
467
+ raise error_message(response) if errors?(response)
468
+ response
440
469
  end
441
470
 
442
471
  end # class Touchpass::Client
@@ -1,9 +1,12 @@
1
1
  module Touchpass
2
2
  class Verification
3
3
 
4
+ STATE_CREATED = 'created'
5
+
4
6
  attr_reader :crypted_salts, :crypted_tokens, :crypted_messages
5
7
  attr_reader :claimed_token
6
8
  attr_reader :location_verification, :claimed_prp, :resolution
9
+ attr_accessor :attributes
7
10
 
8
11
  def initialize(vp_devices, options = {})
9
12
 
@@ -13,6 +16,7 @@ module Touchpass
13
16
  @claimed_token = hashed_token
14
17
  @vp_devices = vp_devices
15
18
  @crypted_messages = []
19
+ @attributes = {}
16
20
 
17
21
  # Encrypt message using each verifying party's (to_party) device public keys
18
22
  add_message(options[:message]) if !options[:message].nil?
@@ -85,7 +89,23 @@ module Touchpass
85
89
 
86
90
  params
87
91
  end
88
-
92
+
93
+ def [](key)
94
+ @attributes.kind_of?(Hash) ? @attributes[key] : nil
95
+ end
96
+
97
+ def to_h
98
+ @attributes
99
+ end
100
+
101
+ def id
102
+ self['id']
103
+ end
104
+
105
+ def state
106
+ self['state']
107
+ end
108
+
89
109
  private
90
110
 
91
111
  def param_hash(values)
@@ -1,3 +1,3 @@
1
1
  module Touchpass
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -56,8 +56,10 @@ describe "Touchpass Client" do
56
56
  username.length.should be >= 15
57
57
  email = "#{username}@geodica.com"
58
58
  password = "password"
59
- new_party = tpclient.register_party(username, password, email)
60
- expect_response_error(new_party, :username, "is too long (maximum is 15 characters)")
59
+
60
+ lambda {
61
+ new_party = tpclient.register_party(username, password, email)
62
+ }.should raise_exception(/username is too long/)
61
63
  end
62
64
 
63
65
  it "should not allow a party to register with an empty email address" do
@@ -184,8 +186,8 @@ describe "Touchpass Client" do
184
186
  end
185
187
 
186
188
  it "should allow for removal of a device by id" do
187
- udid = random_hash # a random string
188
- messaging_value = random_hash # random string
189
+ udid = random_hash # a random string
190
+ messaging_value = random_hash # random string
189
191
 
190
192
  new_device = tpclient.register_device(@new_party['username'], udid,
191
193
  "#{@username}'s Device",
@@ -200,8 +202,9 @@ describe "Touchpass Client" do
200
202
  retrieved_devices['devices'].should_not be nil
201
203
  retrieved_devices['devices'].size.should be 0
202
204
 
203
- retrieved_device = tpclient.get_device(@username, new_device['id'])
204
- expect_response_error(retrieved_device)
205
+ lambda {
206
+ retrieved_device = tpclient.get_device(@username, new_device['id'])
207
+ }.should raise_exception(/Device cannot be found/)
205
208
  end
206
209
 
207
210
  end
@@ -307,11 +310,13 @@ describe "Touchpass Client" do
307
310
 
308
311
  # We should *not* be able to canel or reject this verification
309
312
  # since it's already been validated.
310
- response = @vp_client.cancel_verification(verification['id'], @new_device['id'])
311
- expect_response_error(response, :base, "Verification has already been responded")
313
+ lambda {
314
+ response = @vp_client.cancel_verification(verification['id'], @new_device['id'])
315
+ }.should raise_exception(/has already been responded/)
312
316
 
313
- response = @vp_client.reject_verification(verification['id'], @new_device['id'])
314
- expect_response_error(response, :base, "Verification has already been responded")
317
+ lambda {
318
+ response = @vp_client.reject_verification(verification['id'], @new_device['id'])
319
+ }.should raise_exception(/has already been responded/)
315
320
  end
316
321
  end
317
322
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: touchpass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: