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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7987ee5a58921058cdbb5c708746f0eda484d770
4
- data.tar.gz: a061b87759f04a37665174eb55a73423fb1fc178
3
+ metadata.gz: f2d6e43fd51d8c0df7c790eab160fe1969e38253
4
+ data.tar.gz: 74fdbd96633de36d12939060d1320e0ed62db110
5
5
  SHA512:
6
- metadata.gz: e0b58bb159cb059d76f28d14d0a0a683620016a387917a70cd9f79f6bb3ab665e34f972178aec977b42a0f91e0f6adf91d52c286f012a95f37e6e7e6972539d8
7
- data.tar.gz: c80cd09c8a11e70a7ce0421ed4ff001fdc0575475400bc4aec1cd2dd7c0a98c07bf39e59bf28d9487f4c856125140bc22dcc3ca448010536fb736e3180741737
6
+ metadata.gz: cb725dad6b444eae3f07b2a5fe32d7b4677ccf189590bda29d671af7e299138aa8b9078dab277c31d2b4d87f7c0d53bbc47e49a2034817a8ad124e432185bce4
7
+ data.tar.gz: 4652e9dcd314c57c8bb1552453cf37aea7dd20f0871cc771ffb7ff08e39e98627a9ec45c77556df345e094c9f650e5baabb0584115ce3c9617a390eef32ad984
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sift-partner (0.0.3)
4
+ sift-partner (0.1.0)
5
5
  httparty (~> 0.13.1)
6
6
  multi_json (~> 1.0)
7
7
  sift (~> 1.1.7)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Sift Science
1
+ Copyright (c) 2014-2016 Sift Science
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -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
- merchant_account = partner_client.new_account(
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
 
@@ -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
- # When successful, returns a including the new account id and credentials.
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
- # When successful, returns a hash including the key :data, which is an
67
- # array of account descriptions. (Each element has the same structure as a
68
- # single response from new_account). If the key :has_more is true, then
69
- # pass the :next_ref value into this function again to get the next set
70
- # of results.
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 notification threshold should be a floating point number between 0.0 and 1.0
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 safe_json(http_response)
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
- safe_json(http_response)
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
- safe_json(http_response)
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
- safe_json(http_response)
140
+ sift_response(http_response)
147
141
  end
148
142
 
149
143
  def valid_string?(s)
@@ -1,4 +1,4 @@
1
1
  module SiftPartner
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  API_VERSION = "3"
4
4
  end
@@ -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
- end
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
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-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec