sift 1.1.7.2 → 1.1.7.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2IzYmI3MWNkNWUyNTQyY2IyMGI5OGVjYjM2YmRhYjI2N2RjOGRlNA==
4
+ ZmNiNGJmZDg2OGU5ZTEzYjNmOWJhZjAzMGNiMzZkYTE5NTVmOGFkZg==
5
5
  data.tar.gz: !binary |-
6
- NTFhYzU1MGQxYzBiNGQ1Y2ExYzFjZjEzMmM3MzRjZWE1MjUzZGJiNg==
6
+ NjJmY2FmYWQxMWEyNjFlY2MwMDdmOGZlN2ZiMWE0ODFiMGI1N2MyYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODk0NjQ2MzU5MTIzMGUzY2ZiMDMyYmM2MDc1N2U5N2ZjMmZkODMxMTg3NjBl
10
- Y2Q3ZTc3YmY1OGI0MWE4ZDQxZGNiODkyMjU1Yjg4YmZkMTgwYjg2NmI0MGVk
11
- ZDQ0M2M3Zjc3MjliZGE0NzUzNTU4YmI2OGFkNDlhYmRhNmFiYTQ=
9
+ M2FkOGQyZTM0MzdjM2FiMGVjNjU0ZDgxOTU0MjFjNjQ4NWE0NzM2ZGZkNGJi
10
+ ZjhkNmZlMzA5MGRiNGU1OWM3NGI4MzFjMDZkODE5NzQ3NDkyZGQwYmVhNzIy
11
+ NzI3ZmIzZjkzMzMyMWEwMTBmMzMxYTIwMjA0YTExN2UxZThhNDE=
12
12
  data.tar.gz: !binary |-
13
- MGJmZmYxZDgwNjZmMjQ2OTg4ZWVlZjIwZDVjNDFiOWYyYjAzNmViZTYxYWEz
14
- ZjQyNjhhZDViNzA4N2M1NzIxNmRjNGRiYjkwNzM1NTE2MDEyZGZiZGNiMzM3
15
- Y2ZlMDE0NzhmN2Q5NTg3NzRjZTYzODAyMGNiNGIyYzU4NWU0ZTQ=
13
+ ZGQ0Zjk1YTRmM2YyYzBhMjkzYzcxNzZkOWIxNTIxNTY2MzcyZmUyY2U3ZDRi
14
+ YTk1OGExNzBlZDFjNjhlZjhlOTE4NDUzOWJjNjI0Y2MwOTFmYmEwMmY1MDI0
15
+ OWU1MDQ0YzBmN2EzMmE1ZmQyMDRmNTJkNTI5Y2IzNzAwNTlmN2M=
data/HISTORY CHANGED
@@ -1,3 +1,6 @@
1
+ === 1.1.7.3 2015-08-18
2
+ * Added support for return_action
3
+
1
4
  === 1.1.7.2 2015-04-13
2
5
  * Fixed backwards compatibility issue
3
6
 
@@ -121,26 +121,34 @@ module Sift
121
121
  # Overrides the default API path with a different URL.
122
122
  #
123
123
  # return_score (optional)
124
- # Whether the API response should include a score for this user (the score will
124
+ # Whether the API response should include a score for this user. The score will
125
125
  # be calculated using the submitted event. This feature must be
126
126
  # enabled for your account in order to use it. Please contact
127
127
  # support@siftscience.com if you are interested in using this feature.
128
128
  #
129
+ # return_action (optional)
130
+ # Whether the API response should include an action triggered for this transaction.
131
+ #
129
132
  # == Returns:
130
133
  # In the case of an HTTP error (timeout, broken connection, etc.), this
131
134
  # method returns nil; otherwise, a Response object is returned and captures
132
135
  # the status message and status code. In general, you can ignore the returned
133
136
  # result, though.
134
137
  #
135
- def track(event, properties = {}, timeout = nil, path = nil, return_score = false, api_key = @api_key)
138
+ def track(event, properties = {}, timeout = nil, path = nil, return_score = false, api_key = @api_key, return_action = false)
139
+ warn "[WARNING] api_key cannot be empty, fallback to default api_key." if api_key.to_s.empty?
140
+ api_key ||= @api_key
136
141
  raise("event must be a non-empty string") if (!event.is_a? String) || event.empty?
137
142
  raise("properties cannot be empty") if properties.empty?
138
143
  raise("Bad api_key parameter") if api_key.empty?
139
144
  path ||= @path
140
145
  timeout ||= @timeout
141
- if return_score
142
- path = path + "?return_score=true"
143
- end
146
+
147
+ uri = URI.parse(API_ENDPOINT)
148
+ uri.query = URI.encode_www_form(URI.decode_www_form(uri.query.to_s) << ["return_score", "true"]) if return_score
149
+ uri.query = URI.encode_www_form(URI.decode_www_form(uri.query.to_s) << ["return_action", "true"]) if return_action
150
+ path = path + "?" + uri.query if !uri.query.to_s.empty?
151
+
144
152
  options = {
145
153
  :body => MultiJson.dump(delete_nils(properties).merge({"$type" => event,
146
154
  "$api_key" => api_key})),
@@ -207,7 +215,9 @@ module Sift
207
215
  raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
208
216
 
209
217
  path = Sift.current_users_label_api_path(user_id)
210
- track("$label", delete_nils(properties), timeout, path, false, api_key)
218
+
219
+ # No return_action logic supported when using labels.
220
+ track("$label", delete_nils(properties), timeout, path, false, api_key, false)
211
221
  end
212
222
 
213
223
  # Unlabels a user. This call is blocking.
@@ -237,6 +247,9 @@ module Sift
237
247
  end
238
248
 
239
249
  private
250
+ # def add_query_parameter(query_parameter)
251
+ # uri = URI.parse(API_ENDPOINT)
252
+ # end
240
253
  def delete_nils(properties)
241
254
  properties.delete_if do |k, v|
242
255
  case v
@@ -1,4 +1,4 @@
1
1
  module Sift
2
- VERSION = "1.1.7.2"
2
+ VERSION = "1.1.7.3"
3
3
  API_VERSION = "203"
4
4
  end
@@ -42,6 +42,41 @@ describe Sift::Client do
42
42
  }
43
43
  end
44
44
 
45
+ def action_response_json
46
+ {
47
+ :user_id => "247019",
48
+ :score => 0.93,
49
+ :actions => [{
50
+ :action_id => "1234567890abcdefghijklmn",
51
+ :time => 1437421587052,
52
+ :triggers => [{
53
+ :triggerType => "FORMULA",
54
+ :source => "synchronous_action",
55
+ :trigger_id => "12345678900987654321abcd"
56
+ }],
57
+ :entity => {
58
+ :type => "USER",
59
+ :id => "23056"
60
+ }
61
+ },
62
+ {
63
+ :action_id => "12345678901234567890abcd",
64
+ :time => 1437421587410,
65
+ :triggers => [{
66
+ :triggerType => "FORMULA",
67
+ :source => "synchronous_action",
68
+ :trigger_id => "abcd12345678901234567890"
69
+ }],
70
+ :entity => {
71
+ :type => "ORDER",
72
+ :id => "order_at_ 1437421587009"
73
+ }
74
+ }],
75
+ :status => 0,
76
+ :error_message => "OK"
77
+ }
78
+ end
79
+
45
80
  def fully_qualified_api_endpoint
46
81
  Sift::Client::API_ENDPOINT + Sift.current_rest_api_path
47
82
  end
@@ -58,17 +93,17 @@ describe Sift::Client do
58
93
  end
59
94
 
60
95
  it "Cannot instantiate client with nil, empty, non-string, or blank api key" do
61
- expect(lambda { Sift::Client.new(nil) }).to raise_error
62
- expect(lambda { Sift::Client.new("") }).to raise_error
63
- expect(lambda { Sift::Client.new(123456) }).to raise_error
64
- expect(lambda { Sift::Client.new() }).to raise_error
96
+ expect(lambda { Sift::Client.new(nil) }).to raise_error(StandardError)
97
+ expect(lambda { Sift::Client.new("") }).to raise_error(StandardError)
98
+ expect(lambda { Sift::Client.new(123456) }).to raise_error(StandardError)
99
+ expect(lambda { Sift::Client.new() }).to raise_error(StandardError)
65
100
  end
66
101
 
67
102
  it "Cannot instantiate client with nil, empty, non-string, or blank path" do
68
103
  api_key = "test_local_api_key"
69
- expect(lambda { Sift::Client.new(api_key, nil) }).to raise_error
70
- expect(lambda { Sift::Client.new(api_key, "") }).to raise_error
71
- expect(lambda { Sift::Client.new(api_key, 123456) }).to raise_error
104
+ expect(lambda { Sift::Client.new(api_key, nil) }).to raise_error(StandardError)
105
+ expect(lambda { Sift::Client.new(api_key, "") }).to raise_error(StandardError)
106
+ expect(lambda { Sift::Client.new(api_key, 123456) }).to raise_error(StandardError)
72
107
  end
73
108
 
74
109
  it "Can instantiate client with non-default timeout" do
@@ -76,23 +111,23 @@ describe Sift::Client do
76
111
  end
77
112
 
78
113
  it "Track call must specify an event name" do
79
- expect(lambda { Sift::Client.new("foo").track(nil) }).to raise_error
80
- expect(lambda { Sift::Client.new("foo").track("") }).to raise_error
114
+ expect(lambda { Sift::Client.new("foo").track(nil) }).to raise_error(StandardError)
115
+ expect(lambda { Sift::Client.new("foo").track("") }).to raise_error(StandardError)
81
116
  end
82
117
 
83
118
  it "Must specify an event name" do
84
- expect(lambda { Sift::Client.new("foo").track(nil) }).to raise_error
85
- expect(lambda { Sift::Client.new("foo").track("") }).to raise_error
119
+ expect(lambda { Sift::Client.new("foo").track(nil) }).to raise_error(StandardError)
120
+ expect(lambda { Sift::Client.new("foo").track("") }).to raise_error(StandardError)
86
121
  end
87
122
 
88
123
  it "Must specify properties" do
89
124
  event = "custom_event_name"
90
- expect(lambda { Sift::Client.new("foo").track(event) }).to raise_error
125
+ expect(lambda { Sift::Client.new("foo").track(event) }).to raise_error(StandardError)
91
126
  end
92
127
 
93
128
  it "Score call must specify a user_id" do
94
- expect(lambda { Sift::Client.new("foo").score(nil) }).to raise_error
95
- expect(lambda { Sift::Client.new("foo").score("") }).to raise_error
129
+ expect(lambda { Sift::Client.new("foo").score(nil) }).to raise_error(StandardError)
130
+ expect(lambda { Sift::Client.new("foo").score("") }).to raise_error(StandardError)
96
131
  end
97
132
 
98
133
  it "Doesn't raise an exception on Net/HTTP errors" do
@@ -141,7 +176,7 @@ describe Sift::Client do
141
176
  expect(response.api_error_message).to eq("OK")
142
177
  end
143
178
 
144
- it "Successfully submits event with overriden key" do
179
+ it "Successfully submits event with overridden key" do
145
180
  response_json = { :status => 0, :error_message => "OK"}
146
181
  stub_request(:post, "https://api.siftscience.com/v203/events").
147
182
  with { | request|
@@ -154,7 +189,7 @@ describe Sift::Client do
154
189
  event = "$transaction"
155
190
  properties = valid_transaction_properties
156
191
 
157
- response = Sift::Client.new(api_key).track(event, properties, nil, nil, false, "overridden")
192
+ response = Sift::Client.new(api_key).track(event, properties, nil, nil, false, "overridden", false)
158
193
  expect(response.ok?).to eq(true)
159
194
  expect(response.api_status).to eq(0)
160
195
  expect(response.api_error_message).to eq("OK")
@@ -233,13 +268,34 @@ describe Sift::Client do
233
268
 
234
269
  event = "$transaction"
235
270
  properties = valid_transaction_properties
236
- response = Sift::Client.new(api_key).track(event, properties, nil, nil, true)
271
+ response = Sift::Client.new(api_key).track(event, properties, nil, nil, true, nil, nil)
237
272
  expect(response.ok?).to eq(true)
238
273
  expect(response.api_status).to eq(0)
239
274
  expect(response.api_error_message).to eq("OK")
240
275
  expect(response.body["score_response"]["score"]).to eq(0.93)
241
276
  end
242
277
 
278
+ it "Successfuly make a sync action request" do
279
+
280
+ api_key = "foobar"
281
+ response_json = {
282
+ :status => 0,
283
+ :error_message => "OK",
284
+ :score_response => action_response_json
285
+ }
286
+
287
+ stub_request(:post, "https://api.siftscience.com/v203/events?return_action=true").
288
+ to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {"content-type"=>"application/json; charset=UTF-8","content-length"=> "74"})
289
+
290
+ event = "$transaction"
291
+ properties = valid_transaction_properties
292
+ response = Sift::Client.new(api_key).track(event, properties, nil, nil, nil, nil, true)
293
+ expect(response.ok?).to eq(true)
294
+ expect(response.api_status).to eq(0)
295
+ expect(response.api_error_message).to eq("OK")
296
+ expect(response.body["score_response"]["actions"].first["entity"]["type"]).to eq("USER")
297
+ end
298
+
243
299
 
244
300
 
245
301
  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: 1.1.7.2
4
+ version: 1.1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Sadaghiani
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-13 00:00:00.000000000 Z
12
+ date: 2015-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec