tokenex 0.5.1 → 0.5.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: 4672a0ace60e8132c8e064ace265829936ea45c3
4
- data.tar.gz: bf2bddca1e836838bb39476b8bc7f0315ba61e30
3
+ metadata.gz: cd3be0f56b6f26df13c7c3df0468a3b2d5b520f9
4
+ data.tar.gz: c94fe90b7592994bf323fdee7c0f4f40fe32db51
5
5
  SHA512:
6
- metadata.gz: 317a60967808c3c295137e4a5feee09f284989d1e9db0151fd6e266b89e0043d672685696c412f6102d252623a0356fec479997094bdeaf6b89291a93a555959
7
- data.tar.gz: 2634b73416da8f12cb776c49091b1b9a3a65c9bb78b8ff14e67f9bfcd37517f2849571e03cd3d231c45972d891363a96b73fa46b3b6e4973f0c98263cb56f27d
6
+ metadata.gz: 24590d36757a638d6b2641a223d1af0c02ee1e3e2196bf43ef6687f8d7569bc9566b1fe1fafe1fd76d39236b082dd82a390589014950d196db8f5da8820a3bf8
7
+ data.tar.gz: d8f411289d0d5aef513e7265d0c5f2bacd352e7dcc5a24d70b6aacdbc7540c7d49653743694a7bf0873841634484e56f69703f3ef0b56452eb79b4ca4acdaa3f
data/README.md CHANGED
@@ -58,8 +58,26 @@ token = tokenex.token_from_ccnum(4242424242424242)
58
58
  tokenex.delete_token(token)
59
59
  ```
60
60
 
61
+
62
+ #### Errors and References
63
+
64
+ Each action call will return a reference ID that can be used to lookup a call in
65
+ the TokenEx dashboard. Unsuccessful calls will also return an error describing
66
+ the problem. Each can be accessed via:
67
+ ```ruby
68
+ tokenex.error
69
+ tokenex.reference_number
70
+ ```
71
+
61
72
  ## Development
62
73
 
74
+ Before proceeding, make sure the following environment variables are set (they are required for running the specs):
75
+ ```
76
+ TOKENEX_API_BASE_URL=https://test-api.tokenex.com/TokenServices.svc/REST/
77
+ TOKENEX_ID=<YOUR TOKENEX_ID>
78
+ TOKENEX_API_KEY=<YOUR TOKENEX_API_KEY>
79
+ ```
80
+
63
81
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
82
 
65
83
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -1,4 +1,6 @@
1
1
  require "tokenex/version"
2
+ require "tokenex/token_action"
3
+ require "tokenex/token_params"
2
4
  require "tokenex/token_scheme"
3
5
  require "tokenex/environment"
4
6
 
@@ -4,6 +4,7 @@ require "uri"
4
4
 
5
5
  module Tokenex
6
6
  class Environment
7
+ attr_reader :error, :reference_number
7
8
 
8
9
  def initialize(api_base_url, tokenex_id, api_key, options={})
9
10
  @api_base_url = api_base_url
@@ -19,65 +20,60 @@ module Tokenex
19
20
  end
20
21
 
21
22
  def tokenize(data, token_scheme = TOKEN_SCHEME[:GUID])
22
- action = "Tokenize"
23
23
  request_parameters = {
24
- "Data" => data,
25
- "TokenScheme" => token_scheme
24
+ REQUEST_PARAMS[:Data] => data,
25
+ REQUEST_PARAMS[:TokenScheme] => token_scheme
26
26
  }
27
27
 
28
- response = send_request(action, request_parameters)
29
- throw :tokenex_cannot_tokenize_data unless is_valid_response(response)
30
-
31
- response['Token']
28
+ catch (:tokenex_invalid_response) do
29
+ return send_request(TOKEN_ACTION[:Tokenize], request_parameters)
30
+ end
31
+ throw :tokenex_cannot_tokenize_data
32
32
  end
33
33
 
34
34
  def tokenize_from_encrypted_value(encrypted_data, token_scheme)
35
- action = "TokenizeFromEncryptedValue"
36
35
  request_parameters = {
37
- "EcryptedData" => encrypted_data,
38
- "TokenScheme" => token_scheme
36
+ REQUEST_PARAMS[:EncryptedData] => encrypted_data,
37
+ REQUEST_PARAMS[:TokenScheme] => token_scheme
39
38
  }
40
39
 
41
- response = send_request(action, request_parameters)
42
- throw :tokenex_cannot_tokenize_from_encrypted_value unless is_valid_response(response)
43
-
44
- response['Token']
40
+ catch (:tokenex_invalid_response) do
41
+ return send_request(TOKEN_ACTION[:TokenizeFromEncryptedValue], request_parameters)
42
+ end
43
+ throw :tokenex_cannot_tokenize_from_encrypted_value
45
44
  end
46
45
 
47
46
  def detokenize(token)
48
- action = "Detokenize"
49
47
  request_parameters = {
50
- "Token" => token
48
+ REQUEST_PARAMS[:Token] => token
51
49
  }
52
50
 
53
- response = send_request(action, request_parameters)
54
- throw :tokenex_invalid_token unless is_valid_response(response)
55
-
56
- response['Value']
51
+ catch (:tokenex_invalid_response) do
52
+ return send_request(TOKEN_ACTION[:Detokenize], request_parameters)
53
+ end
54
+ throw :tokenex_invalid_token
57
55
  end
58
56
 
59
57
  def validate_token(token)
60
- action = "ValidateToken"
61
58
  request_parameters = {
62
- "Token" => token
59
+ REQUEST_PARAMS[:Token] => token
63
60
  }
64
61
 
65
- response = send_request(action, request_parameters)
66
- throw :tokenex_invalid_token unless is_valid_response(response)
67
-
68
- response['Valid']
62
+ catch (:tokenex_invalid_response) do
63
+ return send_request(TOKEN_ACTION[:ValidateToken], request_parameters)
64
+ end
65
+ throw :tokenex_invalid_token
69
66
  end
70
67
 
71
68
  def delete_token(token)
72
- action = "DeleteToken"
73
69
  request_parameters = {
74
- "Token" => token
70
+ REQUEST_PARAMS[:Token] => token
75
71
  }
76
72
 
77
- response = send_request(action, request_parameters)
78
- throw :tokenex_invalid_token unless is_valid_response(response)
79
-
80
- response['Success']
73
+ catch (:tokenex_invalid_response) do
74
+ return send_request(TOKEN_ACTION[:DeleteToken], request_parameters)
75
+ end
76
+ throw :tokenex_invalid_token
81
77
  end
82
78
 
83
79
  private
@@ -88,31 +84,32 @@ module Tokenex
88
84
  }
89
85
  end
90
86
 
91
- def build_request_array(data)
92
- request_array = {
93
- "APIKey" => @api_key,
94
- "TokenExID" => @tokenex_id
87
+ def request(data)
88
+ {
89
+ REQUEST_PARAMS[:APIKey] => @api_key,
90
+ REQUEST_PARAMS[:TokenExID] => @tokenex_id
95
91
  }.merge(data)
96
-
97
- request_array
98
92
  end
99
93
 
100
94
  def send_request(action, data)
101
- request_body = build_request_array(data).to_json
102
-
103
- uri = URI.parse("#{@api_base_url}#{action}")
95
+ uri = URI.parse("#{@api_base_url}#{action[:Name]}")
104
96
  http = Net::HTTP.new(uri.host, uri.port)
105
97
  http.use_ssl = true
106
98
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
107
99
 
108
100
  request = Net::HTTP::Post.new(uri, initheader = headers)
109
- request.body = request_body
101
+ request.body = request(data).to_json
110
102
  response = http.request(request)
111
- JSON.parse(response.body)
103
+ return_data = JSON.parse(response.body)
104
+ throw :tokenex_invalid_response unless is_valid_response(return_data)
105
+
106
+ return_data[action[:Key]]
112
107
  end
113
108
 
114
109
  def is_valid_response(response)
115
- !response['Success'].nil? && response['Success'] == true
110
+ @error = response[RESPONSE_PARAMS[:Error]].empty? ? nil : response[RESPONSE_PARAMS[:Error]]
111
+ @reference_number = response[RESPONSE_PARAMS[:ReferenceNumber]].empty? ? nil : response[RESPONSE_PARAMS[:ReferenceNumber]]
112
+ !response[RESPONSE_PARAMS[:Success]].nil? && response[RESPONSE_PARAMS[:Success]] == true
116
113
  end
117
114
 
118
115
  end
@@ -0,0 +1,24 @@
1
+ module Tokenex
2
+ TOKEN_ACTION = {
3
+ Tokenize: {
4
+ Name: 'Tokenize',
5
+ Key: 'Token'
6
+ },
7
+ TokenizeFromEncryptedValue: {
8
+ Name: 'TokenizeFromEncryptedValue',
9
+ Key: 'Token'
10
+ },
11
+ ValidateToken: {
12
+ Name: 'ValidateToken',
13
+ Key: 'Valid'
14
+ },
15
+ Detokenize: {
16
+ Name: 'Detokenize',
17
+ Key: 'Value'
18
+ },
19
+ DeleteToken: {
20
+ Name: 'DeleteToken',
21
+ Key: 'Success'
22
+ }
23
+ }
24
+ end
@@ -0,0 +1,19 @@
1
+ module Tokenex
2
+ REQUEST_PARAMS = {
3
+ APIKey: 'APIKey',
4
+ Data: 'Data',
5
+ EncryptedData: 'EcryptedData',
6
+ Token: 'Token',
7
+ TokenExID: 'TokenExID',
8
+ TokenScheme: 'TokenScheme',
9
+ }
10
+
11
+ RESPONSE_PARAMS = {
12
+ Token: 'Token',
13
+ Success: 'Success',
14
+ ReferenceNumber: 'ReferenceNumber',
15
+ Error: 'Error',
16
+ Valid: 'Valid',
17
+ Value: 'Value'
18
+ }
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Tokenex
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokenex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Clifford
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-30 00:00:00.000000000 Z
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,6 +83,8 @@ files:
83
83
  - bin/setup
84
84
  - lib/tokenex.rb
85
85
  - lib/tokenex/environment.rb
86
+ - lib/tokenex/token_action.rb
87
+ - lib/tokenex/token_params.rb
86
88
  - lib/tokenex/token_scheme.rb
87
89
  - lib/tokenex/version.rb
88
90
  - tokenex.gemspec
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
109
  version: '0'
108
110
  requirements: []
109
111
  rubyforge_project:
110
- rubygems_version: 2.5.1
112
+ rubygems_version: 2.2.2
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Provides a Ruby wrapper for the TokenEx API