trustev 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +335 -0
- data/Rakefile +2 -0
- data/lib/trustev.rb +112 -0
- data/lib/trustev/authenticate.rb +47 -0
- data/lib/trustev/digital_signature.rb +40 -0
- data/lib/trustev/error.rb +18 -0
- data/lib/trustev/profile.rb +34 -0
- data/lib/trustev/social.rb +57 -0
- data/lib/trustev/transaction.rb +200 -0
- data/lib/trustev/version.rb +3 -0
- data/test/authenticate_test.rb +12 -0
- data/test/digital_signature_test.rb +32 -0
- data/test/error_test.rb +18 -0
- data/test/profile_test.rb +45 -0
- data/test/social_test.rb +56 -0
- data/test/test_helper.rb +80 -0
- data/test/transaction_test.rb +37 -0
- data/trustev.gemspec +28 -0
- metadata +157 -0
data/test/error_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
describe Trustev::Error do
|
4
|
+
|
5
|
+
describe 'when an error is created' do
|
6
|
+
it 'must convert to a string properly' do
|
7
|
+
error = Trustev::Error.new('Test Message', 404, 'Invalid API Response')
|
8
|
+
error.to_s.must_equal '(Status 404) Test Message Invalid API Response'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'an error without a status code' do
|
13
|
+
it 'should just have messages when converted to a string' do
|
14
|
+
error = Trustev::Error.new('Test Message', nil, 'Invalid API Response')
|
15
|
+
error.to_s.must_equal 'Test Message Invalid API Response'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe Trustev::Profile do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@transaction_number = SecureRandom.hex
|
8
|
+
transaction = Trustev::Transaction.new(@transaction_number)
|
9
|
+
transaction.create(build_transaction)
|
10
|
+
@profile = Trustev::Profile.new(@transaction_number )
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'when retrieving all scores' do
|
14
|
+
it 'must return a json object containing score data' do
|
15
|
+
score_data = @profile.retrieve_scores
|
16
|
+
score_data[:Code].must_equal 200
|
17
|
+
score_data[:Message].must_equal 'Success'
|
18
|
+
score_data[:Timestamp].must_match /\/Date\(.*\)\//
|
19
|
+
score_data[:Profile].must_be_instance_of Hash
|
20
|
+
score_data[:Profile][:Sources].must_be_instance_of Array
|
21
|
+
score_data[:Profile][:Sources][0].must_be_instance_of Hash
|
22
|
+
score_data[:Profile][:Sources][0][:Source].must_equal 7
|
23
|
+
score_data[:Profile][:Sources][0][:Scores].must_be_instance_of Array
|
24
|
+
score_data[:Profile][:Sources][0][:Scores][0][:Confidence].must_be_instance_of Fixnum
|
25
|
+
score_data[:Profile][:Sources][0][:Scores][0][:Parameter].must_be_instance_of Fixnum
|
26
|
+
score_data[:Profile][:Sources][0][:Scores][0][:Score].must_be_instance_of Float
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'when retrieving overall score' do
|
31
|
+
it 'must just return the overall score' do
|
32
|
+
@profile.get_overall_score.must_be_instance_of Float
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'when retrieving a specific score' do
|
37
|
+
it 'must return that specific score' do
|
38
|
+
@profile.retrieve_scores[:Profile][:Sources].each do | source |
|
39
|
+
if source[:Source] == 7
|
40
|
+
source[:Scores].each { | score | score[:Score].must_equal @profile.get_score(7, 0) if score[:Parameter] == 0 }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/test/social_test.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe Trustev::Social do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@social_network_id = Random.rand(0..9999999999)
|
8
|
+
Trustev::Social.delete(0, @social_network_id)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'when adding social network data' do
|
12
|
+
it 'must return a good response code' do
|
13
|
+
create_social.code.must_equal 200
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'when updating social network data' do
|
18
|
+
it 'must turn a good response code' do
|
19
|
+
create_social
|
20
|
+
Trustev::Social.update(
|
21
|
+
{
|
22
|
+
type: 0,
|
23
|
+
id: @social_network_id,
|
24
|
+
short_term_token: 'CAAGEIkkiehQrXSIK9vHOiPnZB139M',
|
25
|
+
long_term_token: 'CAAGXgR7VWu',
|
26
|
+
short_term_expiry: 1390238654000,
|
27
|
+
long_term_expiry: 1395417029000,
|
28
|
+
secret: '84bcd7da0e967139652f7ce59e4c859e'
|
29
|
+
}
|
30
|
+
).code.must_equal 200
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'when deleting social network data' do
|
35
|
+
it 'must return a good response code' do
|
36
|
+
create_social
|
37
|
+
Trustev::Social.delete(0, @social_network_id).code.must_equal 200
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def create_social
|
44
|
+
Trustev::Social.create([
|
45
|
+
{
|
46
|
+
type: 0,
|
47
|
+
id: @social_network_id,
|
48
|
+
short_term_token: 'CAAGEIkkiehQrXSIK9vHOiPnZB139M',
|
49
|
+
long_term_token: 'CAAGXgR7VWu',
|
50
|
+
short_term_expiry: 1390238654000,
|
51
|
+
long_term_expiry: 1395417029000,
|
52
|
+
secret: '84bcd7da0e967139652f7ce59e4c859e'
|
53
|
+
}
|
54
|
+
])
|
55
|
+
end
|
56
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../lib/trustev'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
Trustev.username = 'FancyTees'
|
6
|
+
Trustev.password = '58dcca6b98a24e5a80b2a3682190da1a'
|
7
|
+
Trustev.shared_secret = '48357fbb820c407f855d72893d3f47ed'
|
8
|
+
Trustev.private_key = '65950d41f8d3ea86dc25aaf893ba15db'
|
9
|
+
|
10
|
+
def build_transaction
|
11
|
+
{
|
12
|
+
social_network: {
|
13
|
+
type: 0,
|
14
|
+
id: '780218520'
|
15
|
+
},
|
16
|
+
transaction_data: {
|
17
|
+
currency_code: 'EUR',
|
18
|
+
total_delivery: 10.0,
|
19
|
+
total_before_tax: 40,
|
20
|
+
total_discount: 10,
|
21
|
+
total_tax: 10,
|
22
|
+
total_transaction_value: 50.00,
|
23
|
+
timestamp: 1391449224000,
|
24
|
+
address: [
|
25
|
+
{
|
26
|
+
type: 0,
|
27
|
+
first_name: 'Joe',
|
28
|
+
last_name: 'Bloggs',
|
29
|
+
address_1: '2011',
|
30
|
+
address_2: 'Imaginary Way',
|
31
|
+
address_3: '',
|
32
|
+
city: 'Anycity',
|
33
|
+
state: 'AnyState',
|
34
|
+
postal_code: '123456',
|
35
|
+
country_code: 'US'
|
36
|
+
}
|
37
|
+
],
|
38
|
+
item: [
|
39
|
+
{
|
40
|
+
name: 'T-Shirt',
|
41
|
+
url: 'T-shirts.com',
|
42
|
+
image_url: 'T-shirts.com/Trustev-T-Shirt',
|
43
|
+
quantity: 1,
|
44
|
+
total_before_tax: 40.0,
|
45
|
+
total_discount: 0.0,
|
46
|
+
total_tax: 10,
|
47
|
+
total_item_value: 50.0
|
48
|
+
}
|
49
|
+
]
|
50
|
+
},
|
51
|
+
customer: {
|
52
|
+
first_name: 'John',
|
53
|
+
last_name: 'Doe',
|
54
|
+
phone_number: '00353861658789',
|
55
|
+
date_of_birth: 1403256280325,
|
56
|
+
email: [
|
57
|
+
{
|
58
|
+
is_default: true,
|
59
|
+
email_address: "jondoe@mail.com"
|
60
|
+
}
|
61
|
+
],
|
62
|
+
address: [
|
63
|
+
{
|
64
|
+
type: 0,
|
65
|
+
first_name: 'Joe',
|
66
|
+
last_name: 'Bloggs',
|
67
|
+
address_1: '2011',
|
68
|
+
address_2: 'Imaginary Way',
|
69
|
+
address_3: '',
|
70
|
+
city: 'Anycity',
|
71
|
+
state: 'AnyState',
|
72
|
+
postal_code: '123456',
|
73
|
+
country_code: 'US',
|
74
|
+
is_default: true
|
75
|
+
}
|
76
|
+
]
|
77
|
+
},
|
78
|
+
session_id: '4cec59b2-37f9-461e-9abc-861267e1a4d7'
|
79
|
+
}
|
80
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe Trustev::Transaction do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@transaction_number = SecureRandom.hex
|
8
|
+
@transaction = Trustev::Transaction.new(@transaction_number)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'when creating a transaction' do
|
12
|
+
it 'must return a good response code' do
|
13
|
+
@transaction.create(build_transaction).code.must_equal 200
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'when updating a transaction' do
|
18
|
+
it 'must return a good response code' do
|
19
|
+
@transaction.create(build_transaction)
|
20
|
+
@transaction.update(build_transaction).code.must_equal 200
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'when updating the status of a transaction' do
|
25
|
+
it 'must return a good response code' do
|
26
|
+
@transaction.create(build_transaction)
|
27
|
+
@transaction.set_status(3, 2, 'Transaction was refused due to a Trustev Score of 35').code.must_equal 200
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'when setting a transaction\'s BIN' do
|
32
|
+
it 'must return a good response code' do
|
33
|
+
@transaction.create(build_transaction)
|
34
|
+
@transaction.set_bin(411111).code.must_equal 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/trustev.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trustev/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'trustev'
|
8
|
+
spec.version = Trustev::VERSION
|
9
|
+
spec.authors = ['Jonah Hirsch']
|
10
|
+
spec.email = ['jonah@giftcardzen.com']
|
11
|
+
spec.summary = %q{Ruby wrapper for Trustev API.}
|
12
|
+
spec.description = %q{A Ruby wrapper for the Trustev API.}
|
13
|
+
spec.homepage = 'https://github.com/giftcardzen/trustev'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.4'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'httparty', '~> 0.13'
|
27
|
+
spec.add_runtime_dependency 'multi_json', '~> 1.10'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trustev
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonah Hirsch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.13'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: multi_json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.10'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.10'
|
97
|
+
description: A Ruby wrapper for the Trustev API.
|
98
|
+
email:
|
99
|
+
- jonah@giftcardzen.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- lib/trustev.rb
|
110
|
+
- lib/trustev/authenticate.rb
|
111
|
+
- lib/trustev/digital_signature.rb
|
112
|
+
- lib/trustev/error.rb
|
113
|
+
- lib/trustev/profile.rb
|
114
|
+
- lib/trustev/social.rb
|
115
|
+
- lib/trustev/transaction.rb
|
116
|
+
- lib/trustev/version.rb
|
117
|
+
- test/authenticate_test.rb
|
118
|
+
- test/digital_signature_test.rb
|
119
|
+
- test/error_test.rb
|
120
|
+
- test/profile_test.rb
|
121
|
+
- test/social_test.rb
|
122
|
+
- test/test_helper.rb
|
123
|
+
- test/transaction_test.rb
|
124
|
+
- trustev.gemspec
|
125
|
+
homepage: https://github.com/giftcardzen/trustev
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.2.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Ruby wrapper for Trustev API.
|
149
|
+
test_files:
|
150
|
+
- test/authenticate_test.rb
|
151
|
+
- test/digital_signature_test.rb
|
152
|
+
- test/error_test.rb
|
153
|
+
- test/profile_test.rb
|
154
|
+
- test/social_test.rb
|
155
|
+
- test/test_helper.rb
|
156
|
+
- test/transaction_test.rb
|
157
|
+
has_rdoc:
|