sift 4.3.0 → 4.4.0

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
  SHA256:
3
- metadata.gz: e538e799471ba36d0c73d8b6bdea81f56e5928ef018a01a8aa0d1d376151ba97
4
- data.tar.gz: 7ba73b5ea722594550ce5fb2b9259c8728b6658ac393206f991ac182e6216fd1
3
+ metadata.gz: 3ba7bb7dc985a6f320db6c39717c90e349a16306ec2b85f7a2ba28945c5e2f64
4
+ data.tar.gz: 8665633d78bb4c9502443f241943d4fb98015ede3060d233913169f5921d528b
5
5
  SHA512:
6
- metadata.gz: d6a650d190c215fa627b364e134e51d35012edd1b40682c8d24e8ea446e7bbbcfc2121189d9ef1335a5f67ee5aeb4472c42823e99737bd5879ea14a51c4f0e2c
7
- data.tar.gz: 1569ecf84bf4bfee1991a7664922293a24ab6993ac56766b28a10183cd8cc593641ff301c3e68fbdc1e8f2f51b3425b1ad64131332c12c4ded51489e54703eb3
6
+ metadata.gz: 75ce0e5c6631fbd4aa22ad72cb2ad9cebc0cf5ee0ec7e7de1dc308d9d90d3c1ef288a75a699ac0ef04ae650700a4a7b63ad1ece30d1386da0c06ceefcea10420
7
+ data.tar.gz: 3804c62aaf0795bfce7eadc4d048ae36d3a67a0d1dd9c81548d31926f950a5908a4fb158a8363182bb14ebb77545d3c671b37292802c093ea31719176683bb26
@@ -12,18 +12,14 @@ jobs:
12
12
  steps:
13
13
  - name: Checkout code
14
14
  uses: actions/checkout@v3
15
-
16
-
17
15
  - name: Set up Ruby
18
16
  uses: ruby/setup-ruby@v1
19
17
  with:
20
18
  ruby-version: 2.7
21
-
22
19
  - name: Install Bundler
23
20
  run: |
24
21
  sudo gem install bundler
25
22
  bundle install
26
-
27
23
  - name: Build and push gem
28
24
  run: |
29
25
  mkdir -p $HOME/.gem
@@ -37,14 +33,6 @@ jobs:
37
33
  gem build sift.gemspec
38
34
  gem push sift-$version.gem
39
35
  rm -rf $HOME/.gem
40
- ls -la $HOME/
41
36
  else
42
37
  echo "Gem version $version exists on RubyGems"
43
38
  fi
44
-
45
- - name: Run Rake tasks
46
- run: |
47
- bundle exec rake -T
48
- bundle exec rake build
49
- bundle exec rake install
50
- bundle exec rake release
data/HISTORY CHANGED
@@ -1,3 +1,6 @@
1
+ === 4.4.0 2023-10-05
2
+ - Score percentiles in Score API
3
+
1
4
  === 4.3.0 2023-08-21
2
5
  - PSP Merchant Management API
3
6
 
data/lib/sift/client.rb CHANGED
@@ -201,6 +201,9 @@ module Sift
201
201
  #
202
202
  # :path::
203
203
  # Overrides the URI path for this API call.
204
+ #
205
+ # :include_score_percentiles::
206
+ # include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
204
207
  #
205
208
  # ==== Returns:
206
209
  #
@@ -275,6 +278,9 @@ module Sift
275
278
  #
276
279
  # :version::
277
280
  # Overrides the version of the Events API to call.
281
+ #
282
+ # :include_score_percentiles::
283
+ # include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
278
284
  #
279
285
  # ==== Returns:
280
286
  #
@@ -286,6 +292,7 @@ module Sift
286
292
  api_key = opts[:api_key] || @api_key
287
293
  timeout = opts[:timeout] || @timeout
288
294
  version = opts[:version] || @version
295
+ include_score_percentiles = opts[:include_score_percentiles]
289
296
 
290
297
  raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
291
298
  raise("Bad api_key parameter") if api_key.empty?
@@ -293,6 +300,9 @@ module Sift
293
300
  query = {}
294
301
  query["api_key"] = api_key
295
302
  query["abuse_types"] = abuse_types.join(",") if abuse_types
303
+ if include_score_percentiles == "true"
304
+ query["fields"] = "SCORE_PERCENTILES"
305
+ end
296
306
 
297
307
  options = {
298
308
  :headers => {"User-Agent" => user_agent},
@@ -332,6 +342,9 @@ module Sift
332
342
  #
333
343
  # :timeout::
334
344
  # Overrides the timeout (in seconds) for this call.
345
+ #
346
+ # :include_score_percentiles::
347
+ # include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
335
348
  #
336
349
  # ==== Returns:
337
350
  #
@@ -342,6 +355,7 @@ module Sift
342
355
  abuse_types = opts[:abuse_types]
343
356
  api_key = opts[:api_key] || @api_key
344
357
  timeout = opts[:timeout] || @timeout
358
+ include_score_percentiles = opts[:include_score_percentiles]
345
359
 
346
360
  raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
347
361
  raise("Bad api_key parameter") if api_key.empty?
@@ -349,6 +363,9 @@ module Sift
349
363
  query = {}
350
364
  query["api_key"] = api_key
351
365
  query["abuse_types"] = abuse_types.join(",") if abuse_types
366
+ if include_score_percentiles == "true"
367
+ query["fields"] = "SCORE_PERCENTILES"
368
+ end
352
369
 
353
370
  options = {
354
371
  :headers => {"User-Agent" => user_agent},
data/lib/sift/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Sift
2
- VERSION = "4.3.0"
2
+ VERSION = "4.4.0"
3
3
  API_VERSION = "205"
4
4
  end
@@ -110,6 +110,60 @@ describe Sift::Client do
110
110
  }
111
111
  end
112
112
 
113
+ def percentile_response_json
114
+ {
115
+ :user_id => 'billy_jones_301',
116
+ :latest_labels => {},
117
+ :workflow_statuses => [],
118
+ :scores => {
119
+ :account_abuse => {
120
+ :score => 0.32787917675535705,
121
+ :reasons => [{
122
+ :name => 'Latest item product title',
123
+ :value => 'The Slanket Blanket-Texas Tea'
124
+ }],
125
+ :percentiles => {
126
+ :last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
127
+ }
128
+ },
129
+ :acontent_abuse => {
130
+ :score => 0.28056292905897995,
131
+ :reasons => [{
132
+ :name => 'timeSinceFirstEvent',
133
+ :value => '13.15 minutes'
134
+ }],
135
+ :percentiles => {
136
+ :last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
137
+ }
138
+ },
139
+ :payment_abuse => {
140
+ :score => 0.28610507028376797,
141
+ :reasons => [{
142
+ :name => 'Latest item currency code',
143
+ :value => 'USD'
144
+ }, {
145
+ :name => 'Latest item item ID',
146
+ :value => 'B004834GQO'
147
+ }, {
148
+ :name => 'Latest item product title',
149
+ :value => 'The Slanket Blanket-Texas Tea'
150
+ }],
151
+ :percentiles => {
152
+ :last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
153
+ }
154
+ },
155
+ :promotion_abuse => {
156
+ :score => 0.05731508921450917,
157
+ :percentiles => {
158
+ :last_7_days => -1.0, :last_1_days => -1.0, :last_10_days => -1.0, :last_5_days => -1.0
159
+ }
160
+ }
161
+ },
162
+ :status => 0,
163
+ :error_message => 'OK'
164
+ }
165
+ end
166
+
113
167
  def fully_qualified_api_endpoint
114
168
  Sift::Client::API_ENDPOINT + Sift.rest_api_path
115
169
  end
@@ -554,4 +608,85 @@ describe Sift::Client do
554
608
  expect(response.body["decisions"]["content_abuse"]["decision"]["id"]).to eq("decision7")
555
609
  end
556
610
 
611
+ it "Successfully submits a v205 event with SCORE_PERCENTILES" do
612
+ response_json =
613
+ { :status => 0, :error_message => "OK", :score_response => percentile_response_json}
614
+ stub_request(:post, "https://api.siftscience.com/v205/events?fields=SCORE_PERCENTILES&return_score=true").
615
+ with { | request|
616
+ parsed_body = JSON.parse(request.body)
617
+ expect(parsed_body).to include("$api_key" => "overridden")
618
+ }.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
619
+
620
+ api_key = "foobar"
621
+ event = "$transaction"
622
+ properties = valid_transaction_properties
623
+
624
+ response = Sift::Client.new(:api_key => api_key, :version => "205")
625
+ .track(event, properties, :api_key => "overridden", :include_score_percentiles => "true", :return_score => "true")
626
+ expect(response.ok?).to eq(true)
627
+ expect(response.api_status).to eq(0)
628
+ expect(response.api_error_message).to eq("OK")
629
+ expect(response.body["score_response"]["scores"]["account_abuse"]["percentiles"]["last_7_days"]).to eq(-1.0)
630
+ end
631
+
632
+ it "Successfully submits a v205 event with SCORE_PERCENTILES" do
633
+ response_json =
634
+ { :status => 0, :error_message => "OK", :score_response => percentile_response_json}
635
+ stub_request(:post, "https://api.siftscience.com/v205/events?fields=SCORE_PERCENTILES&return_score=true").
636
+ with { | request|
637
+ parsed_body = JSON.parse(request.body)
638
+ expect(parsed_body).to include("$api_key" => "overridden")
639
+ }.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
640
+
641
+ api_key = "foobar"
642
+ event = "$transaction"
643
+ properties = valid_transaction_properties
644
+
645
+ response = Sift::Client.new(:api_key => api_key, :version => "205")
646
+ .track(event, properties, :api_key => "overridden", :include_score_percentiles => "true", :return_score => "true")
647
+ expect(response.ok?).to eq(true)
648
+ expect(response.api_status).to eq(0)
649
+ expect(response.api_error_message).to eq("OK")
650
+ expect(response.body["score_response"]["scores"]["account_abuse"]["percentiles"]["last_7_days"]).to eq(-1.0)
651
+ end
652
+
653
+ it "Successfully fetches a v205 score with SCORE_PERCENTILES" do
654
+
655
+ api_key = "foobar"
656
+ response_json = score_response_json
657
+
658
+ stub_request(:get, "https://api.siftscience.com/v205/score/247019/?api_key=foobar&fields=SCORE_PERCENTILES")
659
+ .to_return(:status => 200, :body => MultiJson.dump(response_json),
660
+ :headers => {"content-type"=>"application/json; charset=UTF-8",
661
+ "content-length"=> "74"})
662
+
663
+ response = Sift::Client.new(:api_key => api_key)
664
+ .score(score_response_json[:user_id], :version => 205, :include_score_percentiles => "true")
665
+ expect(response.ok?).to eq(true)
666
+ expect(response.api_status).to eq(0)
667
+ expect(response.api_error_message).to eq("OK")
668
+
669
+ expect(response.body["score"]).to eq(0.93)
670
+ end
671
+
672
+ it "Successfully executes client.get_user_score() with SCORE_PERCENTILES" do
673
+
674
+ api_key = "foobar"
675
+ response_json = user_score_response_json
676
+
677
+ stub_request(:get, "https://api.siftscience.com/v205/users/247019/score?api_key=foobar&fields=SCORE_PERCENTILES")
678
+ .to_return(:status => 200, :body => MultiJson.dump(response_json),
679
+ :headers => {"content-type"=>"application/json; charset=UTF-8",
680
+ "content-length"=> "74"})
681
+
682
+ response = Sift::Client.new(:api_key => api_key)
683
+ .get_user_score(user_score_response_json[:entity_id], :include_score_percentiles => "true")
684
+ expect(response.ok?).to eq(true)
685
+ expect(response.api_status).to eq(0)
686
+ expect(response.api_error_message).to eq("OK")
687
+
688
+ expect(response.body["entity_id"]).to eq("247019")
689
+ expect(response.body["scores"]["payment_abuse"]["score"]).to eq(0.78)
690
+ end
691
+
557
692
  end
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: 4.3.0
4
+ version: 4.4.0
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: 2023-08-29 00:00:00.000000000 Z
13
+ date: 2023-10-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec