sift 1.1.6.2 → 4.5.0
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 +5 -13
- data/.circleci/config.yml +105 -0
- data/.github/pull_request_template.md +12 -0
- data/.github/workflows/publishing_sift_ruby.yml +38 -0
- data/.gitignore +1 -0
- data/.jenkins/Jenkinsfile +103 -0
- data/HISTORY +104 -0
- data/README.md +351 -0
- data/examples/psp_merchant_management_apis.rb +105 -0
- data/examples/validation_apis.rb +47 -0
- data/lib/sift/client/decision/apply_to.rb +129 -0
- data/lib/sift/client/decision.rb +66 -0
- data/lib/sift/client.rb +845 -112
- data/lib/sift/error.rb +13 -0
- data/lib/sift/router.rb +41 -0
- data/lib/sift/utils/hash_getter.rb +15 -0
- data/lib/sift/validate/decision.rb +65 -0
- data/lib/sift/validate/primitive.rb +43 -0
- data/lib/sift/version.rb +2 -2
- data/lib/sift.rb +85 -11
- data/sift.gemspec +5 -3
- data/spec/fixtures/fake_responses.rb +16 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/client/decision/apply_to_spec.rb +262 -0
- data/spec/unit/client/decision_spec.rb +83 -0
- data/spec/unit/client_203_spec.rb +193 -0
- data/spec/unit/client_205_spec.rb +117 -0
- data/spec/unit/client_label_spec.rb +68 -11
- data/spec/unit/client_psp_merchant_spec.rb +133 -0
- data/spec/unit/client_spec.rb +556 -79
- data/spec/unit/client_validationapi_spec.rb +91 -0
- data/spec/unit/router_spec.rb +37 -0
- data/spec/unit/validate/decision_spec.rb +85 -0
- data/spec/unit/validate/primitive_spec.rb +73 -0
- data/test_integration_app/decisions_api/test_decisions_api.rb +31 -0
- data/test_integration_app/events_api/test_events_api.rb +843 -0
- data/test_integration_app/globals.rb +2 -0
- data/test_integration_app/main.rb +67 -0
- data/test_integration_app/psp_merchants_api/test_psp_merchant_api.rb +44 -0
- data/test_integration_app/score_api/test_score_api.rb +11 -0
- data/test_integration_app/verification_api/test_verification_api.rb +32 -0
- metadata +85 -28
- data/.travis.yml +0 -13
- data/README.rdoc +0 -85
- data/spec/unit/sift_spec.rb +0 -6
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative "../../spec_helper"
|
2
|
+
require "multi_json"
|
3
|
+
|
4
|
+
require "spec/fixtures/fake_responses"
|
5
|
+
require "sift/client/decision"
|
6
|
+
require "sift/router"
|
7
|
+
|
8
|
+
module Sift
|
9
|
+
class Client
|
10
|
+
describe Decision do
|
11
|
+
let(:api_key) { "test_api_key" }
|
12
|
+
let(:account_id) { "test_account_id" }
|
13
|
+
let(:decision) { Decision.new(api_key, account_id) }
|
14
|
+
|
15
|
+
let(:decision_index_path) {
|
16
|
+
# TODO(Kaoru): When we move to webmock 2 we won't need to do this
|
17
|
+
# hackery
|
18
|
+
#
|
19
|
+
# https://github.com/bblimke/webmock/blob/master/CHANGELOG.md#200
|
20
|
+
#
|
21
|
+
protocal, uri = decision.index_path.split(/(?<=https\:\/\/)/)
|
22
|
+
|
23
|
+
protocal + api_key + "@" + uri
|
24
|
+
}
|
25
|
+
|
26
|
+
describe "#list" do
|
27
|
+
it "will return a response object that is ok" do
|
28
|
+
stub_request(:get, decision_index_path)
|
29
|
+
.to_return(body: MultiJson.dump(FakeDecisions.index))
|
30
|
+
|
31
|
+
response = decision.list
|
32
|
+
|
33
|
+
expect(response.ok?).to be(true)
|
34
|
+
expect(response.body["data"])
|
35
|
+
.to contain_exactly(*FakeDecisions.index[:data])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "will pass on query params" do
|
39
|
+
query_param = {
|
40
|
+
abuse_types: %w{promo_abuse content_abuse},
|
41
|
+
entity_type: "user",
|
42
|
+
limit: 10
|
43
|
+
}.inject("?") do |result, (key, value)|
|
44
|
+
value = value.join(",") if value.is_a? Array
|
45
|
+
"#{result}&#{key}=#{CGI.escape(value.to_s)}"
|
46
|
+
end
|
47
|
+
|
48
|
+
stub_request(:get, "#{decision_index_path}#{query_param}")
|
49
|
+
.to_return(body: MultiJson.dump(FakeDecisions.index))
|
50
|
+
|
51
|
+
response = decision.list({
|
52
|
+
limit: 10,
|
53
|
+
entity_type: "user",
|
54
|
+
abuse_types: %w{promo_abuse content_abuse}
|
55
|
+
})
|
56
|
+
|
57
|
+
expect(response.ok?).to be(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "with an unsuccessful response will return a response object" do
|
61
|
+
stub_request(:get, decision_index_path)
|
62
|
+
.to_return(status: 404, body: "{}")
|
63
|
+
|
64
|
+
response = decision.list
|
65
|
+
|
66
|
+
expect(response.ok?).to be(false)
|
67
|
+
expect(response.http_status_code).to be(404)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "will fetch next page" do
|
71
|
+
next_page = "#{decision.index_path}?from=100"
|
72
|
+
|
73
|
+
stub_request(:get, "#{decision_index_path}?from=100")
|
74
|
+
.to_return(body: MultiJson.dump(FakeDecisions.index))
|
75
|
+
|
76
|
+
response = decision.list({ "next_ref" => next_page })
|
77
|
+
|
78
|
+
expect(response.ok?).to be(true)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require "sift"
|
3
|
+
|
4
|
+
describe Sift::Client do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Sift.api_key = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid_transaction_properties
|
11
|
+
{
|
12
|
+
:$buyer_user_id => "123456",
|
13
|
+
:$seller_user_id => "654321",
|
14
|
+
:$amount => 1253200,
|
15
|
+
:$currency_code => "USD",
|
16
|
+
:$time => Time.now.to_i,
|
17
|
+
:$transaction_id => "my_transaction_id",
|
18
|
+
:$billing_name => "Mike Snow",
|
19
|
+
:$billing_bin => "411111",
|
20
|
+
:$billing_last4 => "1111",
|
21
|
+
:$billing_address1 => "123 Main St.",
|
22
|
+
:$billing_city => "San Francisco",
|
23
|
+
:$billing_region => "CA",
|
24
|
+
:$billing_country => "US",
|
25
|
+
:$billing_zip => "94131",
|
26
|
+
:$user_email => "mike@example.com"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def score_response_json
|
31
|
+
{
|
32
|
+
:user_id => "247019",
|
33
|
+
:score => 0.93,
|
34
|
+
:reasons => [{
|
35
|
+
:name => "UsersPerDevice",
|
36
|
+
:value => 4,
|
37
|
+
:details => {
|
38
|
+
:users => "a, b, c, d"
|
39
|
+
}
|
40
|
+
}],
|
41
|
+
:status => 0,
|
42
|
+
:error_message => "OK"
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def action_response_json
|
47
|
+
{
|
48
|
+
:user_id => "247019",
|
49
|
+
:score => 0.93,
|
50
|
+
:actions => [{
|
51
|
+
:action_id => "1234567890abcdefghijklmn",
|
52
|
+
:time => 1437421587052,
|
53
|
+
:triggers => [{
|
54
|
+
:triggerType => "FORMULA",
|
55
|
+
:source => "synchronous_action",
|
56
|
+
:trigger_id => "12345678900987654321abcd"
|
57
|
+
}],
|
58
|
+
:entity => {
|
59
|
+
:type => "USER",
|
60
|
+
:id => "23056"
|
61
|
+
}
|
62
|
+
},
|
63
|
+
{
|
64
|
+
:action_id => "12345678901234567890abcd",
|
65
|
+
:time => 1437421587410,
|
66
|
+
:triggers => [{
|
67
|
+
:triggerType => "FORMULA",
|
68
|
+
:source => "synchronous_action",
|
69
|
+
:trigger_id => "abcd12345678901234567890"
|
70
|
+
}],
|
71
|
+
:entity => {
|
72
|
+
:type => "ORDER",
|
73
|
+
:id => "order_at_ 1437421587009"
|
74
|
+
}
|
75
|
+
}],
|
76
|
+
:status => 0,
|
77
|
+
:error_message => "OK"
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def fully_qualified_api_endpoint
|
82
|
+
Sift::Client::API_ENDPOINT + Sift.rest_api_path
|
83
|
+
end
|
84
|
+
|
85
|
+
it "Successfully submits a v203 event with overridden key" do
|
86
|
+
response_json = { :status => 0, :error_message => "OK"}
|
87
|
+
stub_request(:post, "https://api.siftscience.com/v203/events").
|
88
|
+
with { | request|
|
89
|
+
parsed_body = JSON.parse(request.body)
|
90
|
+
expect(parsed_body).to include("$buyer_user_id" => "123456")
|
91
|
+
expect(parsed_body).to include("$api_key" => "overridden")
|
92
|
+
}.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
|
93
|
+
|
94
|
+
api_key = "foobar"
|
95
|
+
event = "$transaction"
|
96
|
+
properties = valid_transaction_properties
|
97
|
+
|
98
|
+
response = Sift::Client.new(:api_key => api_key, :version => "203")
|
99
|
+
.track(event, properties, :api_key => "overridden")
|
100
|
+
expect(response.ok?).to eq(true)
|
101
|
+
expect(response.api_status).to eq(0)
|
102
|
+
expect(response.api_error_message).to eq("OK")
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
it "Successfully fetches a v203 score" do
|
107
|
+
|
108
|
+
api_key = "foobar"
|
109
|
+
response_json = score_response_json
|
110
|
+
|
111
|
+
stub_request(:get, "https://api.siftscience.com/v203/score/247019/?api_key=foobar")
|
112
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json),
|
113
|
+
:headers => {"content-type"=>"application/json; charset=UTF-8",
|
114
|
+
"content-length"=> "74"})
|
115
|
+
|
116
|
+
response = Sift::Client.new(:api_key => api_key)
|
117
|
+
.score(score_response_json[:user_id], :version => 203)
|
118
|
+
expect(response.ok?).to eq(true)
|
119
|
+
expect(response.api_status).to eq(0)
|
120
|
+
expect(response.api_error_message).to eq("OK")
|
121
|
+
|
122
|
+
expect(response.body["score"]).to eq(0.93)
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
it "Successfully fetches a v203 score with an overridden key" do
|
127
|
+
|
128
|
+
api_key = "foobar"
|
129
|
+
response_json = score_response_json
|
130
|
+
|
131
|
+
stub_request(:get, "https://api.siftscience.com/v203/score/247019/?api_key=overridden")
|
132
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
|
133
|
+
|
134
|
+
response = Sift::Client.new(:api_key => api_key, :version => 203)
|
135
|
+
.score(score_response_json[:user_id], :api_key => "overridden")
|
136
|
+
expect(response.ok?).to eq(true)
|
137
|
+
expect(response.api_status).to eq(0)
|
138
|
+
expect(response.api_error_message).to eq("OK")
|
139
|
+
|
140
|
+
expect(response.body["score"]).to eq(0.93)
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
it "Successfuly make a v203 sync score request" do
|
145
|
+
|
146
|
+
api_key = "foobar"
|
147
|
+
response_json = {
|
148
|
+
:status => 0,
|
149
|
+
:error_message => "OK",
|
150
|
+
:score_response => score_response_json
|
151
|
+
}
|
152
|
+
|
153
|
+
stub_request(:post, "https://api.siftscience.com/v203/events?return_score=true")
|
154
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json),
|
155
|
+
:headers => {"content-type"=>"application/json; charset=UTF-8",
|
156
|
+
"content-length"=> "74"})
|
157
|
+
|
158
|
+
event = "$transaction"
|
159
|
+
properties = valid_transaction_properties
|
160
|
+
response = Sift::Client.new(:api_key => api_key)
|
161
|
+
.track(event, properties, :return_score => true, :version => "203")
|
162
|
+
expect(response.ok?).to eq(true)
|
163
|
+
expect(response.api_status).to eq(0)
|
164
|
+
expect(response.api_error_message).to eq("OK")
|
165
|
+
expect(response.body["score_response"]["score"]).to eq(0.93)
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
it "Successfuly make a v203 sync action request" do
|
170
|
+
|
171
|
+
api_key = "foobar"
|
172
|
+
response_json = {
|
173
|
+
:status => 0,
|
174
|
+
:error_message => "OK",
|
175
|
+
:score_response => action_response_json
|
176
|
+
}
|
177
|
+
|
178
|
+
stub_request(:post, "https://api.siftscience.com/v203/events?return_action=true")
|
179
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json),
|
180
|
+
:headers => {"content-type"=>"application/json; charset=UTF-8",
|
181
|
+
"content-length"=> "74"})
|
182
|
+
|
183
|
+
event = "$transaction"
|
184
|
+
properties = valid_transaction_properties
|
185
|
+
response = Sift::Client.new(:api_key => api_key, :version => "203")
|
186
|
+
.track(event, properties, :return_action => true)
|
187
|
+
expect(response.ok?).to eq(true)
|
188
|
+
expect(response.api_status).to eq(0)
|
189
|
+
expect(response.api_error_message).to eq("OK")
|
190
|
+
expect(response.body["score_response"]["actions"].first["entity"]["type"]).to eq("USER")
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require 'sift'
|
3
|
+
|
4
|
+
describe Sift::Client do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Sift.api_key = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid_transaction_properties
|
11
|
+
{
|
12
|
+
:$type => "$add_item_to_cart",
|
13
|
+
:$user_id => "haneeshv@exalture.com",
|
14
|
+
:$session_id => "gigtleqddo84l8cm15qe4il",
|
15
|
+
:$item => {
|
16
|
+
:$item_id => "B004834GQO",
|
17
|
+
:$product_title => "The Slanket Blanket-Texas Tea",
|
18
|
+
:$price => 39990000,
|
19
|
+
:$currency_code => "USD",
|
20
|
+
:$upc => "6786211451001",
|
21
|
+
:$sku => "004834GQ",
|
22
|
+
:$brand => "Slanket",
|
23
|
+
:$manufacturer => "Slanket",
|
24
|
+
:$category => "Blankets & Throws",
|
25
|
+
:$tags => [
|
26
|
+
"Awesome",
|
27
|
+
"Wintertime specials"
|
28
|
+
],
|
29
|
+
:$color => "Texas Tea",
|
30
|
+
:$quantity => 16
|
31
|
+
},
|
32
|
+
:$brand_name => "sift",
|
33
|
+
:$site_domain => "sift.com",
|
34
|
+
:$site_country => "US",
|
35
|
+
:$browser => {
|
36
|
+
:$user_agent => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
|
37
|
+
:$accept_language => "en-US",
|
38
|
+
:$content_language => "en-GB"
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def percentile_response_json
|
44
|
+
{
|
45
|
+
:user_id => 'haneeshv@exalture.com',
|
46
|
+
:latest_labels => {},
|
47
|
+
:workflow_statuses => [],
|
48
|
+
:scores => {
|
49
|
+
:account_abuse => {
|
50
|
+
:score => 0.32787917675535705,
|
51
|
+
:reasons => [{
|
52
|
+
:name => 'Latest item product title',
|
53
|
+
:value => 'The Slanket Blanket-Texas Tea'
|
54
|
+
}],
|
55
|
+
:percentiles => {
|
56
|
+
:last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
|
57
|
+
}
|
58
|
+
},
|
59
|
+
:acontent_abuse => {
|
60
|
+
:score => 0.28056292905897995,
|
61
|
+
:reasons => [{
|
62
|
+
:name => 'timeSinceFirstEvent',
|
63
|
+
:value => '13.15 minutes'
|
64
|
+
}],
|
65
|
+
:percentiles => {
|
66
|
+
:last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
|
67
|
+
}
|
68
|
+
},
|
69
|
+
:payment_abuse => {
|
70
|
+
:score => 0.28610507028376797,
|
71
|
+
:reasons => [{
|
72
|
+
:name => 'Latest item currency code',
|
73
|
+
:value => 'USD'
|
74
|
+
}, {
|
75
|
+
:name => 'Latest item item ID',
|
76
|
+
:value => 'B004834GQO'
|
77
|
+
}, {
|
78
|
+
:name => 'Latest item product title',
|
79
|
+
:value => 'The Slanket Blanket-Texas Tea'
|
80
|
+
}],
|
81
|
+
:percentiles => {
|
82
|
+
:last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
|
83
|
+
}
|
84
|
+
},
|
85
|
+
:promotion_abuse => {
|
86
|
+
:score => 0.05731508921450917,
|
87
|
+
:percentiles => {
|
88
|
+
:last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
|
89
|
+
}
|
90
|
+
}
|
91
|
+
},
|
92
|
+
:status => 0,
|
93
|
+
:error_message => 'OK'
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
it "Successfully submits a v205 event with SCORE_PERCENTILES" do
|
98
|
+
response_json =
|
99
|
+
{ :status => 0, :error_message => "OK", :score_response => percentile_response_json}
|
100
|
+
stub_request(:post, "https://api.siftscience.com/v205/events?fields=SCORE_PERCENTILES&return_score=true").
|
101
|
+
with { | request|
|
102
|
+
parsed_body = JSON.parse(request.body)
|
103
|
+
expect(parsed_body).to include("$api_key" => "overridden")
|
104
|
+
}.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
|
105
|
+
|
106
|
+
api_key = "foobar"
|
107
|
+
event = "$transaction"
|
108
|
+
properties = valid_transaction_properties
|
109
|
+
|
110
|
+
response = Sift::Client.new(:api_key => api_key, :version => "205")
|
111
|
+
.track(event, properties, :api_key => "overridden", :include_score_percentiles => "true", :return_score => "true")
|
112
|
+
expect(response.ok?).to eq(true)
|
113
|
+
expect(response.api_status).to eq(0)
|
114
|
+
expect(response.api_error_message).to eq("OK")
|
115
|
+
expect(response.body["score_response"]["scores"]["account_abuse"]["percentiles"]["last_7_days"]).to eq(-1.0)
|
116
|
+
end
|
117
|
+
end
|
@@ -1,8 +1,17 @@
|
|
1
|
-
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require "sift"
|
2
3
|
|
3
4
|
describe Sift::Client do
|
4
5
|
|
5
6
|
def valid_label_properties
|
7
|
+
{
|
8
|
+
:$abuse_type => 'content_abuse',
|
9
|
+
:$is_bad => true,
|
10
|
+
:$description => "Listed a fake item"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid_label_properties_203
|
6
15
|
{
|
7
16
|
:$reasons => [ "$fake" ],
|
8
17
|
:$is_bad => true,
|
@@ -10,26 +19,74 @@ describe Sift::Client do
|
|
10
19
|
}
|
11
20
|
end
|
12
21
|
|
13
|
-
|
14
|
-
|
22
|
+
|
23
|
+
it "Successfuly handles a $label and returns OK" do
|
24
|
+
|
25
|
+
response_json = { :status => 0, :error_message => "OK" }
|
26
|
+
user_id = "frodo_baggins"
|
27
|
+
|
28
|
+
stub_request(:post, "https://api.siftscience.com/v205/users/frodo_baggins/labels")
|
29
|
+
.with(:body => ('{"$abuse_type":"content_abuse","$is_bad":true,"$description":"Listed a fake item","$type":"$label","$api_key":"foobar"}'))
|
30
|
+
.to_return(:body => MultiJson.dump(response_json), :status => 200,
|
31
|
+
:headers => {"content-type"=>"application/json; charset=UTF-8",
|
32
|
+
"content-length"=> "74"})
|
33
|
+
|
34
|
+
api_key = "foobar"
|
35
|
+
properties = valid_label_properties
|
36
|
+
|
37
|
+
response = Sift::Client.new(:api_key => api_key).label(user_id, properties)
|
38
|
+
expect(response.ok?).to eq(true)
|
39
|
+
expect(response.api_status).to eq(0)
|
40
|
+
expect(response.api_error_message).to eq("OK")
|
15
41
|
end
|
16
42
|
|
43
|
+
|
44
|
+
it "Successfully handles an $unlabel and returns OK" do
|
45
|
+
user_id = "frodo_baggins"
|
46
|
+
|
47
|
+
stub_request(:delete,
|
48
|
+
"https://api.siftscience.com/v205/users/frodo_baggins/labels?api_key=foobar&abuse_type=payment_abuse")
|
49
|
+
.to_return(:status => 204)
|
50
|
+
|
51
|
+
api_key = "foobar"
|
52
|
+
|
53
|
+
response = Sift::Client.new(:api_key => api_key).unlabel(user_id, :abuse_type => 'payment_abuse')
|
54
|
+
expect(response.ok?).to eq(true)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
17
58
|
it "Successfuly handles a $label with the v203 API and returns OK" do
|
18
59
|
|
19
60
|
response_json = { :status => 0, :error_message => "OK" }
|
20
61
|
user_id = "frodo_baggins"
|
21
62
|
|
22
|
-
stub_request(:post, "https://api.siftscience.com/v203/users/frodo_baggins/labels")
|
23
|
-
with(:body => '{"$reasons":["$fake"],"$is_bad":true,"$description":"Listed a fake item","$type":"$label","$api_key":"foobar"}')
|
24
|
-
to_return(:body => MultiJson.dump(response_json), :status => 200,
|
63
|
+
stub_request(:post, "https://api.siftscience.com/v203/users/frodo_baggins/labels")
|
64
|
+
.with(:body => ('{"$reasons":["$fake"],"$is_bad":true,"$description":"Listed a fake item","$type":"$label","$api_key":"foobar"}'))
|
65
|
+
.to_return(:body => MultiJson.dump(response_json), :status => 200,
|
66
|
+
:headers => {"content-type"=>"application/json; charset=UTF-8",
|
67
|
+
"content-length"=> "74"})
|
68
|
+
|
69
|
+
api_key = "foobar"
|
70
|
+
properties = valid_label_properties_203
|
71
|
+
|
72
|
+
response = Sift::Client.new(:api_key => api_key, :version => 203).label(user_id, properties)
|
73
|
+
expect(response.ok?).to eq(true)
|
74
|
+
expect(response.api_status).to eq(0)
|
75
|
+
expect(response.api_error_message).to eq("OK")
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
it "Successfully handles an $unlabel with the v203 API endpoing and returns OK" do
|
80
|
+
user_id = "frodo_baggins"
|
81
|
+
|
82
|
+
stub_request(:delete,
|
83
|
+
"https://api.siftscience.com/v203/users/frodo_baggins/labels?api_key=foobar")
|
84
|
+
.to_return(:status => 204)
|
25
85
|
|
26
86
|
api_key = "foobar"
|
27
|
-
properties = valid_label_properties
|
28
87
|
|
29
|
-
response = Sift::Client.new(api_key).
|
30
|
-
response.ok
|
31
|
-
response.api_status.should eq(0)
|
32
|
-
response.api_error_message.should eq("OK")
|
88
|
+
response = Sift::Client.new(:api_key => api_key).unlabel(user_id, :version => "203")
|
89
|
+
expect(response.ok?).to eq(true)
|
33
90
|
end
|
34
91
|
|
35
92
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative "../spec_helper"
|
2
|
+
require "sift"
|
3
|
+
|
4
|
+
describe Sift::Client do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Sift.api_key = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def post_psp_merchant_properties
|
11
|
+
{
|
12
|
+
"id": "api-key1-6",
|
13
|
+
"name": "Wonderful Payments Inc.",
|
14
|
+
"description": "Wonderful Payments payment provider.",
|
15
|
+
"address": {
|
16
|
+
"name": "Alany",
|
17
|
+
"address_1": "Big Payment blvd, 22",
|
18
|
+
"address_2": "apt, 8",
|
19
|
+
"city": "New Orleans",
|
20
|
+
"region": "NA",
|
21
|
+
"country": "US",
|
22
|
+
"zipcode": "76830",
|
23
|
+
"phone": "0394888320"
|
24
|
+
},
|
25
|
+
"category": "1002",
|
26
|
+
"service_level": "Platinum",
|
27
|
+
"status": "active",
|
28
|
+
"risk_profile": {
|
29
|
+
"level": "low",
|
30
|
+
"score": 10
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def put_psp_merchant_properties
|
36
|
+
{
|
37
|
+
"id": "api-key1-7",
|
38
|
+
"name": "Wonderful Payments Inc.",
|
39
|
+
"description": "Wonderful Payments payment provider.",
|
40
|
+
"address": {
|
41
|
+
"name": "Alany",
|
42
|
+
"address_1": "Big Payment blvd, 22",
|
43
|
+
"address_2": "apt, 8",
|
44
|
+
"city": "New Orleans",
|
45
|
+
"region": "NA",
|
46
|
+
"country": "US",
|
47
|
+
"zipcode": "76830",
|
48
|
+
"phone": "0394888320"
|
49
|
+
},
|
50
|
+
"category": "1002",
|
51
|
+
"service_level": "Platinum",
|
52
|
+
"status": "active",
|
53
|
+
"risk_profile": {
|
54
|
+
"level": "low",
|
55
|
+
"score": 10
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
it "Successfully sumit create psp merchant" do
|
61
|
+
api_key = "foobar1"
|
62
|
+
|
63
|
+
response_json = { :status => 0, :error_message => "OK" }
|
64
|
+
|
65
|
+
stub_request(:post, "https://foobar1:@api.siftscience.com/v3/accounts/ACCT/psp_management/merchants")
|
66
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json))
|
67
|
+
|
68
|
+
response = Sift::Client.new(:api_key => api_key, :account_id => "ACCT").create_psp_merchant_profile(post_psp_merchant_properties)
|
69
|
+
expect(response.ok?).to eq(true)
|
70
|
+
expect(response.api_status).to eq(0)
|
71
|
+
expect(response.api_error_message).to eq("OK")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "Successfully submit update psp merchant" do
|
75
|
+
api_key = "foobar1"
|
76
|
+
merchant_id = "api-key1-7"
|
77
|
+
|
78
|
+
response_json = { :status => 0, :error_message => "OK"}
|
79
|
+
|
80
|
+
stub_request(:put, "https://foobar1:@api.siftscience.com/v3/accounts/ACCT/psp_management/merchants/api-key1-7")
|
81
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json))
|
82
|
+
|
83
|
+
response = Sift::Client.new(:api_key => api_key, :account_id => "ACCT").update_psp_merchant_profile(merchant_id, put_psp_merchant_properties)
|
84
|
+
expect(response.ok?).to eq(true)
|
85
|
+
expect(response.api_status).to eq(0)
|
86
|
+
expect(response.api_error_message).to eq("OK")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "Successfully get a psp merchant profile" do
|
90
|
+
api_key = "foobar1"
|
91
|
+
merchant_id = "api-key1-7"
|
92
|
+
|
93
|
+
response_json = { :status => 0, :error_message => "OK"}
|
94
|
+
|
95
|
+
stub_request(:get, "https://foobar1:@api.siftscience.com/v3/accounts/ACCT/psp_management/merchants/api-key1-7")
|
96
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json))
|
97
|
+
|
98
|
+
response = Sift::Client.new(:api_key => api_key, :account_id => "ACCT").get_a_psp_merchant_profile(merchant_id)
|
99
|
+
expect(response.ok?).to eq(true)
|
100
|
+
expect(response.api_status).to eq(0)
|
101
|
+
expect(response.api_error_message).to eq("OK")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "Successfully get all psp merchant profile with batch size" do
|
105
|
+
api_key = "foobar1"
|
106
|
+
|
107
|
+
response_json = { :status => 0, :error_message => "OK"}
|
108
|
+
|
109
|
+
stub_request(:get, "https://foobar1:@api.siftscience.com/v3/accounts/ACCT/psp_management/merchants?batch_size=2")
|
110
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json))
|
111
|
+
|
112
|
+
response = Sift::Client.new(:api_key => api_key, :account_id => "ACCT").get_psp_merchant_profiles(2)
|
113
|
+
expect(response.ok?).to eq(true)
|
114
|
+
expect(response.api_status).to eq(0)
|
115
|
+
expect(response.api_error_message).to eq("OK")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "Successfully get all psp merchant profile with batch size and batch token" do
|
119
|
+
api_key = "foobar1"
|
120
|
+
batch_size = 2
|
121
|
+
batch_token = "batch_token"
|
122
|
+
response_json = { :status => 0, :error_message => "OK"}
|
123
|
+
|
124
|
+
stub_request(:get, "https://foobar1:@api.siftscience.com/v3/accounts/ACCT/psp_management/merchants?batch_size=2&batch_token=batch_token")
|
125
|
+
.to_return(:status => 200, :body => MultiJson.dump(response_json))
|
126
|
+
|
127
|
+
response = Sift::Client.new(:api_key => api_key, :account_id => "ACCT").get_psp_merchant_profiles(batch_size, batch_token)
|
128
|
+
expect(response.ok?).to eq(true)
|
129
|
+
expect(response.api_status).to eq(0)
|
130
|
+
expect(response.api_error_message).to eq("OK")
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|