sift 1.1.6.0 → 1.1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzY5Mjg2YTQ4ZjRmYWRlOTQ4NTk4NzFmNjNiZjFmYmE3NTg3MDM2MQ==
4
+ MzdkOThmNmZiYWRmMDI3ODgyYjI4MjYyMjc2ZDg1YjhkOTdlNGU0MQ==
5
5
  data.tar.gz: !binary |-
6
- ZGIzOTAwOWE4OTExMWQ0MzlkYTRiYjk4OTQzNmU0NzQ5YWVkMzg3OQ==
6
+ N2RiZGI4ZTFlZWI1YjBkNDQ1MDQyM2MxYTNmMDNlMzUxZjMyZDM1OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTM1ZTM3ZGU3ODI4ZmE5YzdiMTQ4ZWMxODUxZDhjZTAzZmZiYTAzMGZjMzZk
10
- YzYxZjI5MDk1MjQ4ZWI1NDFhNWI1ODY2Y2MyYjk1MTI3YTA4ZjdmZjhjOTNl
11
- NTc0ZGYzYzM5NmI0N2ZiM2JmMzgzMDg5M2ZhZWIwYjQwNWY1MGQ=
9
+ M2YzZTYyZmJhMzBjMDVmZmJiNWM5N2ZmNmJmNjkzOTMzN2ExODIxMTIwOGRh
10
+ OTBmYThlZDA1ZDVmMDYzZTI4MjIxZDcxYTFjYjZhMzc0MzlkYjk1ZThhZTMy
11
+ YjhlNGUwMzEwOTI2MjhlNGI5ODYwZTJmYmRkNGI4YzlkM2IzYTE=
12
12
  data.tar.gz: !binary |-
13
- NzlhNGRiODU4M2UzNWQzZGRkM2U2OGM4MTk5MWVkZmE4ZjQ1YmJkYzcxZjI2
14
- OWY1OGI5OWRjMzA4ODM1YWVkZGE4MGVhMzBhMjRkNDg3M2ZlMzNhY2M0YTQ4
15
- OWJkNjkwN2EzNzIyOTRjMGNhOGNjNzIyMWYzNDdmN2Y3OWQ4ZTE=
13
+ NGVjMmZjYTJiOWI0NDA4N2Y5NjU3NGNkNDk1NTNjMDdhZGQ3NGZmNDEwNTYw
14
+ MTVmZGQ5ZDQ4NTY4ZmEyMTkwNjYwZDFhMTBmZDgwNDNiYWVjMWUyZWE0OTk1
15
+ NThlNTY5N2M2ZDAyZTBkMWI5Mjg4YzVhMmM2M2MyZDU5YjU1MDE=
data/lib/sift/client.rb CHANGED
@@ -76,7 +76,7 @@ module Sift
76
76
  @path = path
77
77
  @timeout = timeout
78
78
 
79
-
79
+
80
80
  end
81
81
 
82
82
  def api_key
@@ -108,7 +108,7 @@ module Sift
108
108
  # Overrides the default API path with a different URL.
109
109
  #
110
110
  # return_score (optional)
111
- # Whether the API response should include a score for this user (the score will
111
+ # Whether the API response should include a score for this user (the score will
112
112
  # be calculated using the submitted event
113
113
  #
114
114
  # == Returns:
@@ -117,9 +117,10 @@ module Sift
117
117
  # the status message and status code. In general, you can ignore the returned
118
118
  # result, though.
119
119
  #
120
- def track(event, properties = {}, timeout = nil, path = nil, return_score = false)
120
+ def track(event, properties = {}, timeout = nil, path = nil, return_score = false, api_key = @api_key)
121
121
  raise(RuntimeError, "event must be a non-empty string") if (!event.is_a? String) || event.empty?
122
122
  raise(RuntimeError, "properties cannot be empty") if properties.empty?
123
+ raise(RuntimeError, "Bad api_key parameter") if api_key.empty?
123
124
  path ||= @path
124
125
  timeout ||= @timeout
125
126
  if return_score
@@ -127,7 +128,7 @@ module Sift
127
128
  end
128
129
  options = {
129
130
  :body => MultiJson.dump(delete_nils(properties).merge({"$type" => event,
130
- "$api_key" => @api_key})),
131
+ "$api_key" => api_key})),
131
132
  :headers => {"User-Agent" => user_agent}
132
133
  }
133
134
  options.merge!(:timeout => timeout) unless timeout.nil?
@@ -153,15 +154,16 @@ module Sift
153
154
  # A Response object is returned and captures the status message and
154
155
  # status code. In general, you can ignore the returned result, though.
155
156
  #
156
- def score(user_id, timeout = nil)
157
+ def score(user_id, timeout = nil, api_key = @api_key)
157
158
 
158
159
  raise(RuntimeError, "user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
160
+ raise(RuntimeError, "Bad api_key parameter") if api_key.empty?
159
161
  timetout ||= @timeout
160
162
 
161
163
  options = { :headers => {"User-Agent" => user_agent} }
162
164
  options.merge!(:timeout => timeout) unless timeout.nil?
163
165
 
164
- response = self.class.get("/v#{API_VERSION}/score/#{user_id}/?api_key=#{@api_key}", options)
166
+ response = self.class.get("/v#{API_VERSION}/score/#{user_id}/?api_key=#{api_key}", options)
165
167
  Response.new(response.body, response.code)
166
168
 
167
169
  end
@@ -185,12 +187,12 @@ module Sift
185
187
  # A Response object is returned and captures the status message and
186
188
  # status code. In general, you can ignore the returned result, though.
187
189
  #
188
- def label(user_id, properties = {}, timeout = nil)
190
+ def label(user_id, properties = {}, timeout = nil, api_key = @api_key)
189
191
 
190
192
  raise(RuntimeError, "user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
191
193
 
192
194
  path = Sift.current_users_label_api_path(user_id)
193
- track("$label", delete_nils(properties), timeout, path)
195
+ track("$label", delete_nils(properties), timeout, path, false, api_key)
194
196
  end
195
197
 
196
198
  private
data/lib/sift/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Sift
2
- VERSION = "1.1.6.0"
2
+ VERSION = "1.1.6.2"
3
3
  API_VERSION = "203"
4
4
  end
@@ -141,6 +141,25 @@ describe Sift::Client do
141
141
  response.api_error_message.should eq("OK")
142
142
  end
143
143
 
144
+ it "Successfully submits event with overriden key" do
145
+ response_json = { :status => 0, :error_message => "OK"}
146
+ stub_request(:post, "https://api.siftscience.com/v203/events").
147
+ with { | request|
148
+ parsed_body = JSON.parse(request.body)
149
+ parsed_body.should include("$buyer_user_id" => "123456")
150
+ parsed_body.should include("$api_key" => "overridden")
151
+ }.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
152
+
153
+ api_key = "foobar"
154
+ event = "$transaction"
155
+ properties = valid_transaction_properties
156
+
157
+ response = Sift::Client.new(api_key).track(event, properties, nil, nil, false, "overridden")
158
+ response.ok?.should eq(true)
159
+ response.api_status.should eq(0)
160
+ response.api_error_message.should eq("OK")
161
+ end
162
+
144
163
  it "Successfuly scrubs nils" do
145
164
 
146
165
  response_json = { :status => 0, :error_message => "OK" }
@@ -183,6 +202,23 @@ describe Sift::Client do
183
202
  response.body["score"].should eq(0.93)
184
203
  end
185
204
 
205
+ it "Successfully fetches a score with an overridden key" do
206
+
207
+ api_key = "foobar"
208
+ response_json = score_response_json
209
+
210
+ stub_request(:get, "https://api.siftscience.com/v203/score/247019/?api_key=overridden").
211
+ to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
212
+
213
+ response = Sift::Client.new(api_key).score(score_response_json[:user_id], nil, "overridden")
214
+ response.ok?.should eq(true)
215
+ response.api_status.should eq(0)
216
+ response.api_error_message.should eq("OK")
217
+
218
+ response.body["score"].should eq(0.93)
219
+ end
220
+
221
+
186
222
  it "Successfuly make a sync score request" do
187
223
 
188
224
  api_key = "foobar"
@@ -204,4 +240,6 @@ describe Sift::Client do
204
240
  response.body["score_response"]["score"].should eq(0.93)
205
241
  end
206
242
 
243
+
244
+
207
245
  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.6.0
4
+ version: 1.1.6.2
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: 2014-09-03 00:00:00.000000000 Z
12
+ date: 2014-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project: sift
127
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.1.11
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Sift Science Ruby API Gem