sift-partner 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/README.rdoc +5 -1
- data/lib/sift-partner/client.rb +12 -18
- data/lib/sift-partner/version.rb +1 -1
- data/spec/unit/client_spec.rb +12 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2d6e43fd51d8c0df7c790eab160fe1969e38253
|
4
|
+
data.tar.gz: 74fdbd96633de36d12939060d1320e0ed62db110
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb725dad6b444eae3f07b2a5fe32d7b4677ccf189590bda29d671af7e299138aa8b9078dab277c31d2b4d87f7c0d53bbc47e49a2034817a8ad124e432185bce4
|
7
|
+
data.tar.gz: 4652e9dcd314c57c8bb1552453cf37aea7dd20f0871cc771ffb7ff08e39e98627a9ec45c77556df345e094c9f650e5baabb0584115ce3c9617a390eef32ad984
|
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -31,13 +31,17 @@ Alternatively, you can install the gem from Rubyforge:
|
|
31
31
|
partner_client = SiftPartner::Client.new(partner_api_key, partner_acct_id)
|
32
32
|
|
33
33
|
# create a new account for a given merchant
|
34
|
-
|
34
|
+
merchant_account_response = partner_client.new_account(
|
35
35
|
"merchantsite.com", # the url for the merchant's site
|
36
36
|
"shopowner@merchantsite.com", # an email belonging to the merchant
|
37
37
|
"johndoe@merchantsite.com", # an email used to log in to Sift
|
38
38
|
"s0m3l0ngp455w0rd" # password associated with that log in
|
39
39
|
)
|
40
40
|
|
41
|
+
merchant_account_response.ok? # returns true or false
|
42
|
+
merchant_account_response.body # API response body
|
43
|
+
merchant_account_response.http_status_code # HTTP response code, 200 is ok.
|
44
|
+
|
41
45
|
# get a listing of all your accounts
|
42
46
|
all_accounts = partner_client.get_accounts
|
43
47
|
|
data/lib/sift-partner/client.rb
CHANGED
@@ -39,8 +39,7 @@ module SiftPartner
|
|
39
39
|
# password
|
40
40
|
# password (at least 10 chars) to be used to sign into the Console
|
41
41
|
#
|
42
|
-
#
|
43
|
-
# When an error occurs, returns nil.
|
42
|
+
# Returns a Sift::Response object (see https://github.com/SiftScience/sift-ruby)
|
44
43
|
def new_account(site_url, site_email, analyst_email, password)
|
45
44
|
|
46
45
|
raise("site url must be a non-empty string") unless valid_string?(site_url)
|
@@ -63,11 +62,12 @@ module SiftPartner
|
|
63
62
|
# been created by this partner. This will return up to 100 results
|
64
63
|
# at a time.
|
65
64
|
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
65
|
+
# Returns a Sift::Response object (see https://github.com/SiftScience/sift-ruby)
|
66
|
+
# When successful, the response body is a hash including the key :data,
|
67
|
+
# which is an array of account descriptions. (Each element has the same
|
68
|
+
# structure as a single response from new_account.) If
|
69
|
+
# the key :has_more is true, then pass the :next_ref value into this
|
70
|
+
# function again to get the next set of results.
|
71
71
|
def get_accounts(next_ref = nil)
|
72
72
|
http_get(next_ref ? next_ref : accounts_url)
|
73
73
|
end
|
@@ -80,7 +80,7 @@ module SiftPartner
|
|
80
80
|
# A Hash, with keys :http_notification_url and :http_notification_threshold
|
81
81
|
# The value of the notification_url will be a url containing the string '%s' exactly once.
|
82
82
|
# This allows the url to be used as a template, into which a merchant account id can be substituted.
|
83
|
-
# The
|
83
|
+
# The notification threshold should be a floating point number between 0.0 and 1.0
|
84
84
|
def update_notification_config(cfg = nil)
|
85
85
|
|
86
86
|
raise("configuration must be a hash") unless cfg.is_a? Hash
|
@@ -101,18 +101,12 @@ module SiftPartner
|
|
101
101
|
URI("#{API_ENDPOINT}/accounts/#{@id}/config")
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
104
|
+
def sift_response(http_response)
|
105
105
|
response = Sift::Response.new(
|
106
106
|
http_response.body,
|
107
107
|
http_response.code,
|
108
108
|
http_response.response
|
109
109
|
)
|
110
|
-
if !response.nil? and response.ok?
|
111
|
-
response.json
|
112
|
-
else
|
113
|
-
puts "bad value in safeJson :"
|
114
|
-
PP.pp(response)
|
115
|
-
end
|
116
110
|
end
|
117
111
|
|
118
112
|
def prep_https(uri)
|
@@ -126,7 +120,7 @@ module SiftPartner
|
|
126
120
|
"User-Agent" => user_agent}
|
127
121
|
|
128
122
|
http_response = HTTParty.get(uri, :headers =>header)
|
129
|
-
|
123
|
+
sift_response(http_response)
|
130
124
|
end
|
131
125
|
|
132
126
|
def http_put(uri, bodyObj)
|
@@ -135,7 +129,7 @@ module SiftPartner
|
|
135
129
|
"User-Agent" => user_agent}
|
136
130
|
|
137
131
|
http_response = HTTParty.put(uri, :body => bodyObj.to_json, :headers => header)
|
138
|
-
|
132
|
+
sift_response(http_response)
|
139
133
|
end
|
140
134
|
|
141
135
|
def http_post(uri, bodyObj)
|
@@ -143,7 +137,7 @@ module SiftPartner
|
|
143
137
|
"Authorization" => "Basic #{@api_key}",
|
144
138
|
"User-Agent" => user_agent}
|
145
139
|
http_response = HTTParty.post(uri, :body => bodyObj.to_json, :headers => header)
|
146
|
-
|
140
|
+
sift_response(http_response)
|
147
141
|
end
|
148
142
|
|
149
143
|
def valid_string?(s)
|
data/lib/sift-partner/version.rb
CHANGED
data/spec/unit/client_spec.rb
CHANGED
@@ -119,8 +119,8 @@ describe SiftPartner::Client do
|
|
119
119
|
response = partner_client.new_account(site_url, site_email, analyst_email,
|
120
120
|
password)
|
121
121
|
response.should_not be_nil
|
122
|
-
response["production"]["api_keys"][0]["state"].should eq("ACTIVE")
|
123
|
-
|
122
|
+
response.body["production"]["api_keys"][0]["state"].should eq("ACTIVE")
|
123
|
+
end
|
124
124
|
|
125
125
|
it "should march through account listing flow" do
|
126
126
|
stub_request(:get, /https:\/\/.*partner\.siftscience\.com\/v3\/partners\/#{partner_id}\/accounts\z/).
|
@@ -147,16 +147,16 @@ describe SiftPartner::Client do
|
|
147
147
|
partner_client = SiftPartner::Client.new(partner_api_key, partner_id)
|
148
148
|
response = partner_client.get_accounts()
|
149
149
|
response.should_not be_nil
|
150
|
-
response["nextRef"].should_not be_nil
|
151
|
-
response["hasMore"].should be_truthy
|
152
|
-
response["totalResults"].should eq(2)
|
153
|
-
next_ref = response["nextRef"]
|
150
|
+
response.body["nextRef"].should_not be_nil
|
151
|
+
response.body["hasMore"].should be_truthy
|
152
|
+
response.body["totalResults"].should eq(2)
|
153
|
+
next_ref = response.body["nextRef"]
|
154
154
|
|
155
155
|
response = partner_client.get_accounts(next_ref)
|
156
156
|
response.should_not be_nil
|
157
|
-
response["hasMore"].should be_falsey
|
158
|
-
response["nextRef"].should be_nil
|
159
|
-
response["totalResults"].should eq(2)
|
157
|
+
response.body["hasMore"].should be_falsey
|
158
|
+
response.body["nextRef"].should be_nil
|
159
|
+
response.body["totalResults"].should eq(2)
|
160
160
|
end
|
161
161
|
|
162
162
|
|
@@ -190,10 +190,9 @@ describe SiftPartner::Client do
|
|
190
190
|
response = partner_client.update_notification_config(cfg)
|
191
191
|
response.should_not be_nil
|
192
192
|
epsilon = 1e-6
|
193
|
-
response["http_notification_url"].should eq(cfg["http_notification_url"])
|
194
|
-
response["http_notification_threshold"].should < cfg["http_notification_threshold"] + epsilon
|
195
|
-
response["http_notification_threshold"].should > cfg["http_notification_threshold"] - epsilon
|
196
|
-
|
193
|
+
response.body["http_notification_url"].should eq(cfg["http_notification_url"])
|
194
|
+
response.body["http_notification_threshold"].should < cfg["http_notification_threshold"] + epsilon
|
195
|
+
response.body["http_notification_threshold"].should > cfg["http_notification_threshold"] - epsilon
|
197
196
|
end
|
198
197
|
|
199
198
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sift-partner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Beppu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|