sift 1.0.5 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,5 +37,4 @@ Building and publishing the gem is captured by the following steps:
37
37
 
38
38
  To run the various tests use the rake command as follows:
39
39
 
40
- $ rake spec:unit
41
- $ rake spec:integration
40
+ $ rake spec
data/Rakefile CHANGED
@@ -6,9 +6,9 @@ rescue LoadError => e
6
6
  end
7
7
 
8
8
  require "rspec/core/rake_task"
9
+ task :default => :spec
9
10
 
10
11
  desc "Run tests"
11
- RSpec::Core::RakeTask.new(:spec)
12
-
13
- task :default => :spec
14
- task :test => :spec
12
+ RSpec::Core::RakeTask.new(:spec) do |t|
13
+ t.pattern = "./spec/**/*_spec.rb"
14
+ end
data/lib/sift/client.rb CHANGED
@@ -17,7 +17,7 @@ module Sift
17
17
  # == Parameters:
18
18
  # http_response
19
19
  # The HTTP body text returned from the API call. The body is expected to be
20
- # a JSON object that can be decoded into status, message and request
20
+ # a JSON object that can be decoded into status, message and request
21
21
  # sections.
22
22
  #
23
23
  def initialize(http_response, http_response_code)
@@ -92,7 +92,7 @@ module Sift
92
92
  raise(RuntimeError, "properties cannot be empty") if properties.empty?
93
93
 
94
94
  options = {
95
- :body => MultiJson.dump(properties.merge({"$type" => event,
95
+ :body => MultiJson.dump(properties.merge({"$type" => event,
96
96
  "$api_key" => @api_key})),
97
97
  }
98
98
  options.merge!(:timeout => timeout) unless timeout.nil?
@@ -104,5 +104,27 @@ module Sift
104
104
  Sift.warn(e.backtrace)
105
105
  end
106
106
  end
107
+
108
+ # Retrieves a user's fraud score from the Sift Science API. This call
109
+ # is blocking.
110
+ #
111
+ # == Parameters:
112
+ # user_id
113
+ # A user's id. This id should be the same as the user_id used in
114
+ # event calls.
115
+ #
116
+ # == Returns:
117
+ # A Response object is returned and captures
118
+ # the status message and status code. In general, you can ignore the returned
119
+ # result, though.
120
+ #
121
+ def score(user_id)
122
+
123
+ raise(RuntimeError, "user_id must be a string") if user_id.nil? || user_id.to_s.empty?
124
+
125
+ response = self.class.get('/v203/score/'+user_id)
126
+ Response.new(response.body, response.code)
127
+
128
+ end
107
129
  end
108
130
  end
data/lib/sift/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sift
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.12"
3
3
  end
data/sift.gemspec CHANGED
@@ -24,6 +24,9 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "fakeweb", "~> 1.3.0"
25
25
 
26
26
  # Gems that must be intalled for sift to work
27
- s.add_dependency "httparty", ">= 0.8.3"
27
+ s.add_dependency "httparty", ">= 0.10.0"
28
28
  s.add_dependency "multi_json", ">= 1.3.4"
29
+
30
+ s.add_development_dependency("rspec", ">= 2.0")
31
+ s.add_development_dependency("rake")
29
32
  end
@@ -46,6 +46,12 @@ describe Sift::Client do
46
46
  lambda { Sift::Client.new("foo").track(event) }.should raise_error
47
47
  end
48
48
 
49
+ it "Score call must specify a user_id" do
50
+ lambda { Sift::Client.new("foo").score(nil) }.should raise_error
51
+ lambda { Sift::Client.new("foo").score("") }.should raise_error
52
+ end
53
+
54
+
49
55
  it "Doesn't raise an exception on Net/HTTP errors" do
50
56
 
51
57
  FakeWeb.register_uri(:post, fully_qualified_api_endpoint,
@@ -79,4 +85,36 @@ describe Sift::Client do
79
85
  response.api_error_message.should eq("OK")
80
86
  end
81
87
 
88
+ it "Successfully fetches a score" do
89
+
90
+ api_key = "foobar"
91
+ user_id = "247019"
92
+
93
+ response_json = {
94
+ :user_id => user_id,
95
+ :score => 0.93,
96
+ :reasons => [{
97
+ :name => "UsersPerDevice",
98
+ :value => 4,
99
+ :details => {
100
+ :users => "a, b, c, d"
101
+ }
102
+ }],
103
+ :status => 0,
104
+ :error_message => "OK"
105
+ }
106
+
107
+ FakeWeb.register_uri(:get, Sift::Client::API_ENDPOINT + '/v203/score/'+user_id,
108
+ :body => MultiJson.dump(response_json),
109
+ :status => [Net::HTTPOK, "OK"],
110
+ :content_type => "text/json")
111
+
112
+ response = Sift::Client.new(api_key).score(user_id)
113
+ response.ok?.should eq(true)
114
+ response.api_status.should eq(0)
115
+ response.api_error_message.should eq("OK")
116
+
117
+ response.json["score"].should eq(0.93)
118
+ end
119
+
82
120
  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.0.5
4
+ version: 1.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70093902351140 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 2.9.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70093902351140
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.9.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: fakeweb
27
- requirement: &70093902438840 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,21 +37,31 @@ dependencies:
32
37
  version: 1.3.0
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70093902438840
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.0
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: httparty
38
- requirement: &70093902565360 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
42
52
  - !ruby/object:Gem::Version
43
- version: 0.8.3
53
+ version: 0.10.0
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70093902565360
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: multi_json
49
- requirement: &70093902656720 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,7 +69,44 @@ dependencies:
54
69
  version: 1.3.4
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *70093902656720
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.3.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '2.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '2.0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
58
110
  description: Sift Science Ruby API. Please see http://siftscience.com for more details.
59
111
  email:
60
112
  - freds@siftscience.com
@@ -88,15 +140,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
140
  - - ! '>='
89
141
  - !ruby/object:Gem::Version
90
142
  version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 2652595894011283965
91
146
  required_rubygems_version: !ruby/object:Gem::Requirement
92
147
  none: false
93
148
  requirements:
94
149
  - - ! '>='
95
150
  - !ruby/object:Gem::Version
96
151
  version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 2652595894011283965
97
155
  requirements: []
98
156
  rubyforge_project: sift
99
- rubygems_version: 1.8.10
157
+ rubygems_version: 1.8.25
100
158
  signing_key:
101
159
  specification_version: 3
102
160
  summary: Sift Science Ruby API Gem