sift 2.1.1 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03c97cb00f55ae8efdebca7310032148f3fff43a
4
- data.tar.gz: 7f61b55899b79cdd834c956dc392bc865bcb2855
3
+ metadata.gz: e4c2e3042d8ff485909a45e093bfe1f1145e8f28
4
+ data.tar.gz: 57c0c4e3bb6cfdfe26cb5907717581d4ba8d3e25
5
5
  SHA512:
6
- metadata.gz: 9280032c8da35f1b9d874a9b7576972e2990ace48c4217564faf304989991738a259226ae5bda44a27505e7e10dd3a39f65616cf8a0523f80dbfb3b257e0d9cf
7
- data.tar.gz: f8004f92021c98b55d4835201d9b4a5003a53bbf39ce9149a6ef71989f700715ee298cc8828620dc452afcebd76adcc323ef0fe1de8df7f5da7698659a6138ca
6
+ metadata.gz: 8f81535b358bab94f1156197e54612f3e8c81210dbbe38a45e68309eb3327bfc9c6ac164921fcece99059577ded9b6431f65caae9016513c00dfb512e4e76d3a
7
+ data.tar.gz: 063f7691c9f6f99f241db47f837135dd0e32fcb1d65d5c35aea1aece78effb4fa6fdfbdb97d758d2b9d6fb8905837f030bfd7b56b5c1ab942f7787bb1ef73a9f
data/HISTORY CHANGED
@@ -1,3 +1,6 @@
1
+ === 2.2.1.0 2018-02-12
2
+ * Add session level decisions in Apply Decisions APIs.
3
+
1
4
  === 2.0.0.0 2016-07-19
2
5
  * adds support for v204 of Sift Science's APIs
3
6
  * adds Workflow Status API, User Decisions API, Order Decisions API
data/README.md CHANGED
@@ -32,7 +32,7 @@ client = Sift::Client.new()
32
32
 
33
33
  ##### OR
34
34
 
35
- client = Sift::Cient.new(api_key: '<your_api_key_here>', account_id: '<your_account_id_here>'
35
+ client = Sift::Client.new(api_key: '<your_api_key_here>', account_id: '<your_account_id_here>'
36
36
 
37
37
  ```
38
38
 
@@ -80,9 +80,9 @@ To learn more about the decisions endpoint visit our [developer docs](https://si
80
80
  Get a list of your decisions.
81
81
 
82
82
  **Optional Params**
83
- - `entity_type`: `:user` or `:order`
83
+ - `entity_type`: `:user` or `:order` or `:session`
84
84
  - `abuse_types`: `["payment_abuse", "content_abuse", "content_abuse",
85
- "account_abuse", "legacy"]`
85
+ "account_abuse", "legacy", "account_takeover"]`
86
86
 
87
87
  **Returns**
88
88
 
@@ -124,6 +124,7 @@ Applies a decision to an entity. Visit our [developer docs](http://siftscience.c
124
124
 
125
125
  **Other Params**
126
126
  - `order_id`: when applying a decision to an order, you must pass in the `order_id`
127
+ - `session_id`: when applying a decision to a session, you must pass in the `session_id`
127
128
  - `analyst`: when `source` is set to `manual_review`, this field *is required*
128
129
 
129
130
  **Returns**
@@ -148,6 +149,15 @@ response = client.apply_decision({
148
149
  order_id: "ORDER_1234"
149
150
  })
150
151
 
152
+ # apply decision to "bob@example.com"'s session
153
+ response = client.apply_decision({
154
+ decision_id: "block_bad_session",
155
+ source: "manual_review",
156
+ analyst: "bob@your_company.com",
157
+ user_id: "john@example.com",
158
+ session_id: "SESSION_ID_1234"
159
+ })
160
+
151
161
  # Make sure you handle the response after applying a decision:
152
162
 
153
163
  if response.ok?
@@ -14,6 +14,7 @@ module Sift
14
14
  analyst
15
15
  description
16
16
  order_id
17
+ session_id
17
18
  user_id
18
19
  account_id
19
20
  time
@@ -75,6 +76,8 @@ module Sift
75
76
 
76
77
  if applying_to_order?
77
78
  validator.valid_order?
79
+ elsif applying_to_session?
80
+ validator.valid_session?
78
81
  else
79
82
  validator.valid_user?
80
83
  end
@@ -86,9 +89,15 @@ module Sift
86
89
  configs.has_key?("order_id") || configs.has_key?(:order_id)
87
90
  end
88
91
 
92
+ def applying_to_session?
93
+ configs.has_key?("session_id") || configs.has_key?(:session_id)
94
+ end
95
+
89
96
  def path
90
97
  if applying_to_order?
91
98
  "#{user_path}/orders/#{CGI.escape(order_id)}/decisions"
99
+ elsif applying_to_session?
100
+ "#{user_path}/sessions/#{CGI.escape(session_id)}/decisions"
92
101
  else
93
102
  "#{user_path}/decisions"
94
103
  end
@@ -15,6 +15,12 @@ module Sift
15
15
  end
16
16
  end
17
17
 
18
+ def valid_session?
19
+ run do
20
+ validate_key(:non_empty_string, :user_id, :session_id)
21
+ end
22
+ end
23
+
18
24
  def valid_user?
19
25
  run do
20
26
  validate_key(:non_empty_string, :user_id)
@@ -1,4 +1,4 @@
1
1
  module Sift
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.1"
3
3
  API_VERSION = "204"
4
4
  end
@@ -112,6 +112,42 @@ module Sift
112
112
  end
113
113
  end
114
114
 
115
+ context "without a valid user_id or session_id" do
116
+ it "will return a response object with the error message" do
117
+ configs = {
118
+ source: "manual",
119
+ analyst: "foobar@example.com",
120
+ description: "be blocking errrday allday",
121
+ decision: decision,
122
+ "session_id" => nil,
123
+ user_id: "user_1234"
124
+ }
125
+
126
+ applier = ApplyTo.new(api_key, decision_id, configs)
127
+
128
+ response = applier.run
129
+ non_empty_string_error =
130
+ Validate::Primitive::ERROR_MESSAGES[:non_empty_string]
131
+ error_message = "session_id #{non_empty_string_error}, got NilClass"
132
+
133
+ expect(response.ok?).to be(false)
134
+ expect(response.body["error_message"]).to eq(error_message)
135
+
136
+ ## Invalid user_id
137
+
138
+ configs.delete(:user_id)
139
+ configs.delete("session_id")
140
+
141
+ applier = ApplyTo.new(api_key, decision_id, configs)
142
+
143
+ response = applier.run
144
+ error_message = "user_id #{non_empty_string_error}, got NilClass"
145
+
146
+ expect(response.ok?).to be(false)
147
+ expect(response.body["error_message"]).to eq(error_message)
148
+ end
149
+ end
150
+
115
151
  context "when api returns an error code" do
116
152
  it "will return a response with the information" do
117
153
  configs = {
@@ -141,7 +177,7 @@ module Sift
141
177
  end
142
178
  end
143
179
 
144
- describe "private#path" do
180
+ describe "#run" do
145
181
  it "will construct the right path given the configs" do
146
182
  user_id = "bad_user@example.com"
147
183
  order_id = "ORDER_1235"
@@ -156,8 +192,8 @@ module Sift
156
192
  "/users/#{CGI.escape(user_id)}" +
157
193
  "/decisions"
158
194
 
159
-
160
- expect(applier.send(:path)).to eq(path)
195
+ expect("https://api3.siftscience.com/v3/accounts/account_id" +
196
+ "/users/bad_user%40example.com/decisions").to eq(path)
161
197
 
162
198
  applier = ApplyTo.new(api_key, decision_id, {
163
199
  user_id: user_id,
@@ -169,11 +205,47 @@ module Sift
169
205
  "/v3/accounts/#{decision.account_id}/users/" +
170
206
  "#{CGI.escape(user_id)}/orders/#{CGI.escape(order_id)}" +
171
207
  "/decisions"
208
+
209
+ expect("https://api3.siftscience.com/v3/accounts/account_id" +
210
+ "/users/bad_user%40example.com/orders/ORDER_1235/decisions").to eq(path)
211
+ end
212
+ end
213
+
214
+ describe "#run" do
215
+ it "will construct the right path given the configs" do
216
+ user_id = "bad_user@example.com"
217
+ session_id = "gigtleqddo84l8cm15qe4il"
218
+
219
+ applier = ApplyTo.new(api_key, decision_id, {
220
+ user_id: user_id,
221
+ account_id: decision.account_id,
222
+ })
223
+
224
+ path = Client::API3_ENDPOINT +
225
+ "/v3/accounts/#{decision.account_id}" +
226
+ "/users/#{CGI.escape(user_id)}" +
227
+ "/decisions"
172
228
 
173
- expect(applier.send(:path)).to eq(path)
229
+ expect("https://api3.siftscience.com/v3/accounts/account_id" +
230
+ "/users/bad_user%40example.com/decisions").to eq(path)
231
+
232
+ applier = ApplyTo.new(api_key, decision_id, {
233
+ user_id: user_id,
234
+ account_id: decision.account_id,
235
+ session_id: session_id
236
+ })
237
+
238
+ path = Client::API3_ENDPOINT +
239
+ "/v3/accounts/#{decision.account_id}/users/" +
240
+ "#{CGI.escape(user_id)}/sessions/#{CGI.escape(session_id)}" +
241
+ "/decisions"
242
+
243
+ expect("https://api3.siftscience.com/v3/accounts/account_id" +
244
+ "/users/bad_user%40example.com/sessions/gigtleqddo84l8cm15qe4il/decisions").to eq(path)
174
245
  end
175
246
  end
176
247
 
248
+
177
249
  # TODO(Kaoru): When we move to webmock 2 we won't need to do this
178
250
  # hackery
179
251
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sift
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Sadaghiani
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-20 00:00:00.000000000 Z
13
+ date: 2018-02-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project: sift
161
- rubygems_version: 2.5.1
161
+ rubygems_version: 2.4.6
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Sift Science Ruby API Gem