miiCardConsumers 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/miiCardConsumers.rb +97 -16
  2. metadata +17 -7
@@ -1,6 +1,16 @@
1
1
  require "oauth"
2
2
  require "json"
3
3
 
4
+ class MiiCardServiceUrls
5
+ OAUTH_ENDPOINT = "https://sts.miicard.com/auth/OAuth.ashx"
6
+ STS_SITE = "https://sts.miicard.com"
7
+ CLAIMS_SVC = "https://sts.miicard.com/api/v1/Claims.svc/json"
8
+
9
+ def self.get_method_url(method_name)
10
+ return MiiCardServiceUrls::CLAIMS_SVC + "/" + method_name
11
+ end
12
+ end
13
+
4
14
  # Describes the overall status of an API call.
5
15
  module MiiApiCallStatus
6
16
  # The API call succeeded - the associated result information can be found
@@ -22,6 +32,26 @@ module MiiApiErrorCode
22
32
  # The user's miiCard subscription has elapsed. Only users with a current
23
33
  # subscription can share their data with other applications and websites.
24
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
+ # Signifies that your application has been suspended and no API access can take place
45
+ # until miiCard releases the suspension on your application.
46
+ BLACKLISTED = 2000
47
+ # Signifies that your application has been disabled, either by your request or by miiCard.
48
+ # miiCard members will be unable to go through the OAuth process for your application,
49
+ # though you will still be able to access the API.
50
+ PRODUCT_DISABLED = 2010
51
+ # Signifies that your application has been deleted. miiCard members will be unable to go
52
+ # through the OAuth process for your application, nor will you be able to access identity
53
+ # details through the API.
54
+ PRODUCT_DELETED = 2020
25
55
  # A general exception occurred during processing - details may be available
26
56
  # in the error_message property of the response object depending upon the
27
57
  # nature of the exception.
@@ -262,7 +292,7 @@ class MiiUserProfile
262
292
  hash['PreviousFirstName'],
263
293
  hash['PreviousMiddleName'],
264
294
  hash['PreviousLastName'],
265
- hash['LastVerified'],
295
+ Util::parse_dot_net_json_datetime(hash['LastVerified']),
266
296
  hash['ProfileUrl'],
267
297
  hash['ProfileShortUrl'],
268
298
  hash['CardImageUrl'],
@@ -279,20 +309,25 @@ class MiiUserProfile
279
309
  end
280
310
 
281
311
  class MiiApiResponse
282
- attr_accessor :status, :error_code, :error_message, :data
312
+ attr_accessor :status, :error_code, :error_message, :is_test_user, :data
283
313
 
284
- def initialize(status, error_code, error_message, data)
314
+ def initialize(status, error_code, error_message, is_test_user, data)
285
315
  @status = status
286
316
  @error_code = error_code
287
317
  @error_message = error_message
318
+ @is_test_user = is_test_user
288
319
  @data = data
289
320
  end
290
321
 
291
- def self.from_hash(hash, data_processor)
322
+ def self.from_hash(hash, data_processor, array_type_payload = false)
292
323
  payload_json = hash["Data"]
293
324
 
294
325
  if payload_json && !data_processor.nil?
295
- payload = data_processor.call(payload_json)
326
+ if array_type_payload
327
+ payload = payload_json.map{|item| data_processor.call(item)}
328
+ else
329
+ payload = data_processor.call(payload_json)
330
+ end
296
331
  elsif !(payload_json.nil?)
297
332
  payload = payload_json
298
333
  else
@@ -303,11 +338,48 @@ class MiiApiResponse
303
338
  hash["Status"],
304
339
  hash["ErrorCode"],
305
340
  hash["ErrorMessage"],
341
+ hash["IsTestUser"],
306
342
  payload
307
343
  )
308
344
  end
309
345
  end
310
346
 
347
+ class IdentitySnapshotDetails
348
+ attr_accessor :snapshot_id, :username, :timestamp_utc, :was_test_user
349
+
350
+ def initialize(snapshot_id, username, timestamp_utc, was_test_user)
351
+ @snapshot_id = snapshot_id
352
+ @username = username
353
+ @timestamp_utc = timestamp_utc
354
+ @was_test_user = was_test_user
355
+ end
356
+
357
+ def self.from_hash(hash)
358
+ return IdentitySnapshotDetails.new(
359
+ hash["SnapshotId"],
360
+ hash["Username"],
361
+ Util::parse_dot_net_json_datetime(hash["TimestampUtc"]),
362
+ hash["WasTestUser"]
363
+ )
364
+ end
365
+ end
366
+
367
+ class IdentitySnapshot
368
+ attr_accessor :details, :snapshot
369
+
370
+ def initialize(details, snapshot)
371
+ @details = details
372
+ @snapshot = snapshot
373
+ end
374
+
375
+ def self.from_hash(hash)
376
+ return IdentitySnapshot.new(
377
+ IdentitySnapshotDetails::from_hash(hash["Details"]),
378
+ MiiUserProfile::from_hash(hash["Snapshot"])
379
+ )
380
+ end
381
+ end
382
+
311
383
  class MiiCardOAuthServiceBase
312
384
  attr_accessor :consumer_key, :consumer_secret, :access_token, :access_token_secret
313
385
 
@@ -347,16 +419,28 @@ class MiiCardOAuthClaimsService < MiiCardOAuthServiceBase
347
419
 
348
420
  return make_request(MiiCardServiceUrls.get_method_url('AssuranceImage'), params, nil, false)
349
421
  end
422
+
423
+ def get_identity_snapshot_details(snapshot_id = nil)
424
+ params = Hash["snapshotId", snapshot_id]
425
+
426
+ return make_request(MiiCardServiceUrls.get_method_url('GetIdentitySnapshotDetails'), params, IdentitySnapshotDetails.method(:from_hash), true, true)
427
+ end
428
+
429
+ def get_identity_snapshot(snapshot_id)
430
+ params = Hash["snapshotId", snapshot_id]
431
+
432
+ return make_request(MiiCardServiceUrls.get_method_url('GetIdentitySnapshot'), params, IdentitySnapshot.method(:from_hash), true)
433
+ end
350
434
 
351
435
  private
352
- def make_request(url, post_data, payload_processor, wrapped_response)
436
+ def make_request(url, post_data, payload_processor, wrapped_response, array_type_payload = false)
353
437
  consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {:site => MiiCardServiceUrls::STS_SITE, :request_token_path => MiiCardServiceUrls::OAUTH_ENDPOINT, :access_token_path => MiiCardServiceUrls::OAUTH_ENDPOINT, :authorize_path => MiiCardServiceUrls::OAUTH_ENDPOINT })
354
438
  access_token = OAuth::AccessToken.new(consumer, @access_token, @access_token_secret)
355
439
 
356
440
  response = access_token.post(url, post_data.to_json(), { 'Content-Type' => 'application/json' })
357
441
 
358
442
  if wrapped_response
359
- return MiiApiResponse::from_hash(JSON.parse(response.body), payload_processor)
443
+ return MiiApiResponse::from_hash(JSON.parse(response.body), payload_processor, array_type_payload)
360
444
  elsif !payload_processor.nil?
361
445
  return payload_processor.call(response.body)
362
446
  else
@@ -365,13 +449,10 @@ class MiiCardOAuthClaimsService < MiiCardOAuthServiceBase
365
449
  end
366
450
  end
367
451
 
368
- class MiiCardServiceUrls
369
- OAUTH_ENDPOINT = "https://sts.miicard.com/auth/OAuth.ashx"
370
- STS_SITE = "https://sts.miicard.com"
371
- CLAIMS_SVC = "https://sts.miicard.com/api/v1/Claims.svc/json"
372
-
373
- def self.get_method_url(method_name)
374
- return MiiCardServiceUrls::CLAIMS_SVC + "/" + method_name
452
+ class Util
453
+ # Modified from http://stackoverflow.com/questions/1272195/c-sharp-serialized-json-date-to-ruby
454
+ def self.parse_dot_net_json_datetime(datestring)
455
+ seconds_since_epoch = (datestring.scan(/[0-9]+/)[0].to_i) / 1000.0
456
+ return Time.at(seconds_since_epoch)
375
457
  end
376
- end
377
-
458
+ end
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: 1.0.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-14 00:00:00.000000000Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &27018276 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *27018276
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: json
27
- requirement: &27018012 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *27018012
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  description: A simple wrapper library around the miiCard API that makes calling into
37
47
  it easier - just new up a MiiApiOAuthClaimsService with your consumer key, secret,
38
48
  access token and secret and start calling methods.
@@ -63,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
73
  version: '0'
64
74
  requirements: []
65
75
  rubyforge_project:
66
- rubygems_version: 1.7.2
76
+ rubygems_version: 1.8.24
67
77
  signing_key:
68
78
  specification_version: 3
69
79
  summary: Wrapper library around the miiCard API.