miiCardConsumers 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/miiCardConsumers.rb +102 -99
- data/test/test_miiCardConsumers.rb +4 -2
- metadata +3 -3
data/lib/miiCardConsumers.rb
CHANGED
@@ -4,7 +4,7 @@ require "json"
|
|
4
4
|
class MiiCardServiceUrls
|
5
5
|
OAUTH_ENDPOINT = "https://sts.miicard.com/auth/OAuth.ashx"
|
6
6
|
STS_SITE = "https://sts.miicard.com"
|
7
|
-
|
7
|
+
CLAIMS_SVC = "https://sts.miicard.com/api/v1/Claims.svc/json"
|
8
8
|
|
9
9
|
def self.get_method_url(method_name)
|
10
10
|
return MiiCardServiceUrls::CLAIMS_SVC + "/" + method_name
|
@@ -31,16 +31,16 @@ module MiiApiErrorCode
|
|
31
31
|
ACCESS_REVOKED = 100
|
32
32
|
# The user's miiCard subscription has elapsed. Only users with a current
|
33
33
|
# subscription can share their data with other applications and websites.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
USER_SUBSCRIPTION_LAPSED = 200
|
35
|
+
# Signifies that your account has not been enabled for transactional support.
|
36
|
+
TRANSACTIONAL_SUPPORT_DISABLED = 1000
|
37
|
+
# Signifies that your account's support status is development-only. This is the
|
38
|
+
# case when your application hasn't yet been made live in the miiCard system, for example
|
39
|
+
# while we process your billing details and perform final checks.
|
40
|
+
DEVELOPMENT_TRANSACTIONAL_SUPPORT_ONLY = 1010
|
41
|
+
# Signifies that the snapshot ID supplied to a snapshot-based API method was either invalid
|
42
|
+
# or corresponded to a user for which authorisation tokens didn't match.
|
43
|
+
INVALID_SNAPSHOT_ID = 1020
|
44
44
|
# Signifies that your application has been suspended and no API access can take place
|
45
45
|
# until miiCard releases the suspension on your application.
|
46
46
|
BLACKLISTED = 2000
|
@@ -55,7 +55,7 @@ module MiiApiErrorCode
|
|
55
55
|
# A general exception occurred during processing - details may be available
|
56
56
|
# in the error_message property of the response object depending upon the
|
57
57
|
# nature of the exception.
|
58
|
-
|
58
|
+
EXCEPTION = 10000
|
59
59
|
end
|
60
60
|
|
61
61
|
# Describes the overall status of an API call.
|
@@ -199,51 +199,53 @@ class MiiUserProfile
|
|
199
199
|
attr_accessor :previous_first_name, :previous_middle_name, :previous_last_name
|
200
200
|
attr_accessor :last_verified, :profile_url, :profile_short_url, :card_image_url, :email_addresses, :identities, :postal_addresses
|
201
201
|
attr_accessor :phone_numbers, :web_properties, :identity_assured, :has_public_profile
|
202
|
-
attr_accessor :public_profile
|
202
|
+
attr_accessor :public_profile, :date_of_birth
|
203
203
|
|
204
204
|
def initialize(
|
205
205
|
username,
|
206
206
|
salutation,
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
207
|
+
first_name,
|
208
|
+
middle_name,
|
209
|
+
last_name,
|
210
|
+
previous_first_name,
|
211
|
+
previous_middle_name,
|
212
|
+
previous_last_name,
|
213
|
+
last_verified,
|
214
|
+
profile_url,
|
215
|
+
profile_short_url,
|
216
|
+
card_image_url,
|
217
|
+
email_addresses,
|
218
|
+
identities,
|
219
|
+
phone_numbers,
|
220
|
+
postal_addresses,
|
221
|
+
web_properties,
|
222
|
+
identity_assured,
|
223
|
+
has_public_profile,
|
224
|
+
public_profile,
|
225
|
+
date_of_birth
|
225
226
|
)
|
226
227
|
|
227
228
|
@username= username
|
228
229
|
@salutation = salutation
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
230
|
+
@first_name = first_name
|
231
|
+
@middle_name = middle_name
|
232
|
+
@last_name = last_name
|
233
|
+
@previous_first_name = previous_first_name
|
234
|
+
@previous_middle_name = previous_middle_name
|
235
|
+
@previous_last_name = previous_last_name
|
236
|
+
@last_verified = last_verified
|
237
|
+
@profile_url = profile_url
|
238
|
+
@profile_short_url = profile_short_url
|
239
|
+
@card_image_url = card_image_url
|
240
|
+
@email_addresses = email_addresses
|
241
|
+
@identities = identities
|
242
|
+
@phone_numbers = phone_numbers
|
243
|
+
@postal_addresses = postal_addresses
|
244
|
+
@web_properties = web_properties
|
245
|
+
@identity_assured = identity_assured
|
246
|
+
@has_public_profile = has_public_profile
|
247
|
+
@public_profile = public_profile
|
248
|
+
@date_of_birth = date_of_birth
|
247
249
|
end
|
248
250
|
|
249
251
|
def self.from_hash(hash)
|
@@ -303,7 +305,8 @@ class MiiUserProfile
|
|
303
305
|
web_properties_parsed,
|
304
306
|
hash['IdentityAssured'],
|
305
307
|
hash['HasPublicProfile'],
|
306
|
-
public_profile_parsed
|
308
|
+
public_profile_parsed,
|
309
|
+
Util::parse_dot_net_json_datetime(hash['DateOfBirth'])
|
307
310
|
)
|
308
311
|
end
|
309
312
|
end
|
@@ -323,11 +326,11 @@ class MiiApiResponse
|
|
323
326
|
payload_json = hash["Data"]
|
324
327
|
|
325
328
|
if payload_json && !data_processor.nil?
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
329
|
+
if array_type_payload
|
330
|
+
payload = payload_json.map{|item| data_processor.call(item)}
|
331
|
+
else
|
332
|
+
payload = data_processor.call(payload_json)
|
333
|
+
end
|
331
334
|
elsif !(payload_json.nil?)
|
332
335
|
payload = payload_json
|
333
336
|
else
|
@@ -345,39 +348,39 @@ class MiiApiResponse
|
|
345
348
|
end
|
346
349
|
|
347
350
|
class IdentitySnapshotDetails
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
351
|
+
attr_accessor :snapshot_id, :username, :timestamp_utc, :was_test_user
|
352
|
+
|
353
|
+
def initialize(snapshot_id, username, timestamp_utc, was_test_user)
|
354
|
+
@snapshot_id = snapshot_id
|
355
|
+
@username = username
|
356
|
+
@timestamp_utc = timestamp_utc
|
357
|
+
@was_test_user = was_test_user
|
358
|
+
end
|
359
|
+
|
360
|
+
def self.from_hash(hash)
|
361
|
+
return IdentitySnapshotDetails.new(
|
362
|
+
hash["SnapshotId"],
|
363
|
+
hash["Username"],
|
364
|
+
Util::parse_dot_net_json_datetime(hash["TimestampUtc"]),
|
365
|
+
hash["WasTestUser"]
|
366
|
+
)
|
367
|
+
end
|
365
368
|
end
|
366
369
|
|
367
370
|
class IdentitySnapshot
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
371
|
+
attr_accessor :details, :snapshot
|
372
|
+
|
373
|
+
def initialize(details, snapshot)
|
374
|
+
@details = details
|
375
|
+
@snapshot = snapshot
|
376
|
+
end
|
377
|
+
|
378
|
+
def self.from_hash(hash)
|
379
|
+
return IdentitySnapshot.new(
|
380
|
+
IdentitySnapshotDetails::from_hash(hash["Details"]),
|
381
|
+
MiiUserProfile::from_hash(hash["Snapshot"])
|
382
|
+
)
|
383
|
+
end
|
381
384
|
end
|
382
385
|
|
383
386
|
class MiiCardOAuthServiceBase
|
@@ -419,18 +422,18 @@ class MiiCardOAuthClaimsService < MiiCardOAuthServiceBase
|
|
419
422
|
|
420
423
|
return make_request(MiiCardServiceUrls.get_method_url('AssuranceImage'), params, nil, false)
|
421
424
|
end
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
425
|
+
|
426
|
+
def get_identity_snapshot_details(snapshot_id = nil)
|
427
|
+
params = Hash["snapshotId", snapshot_id]
|
428
|
+
|
429
|
+
return make_request(MiiCardServiceUrls.get_method_url('GetIdentitySnapshotDetails'), params, IdentitySnapshotDetails.method(:from_hash), true, true)
|
430
|
+
end
|
431
|
+
|
432
|
+
def get_identity_snapshot(snapshot_id)
|
433
|
+
params = Hash["snapshotId", snapshot_id]
|
434
|
+
|
435
|
+
return make_request(MiiCardServiceUrls.get_method_url('GetIdentitySnapshot'), params, IdentitySnapshot.method(:from_hash), true)
|
436
|
+
end
|
434
437
|
|
435
438
|
private
|
436
439
|
def make_request(url, post_data, payload_processor, wrapped_response, array_type_payload = false)
|
@@ -440,7 +443,7 @@ class MiiCardOAuthClaimsService < MiiCardOAuthServiceBase
|
|
440
443
|
response = access_token.post(url, post_data.to_json(), { 'Content-Type' => 'application/json' })
|
441
444
|
|
442
445
|
if wrapped_response
|
443
|
-
|
446
|
+
return MiiApiResponse::from_hash(JSON.parse(response.body), payload_processor, array_type_payload)
|
444
447
|
elsif !payload_processor.nil?
|
445
448
|
return payload_processor.call(response.body)
|
446
449
|
else
|
@@ -453,6 +456,6 @@ class Util
|
|
453
456
|
# Modified from http://stackoverflow.com/questions/1272195/c-sharp-serialized-json-date-to-ruby
|
454
457
|
def self.parse_dot_net_json_datetime(datestring)
|
455
458
|
seconds_since_epoch = (datestring.scan(/[0-9]+/)[0].to_i) / 1000.0
|
456
|
-
return
|
459
|
+
return DateTime.strptime(seconds_since_epoch.to_s, '%s')
|
457
460
|
end
|
458
461
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'miiCardConsumers'
|
3
3
|
require 'test/unit'
|
4
|
+
require 'date'
|
4
5
|
|
5
6
|
class TestSomething < Test::Unit::TestCase
|
6
7
|
def setup
|
7
|
-
@jsonBody = '{"CardImageUrl":"https:\/\/my.miicard.com\/img\/test.png","EmailAddresses":[{"Verified":true,"Address":"test@example.com","DisplayName":"testEmail","IsPrimary":true},{"Verified":false,"Address":"test2@example.com","DisplayName":"test2Email","IsPrimary":false}],"FirstName":"Test","HasPublicProfile":true,"Identities":null,"IdentityAssured":true,"LastName":"User","LastVerified":"\/Date(
|
8
|
+
@jsonBody = '{"CardImageUrl":"https:\/\/my.miicard.com\/img\/test.png","DateOfBirth":"\/Date(435046400000)\/","EmailAddresses":[{"Verified":true,"Address":"test@example.com","DisplayName":"testEmail","IsPrimary":true},{"Verified":false,"Address":"test2@example.com","DisplayName":"test2Email","IsPrimary":false}],"FirstName":"Test","HasPublicProfile":true,"Identities":null,"IdentityAssured":true,"LastName":"User","LastVerified":"\/Date(1345812103000)\/","MiddleName":"Middle","PhoneNumbers":[{"Verified":true,"CountryCode":"44","DisplayName":"Default","IsMobile":true,"IsPrimary":true,"NationalNumber":"7800123456"},{"Verified":false,"CountryCode":"44","DisplayName":"Default","IsMobile":false,"IsPrimary":false,"NationalNumber":"7800123457"}],"PostalAddresses":[{"House":"Addr1 House1","Line1":"Addr1 Line1","Line2":"Addr1 Line2","City":"Addr1 City","Region":"Addr1 Region","Code":"Addr1 Code","Country":"Addr1 Country","IsPrimary":true,"Verified":true},{"House":"Addr2 House1","Line1":"Addr2 Line1","Line2":"Addr2 Line2","City":"Addr2 City","Region":"Addr2 Region","Code":"Addr2 Code","Country":"Addr2 Country","IsPrimary":false,"Verified":false}],"PreviousFirstName":"PrevFirst","PreviousLastName":"PrevLast","PreviousMiddleName":"PrevMiddle","ProfileShortUrl":"http:\/\/miicard.me\/123456","ProfileUrl":"https:\/\/my.miicard.com\/card\/test","PublicProfile":{"CardImageUrl":"https:\/\/my.miicard.com\/img\/test.png","DateOfBirth":"\/Date(435046400000)\/","FirstName":"Test","HasPublicProfile":true,"IdentityAssured":true,"LastName":"User","LastVerified":"\/Date(1345812103000)\/","MiddleName":"Middle","PreviousFirstName":"PrevFirst","PreviousLastName":"PrevLast","PreviousMiddleName":"PrevMiddle","ProfileShortUrl":"http:\/\/miicard.me\/123456","ProfileUrl":"https:\/\/my.miicard.com\/card\/test","PublicProfile":null,"Salutation":"Ms","Username":"testUser"},"Salutation":"Ms","Username":"testUser","WebProperties":[{"Verified":true,"DisplayName":"example.com","Identifier":"example.com","Type":0},{"Verified":false,"DisplayName":"2.example.com","Identifier":"http:\/\/www.2.example.com","Type":1}]}'
|
8
9
|
@jsonResponseBody = '{"ErrorCode":0,"Status":0,"ErrorMessage":"A test error message","Data":true}'
|
9
10
|
end
|
10
11
|
|
@@ -99,7 +100,8 @@ class TestSomething < Test::Unit::TestCase
|
|
99
100
|
assert_equal("PrevLast", obj.previous_last_name)
|
100
101
|
|
101
102
|
assert_equal(true, obj.identity_assured)
|
102
|
-
|
103
|
+
assert_equal(DateTime.strptime('1345812103','%s'), obj.last_verified)
|
104
|
+
assert_equal(DateTime.strptime('435046400', '%s'), obj.date_of_birth)
|
103
105
|
|
104
106
|
assert_equal(true, obj.has_public_profile)
|
105
107
|
assert_equal("http://miicard.me/123456", obj.profile_short_url)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miiCardConsumers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
description: A simple wrapper library around the miiCard API that makes calling into
|
47
47
|
it easier - just new up a MiiApiOAuthClaimsService with your consumer key, secret,
|
48
48
|
access token and secret and start calling methods.
|
49
|
-
email:
|
49
|
+
email: info@miicard.com
|
50
50
|
executables: []
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|