sift 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ script: "bundle exec rake spec"
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ env:
7
+ # None for now
8
+ gemfile:
9
+ - Gemfile
10
+ services:
11
+ # None for now
12
+ notifications:
13
+ # None for now
data/lib/sift/client.rb CHANGED
@@ -97,8 +97,8 @@ module Sift
97
97
 
98
98
  path ||= @path
99
99
  options = {
100
- :body => MultiJson.dump(properties.merge({"$type" => event,
101
- "$api_key" => @api_key})),
100
+ :body => MultiJson.dump(delete_nils(properties).merge({"$type" => event,
101
+ "$api_key" => @api_key}))
102
102
  }
103
103
  options.merge!(:timeout => timeout) unless timeout.nil?
104
104
  begin
@@ -155,7 +155,22 @@ module Sift
155
155
  raise(RuntimeError, "user_id must be a string") if user_id.nil? || user_id.to_s.empty?
156
156
 
157
157
  path = Sift.current_users_label_api_path(user_id)
158
- track("$label", properties, timeout, path)
158
+ track("$label", delete_nils(properties), timeout, path)
159
+ end
160
+
161
+ private
162
+ def delete_nils(properties)
163
+ properties.delete_if do |k, v|
164
+ case v
165
+ when nil
166
+ true
167
+ when Hash
168
+ delete_nils(v)
169
+ false
170
+ else
171
+ false
172
+ end
173
+ end
159
174
  end
160
175
  end
161
176
  end
data/lib/sift/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sift
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
data/sift.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gems that must be intalled for sift to compile and build
23
23
  s.add_development_dependency "rspec", "~> 2.14.1"
24
- s.add_development_dependency "fakeweb", "~> 1.3.0"
24
+ s.add_development_dependency "webmock", "~> 1.16.0"
25
25
 
26
26
  # Gems that must be intalled for sift to work
27
27
  s.add_dependency "httparty", ">= 0.11.0"
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
 
2
2
  require "bundler/setup"
3
3
  require "sift"
4
- require "fakeweb"
4
+ require "webmock/rspec"
5
5
 
6
6
  # Setup Fakeweb
7
- FakeWeb.allow_net_connect = false
7
+ WebMock.disable_net_connect!
8
8
 
9
9
  RSpec.configure do |config|
10
10
  end
@@ -19,10 +19,9 @@ describe Sift::Client do
19
19
  response_json = { :status => 0, :error_message => "OK" }
20
20
  user_id = "frodo_baggins"
21
21
 
22
- FakeWeb.register_uri(:post, fully_qualified_users_labels_endpoint(user_id),
23
- :body => MultiJson.dump(response_json),
24
- :status => [Net::HTTPOK, "OK"],
25
- :content_type => "text/json")
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, :content_type => "text/json")
26
25
 
27
26
  api_key = "foobar"
28
27
  properties = valid_label_properties
@@ -18,7 +18,7 @@ describe Sift::Client do
18
18
  :$billing_region => "CA",
19
19
  :$billing_country => "US",
20
20
  :$billing_zip => "94131",
21
- :$buyer_email => "mike@example.com"
21
+ :$user_email => "mike@example.com"
22
22
  }
23
23
  end
24
24
 
@@ -54,13 +54,13 @@ describe Sift::Client do
54
54
 
55
55
  it "Doesn't raise an exception on Net/HTTP errors" do
56
56
 
57
- FakeWeb.register_uri(:post, fully_qualified_api_endpoint,
58
- :body => nil, :exception => Net::HTTPError)
59
57
 
60
58
  api_key = "foobar"
61
59
  event = "$transaction"
62
60
  properties = valid_transaction_properties
63
61
 
62
+ stub_request(:any, /.*/).to_return(:status => 401)
63
+
64
64
  # This method should just return false -- the track call failed because
65
65
  # of an HTTP error
66
66
  Sift::Client.new(api_key).track(event, properties).should eq(nil)
@@ -70,10 +70,11 @@ describe Sift::Client do
70
70
 
71
71
  response_json = { :status => 0, :error_message => "OK" }
72
72
 
73
- FakeWeb.register_uri(:post, fully_qualified_api_endpoint,
74
- :body => MultiJson.dump(response_json),
75
- :status => [Net::HTTPOK, "OK"],
76
- :content_type => "text/json")
73
+ stub_request(:post, "https://api.siftscience.com/v203/events").
74
+ with { |request|
75
+ parsed_body = JSON.parse(request.body)
76
+ parsed_body.should include("$buyer_user_id" => "123456")
77
+ }.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
77
78
 
78
79
  api_key = "foobar"
79
80
  event = "$transaction"
@@ -85,6 +86,32 @@ describe Sift::Client do
85
86
  response.api_error_message.should eq("OK")
86
87
  end
87
88
 
89
+ it "Successfuly scrubs nils" do
90
+
91
+ response_json = { :status => 0, :error_message => "OK" }
92
+
93
+ stub_request(:post, "https://api.siftscience.com/v203/events").
94
+ with { |request|
95
+ parsed_body = JSON.parse(request.body)
96
+ parsed_body.should_not include("fake_property")
97
+ parsed_body.should include("sub_object" => {"one" => "two"})
98
+ }.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
99
+
100
+ api_key = "foobar"
101
+ event = "$transaction"
102
+ properties = valid_transaction_properties.merge(
103
+ "fake_property" => nil,
104
+ "sub_object" => {
105
+ "one" => "two",
106
+ "three" => nil
107
+ }
108
+ )
109
+ response = Sift::Client.new(api_key).track(event, properties)
110
+ response.ok?.should eq(true)
111
+ response.api_status.should eq(0)
112
+ response.api_error_message.should eq("OK")
113
+ end
114
+
88
115
  it "Successfully fetches a score" do
89
116
 
90
117
  api_key = "foobar"
@@ -104,10 +131,8 @@ describe Sift::Client do
104
131
  :error_message => "OK"
105
132
  }
106
133
 
107
- FakeWeb.register_uri(:get, Sift::Client::API_ENDPOINT + '/v203/score/'+user_id+'/?api_key=foobar',
108
- :body => MultiJson.dump(response_json),
109
- :status => [Net::HTTPOK, "OK"],
110
- :content_type => "text/json")
134
+ stub_request(:get, "https://api.siftscience.com/v203/score/247019/?api_key=foobar").
135
+ to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
111
136
 
112
137
  response = Sift::Client.new(api_key).score(user_id)
113
138
  response.ok?.should eq(true)
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.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-03 00:00:00.000000000 Z
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -28,13 +28,13 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.14.1
30
30
  - !ruby/object:Gem::Dependency
31
- name: fakeweb
31
+ name: webmock
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.3.0
37
+ version: 1.16.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 1.3.0
45
+ version: 1.16.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: httparty
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,7 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - .gitignore
118
+ - .travis.yml
118
119
  - Gemfile
119
120
  - HISTORY
120
121
  - README.rdoc