sift-partner 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzFkYTY0OGM2MDQxNDQzMzM5NWI5MTczZGJlNzk0YmVmMmU5MjQxMg==
5
- data.tar.gz: !binary |-
6
- NWJkOGVlNjYxZTNhYzQ5ZTcxM2Q0ZDM4MDcxMDYyNjVhNjRhY2RhOA==
2
+ SHA1:
3
+ metadata.gz: 2ffbcc3b8821ea80e55772aec21ba849a5bc8c08
4
+ data.tar.gz: 0ad11555eaf96e0e6d8a60eb12b392ad72913d21
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZjZjY2RkOTVkOTJmNGQ2YWY3YjZkMTk4MjVmYjMxZDBiZTM3OGM1NmZhMTI4
10
- MmRmZjUyNjhlYzc5NGU2YTZmNzhjODllYTVjYmRlMjJiY2MxMzlkZDIyNjcy
11
- ODFiZDMxYTMzNjFhNjQ2MzAwZTAwNDgzZGViZWIyMzIyMTRlYzM=
12
- data.tar.gz: !binary |-
13
- YTMzOGExN2Q5ZjRiMjUwMTk4MjI3NjA2NmIyNmQzYzBlYzU4OWZiMDYxZTE3
14
- Y2I2YjFmN2U3YmNhMTFhYmMwNGIyY2UxZDg0ZTE3ZTY5NGNhYzQ4OTc3YWI0
15
- MWRlZDBmOWRhYTZjMjU3ZjdmM2VlYTAwZGZjY2YxMWUwM2Y2MDQ=
6
+ metadata.gz: 8e8146c86622681634be4cdc83e38b3f01fc071f500261c3b5da94024a41cafa8676d52fb9ba0aa9dc2cee8ff3e4d87897b425c177f28d5109360967ddbc242a
7
+ data.tar.gz: 5dbb787221a05ad9b8b9e7bb9cd268928c7afae0c3332a0d90c51012dab6d2d38636024c8fba599c82e5c3e70377270539666d29ea0633da967881f53f34719d
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ before_install:
3
+ - "gem install bundler"
4
+ - "bundle -v"
5
+ install:
6
+ - bundle install
7
+ script:
8
+ - bundle exec rake spec
9
+ rvm:
10
+ - 1.9.3
11
+ - 2.0.0
12
+ - 2.1.0
13
+ - 2.2.0
14
+ - 2.3.0
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sift-partner (0.0.1)
5
- httparty (>= 0.13.1)
6
- multi_json (>= 1.0)
7
- sift (>= 1.1.6.2)
4
+ sift-partner (0.0.3)
5
+ httparty (~> 0.13.1)
6
+ multi_json (~> 1.0)
7
+ sift (~> 1.1.7)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
@@ -13,27 +13,23 @@ GEM
13
13
  crack (0.4.2)
14
14
  safe_yaml (~> 1.0.0)
15
15
  diff-lcs (1.2.5)
16
- httparty (0.13.1)
16
+ httparty (0.13.7)
17
17
  json (~> 1.8)
18
18
  multi_xml (>= 0.5.2)
19
- json (1.8.1)
20
- multi_json (1.10.1)
19
+ json (1.8.3)
20
+ multi_json (1.12.1)
21
21
  multi_xml (0.5.5)
22
- rake (10.3.2)
23
- rspec (3.1.0)
24
- rspec-core (~> 3.1.0)
25
- rspec-expectations (~> 3.1.0)
26
- rspec-mocks (~> 3.1.0)
27
- rspec-core (3.1.4)
28
- rspec-support (~> 3.1.0)
29
- rspec-expectations (3.1.1)
30
- diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.1.0)
32
- rspec-mocks (3.1.1)
33
- rspec-support (~> 3.1.0)
34
- rspec-support (3.1.0)
35
- safe_yaml (1.0.3)
36
- sift (1.1.6.2)
22
+ rake (11.1.2)
23
+ rspec (2.99.0)
24
+ rspec-core (~> 2.99.0)
25
+ rspec-expectations (~> 2.99.0)
26
+ rspec-mocks (~> 2.99.0)
27
+ rspec-core (2.99.2)
28
+ rspec-expectations (2.99.2)
29
+ diff-lcs (>= 1.1.3, < 2.0)
30
+ rspec-mocks (2.99.4)
31
+ safe_yaml (1.0.4)
32
+ sift (1.1.7.3)
37
33
  httparty (>= 0.11.0)
38
34
  multi_json (>= 1.0)
39
35
  webmock (1.18.0)
@@ -44,7 +40,10 @@ PLATFORMS
44
40
  ruby
45
41
 
46
42
  DEPENDENCIES
47
- rake
48
- rspec (>= 2.14.1)
43
+ rake (~> 11.0)
44
+ rspec (~> 2.0)
49
45
  sift-partner!
50
- webmock (>= 1.16.0)
46
+ webmock (~> 1.0)
47
+
48
+ BUNDLED WITH
49
+ 1.12.5
@@ -1,9 +1,9 @@
1
- = Sift Science Partner Ruby bindings
1
+ = Sift Science Partner Ruby bindings {<img src="https://travis-ci.org/SiftScience/sift-partner-ruby.png?branch=master" alt="Build Status" />}[https://travis-ci.org/SiftScience/sift-partner-ruby]
2
2
 
3
3
  == Requirements
4
4
 
5
5
  * Ruby 1.8.7 or above. (Ruby 1.8.6 might work if you load ActiveSupport.)
6
- * HTTParty, 0.11.0 or greater
6
+ * HTTParty, 0.13.1 or greater
7
7
  * Multi Json, 1.0 or greater
8
8
  * sift, 1.1.6.2 or greater
9
9
 
@@ -22,6 +22,8 @@ module SiftPartner
22
22
  # The account id of the partner
23
23
  # (which may be found in the settings page of the console)
24
24
  def initialize(api_key = Sift.api_key, id = Sift.account_id)
25
+ raise("api_key must be a non-empty string") unless valid_string?(api_key)
26
+ raise("partner must be a non-empty string") unless valid_string?(id)
25
27
  @api_key = api_key
26
28
  @id = id
27
29
  end
@@ -40,6 +42,12 @@ module SiftPartner
40
42
  # When successful, returns a including the new account id and credentials.
41
43
  # When an error occurs, returns nil.
42
44
  def new_account(site_url, site_email, analyst_email, password)
45
+
46
+ raise("site url must be a non-empty string") unless valid_string?(site_url)
47
+ raise("site email must be a non-empty string") unless valid_string?(site_email)
48
+ raise("analyst email must be a non-empty string") unless valid_string?(analyst_email)
49
+ raise("password must be a non-empty string") unless valid_string?(password)
50
+
43
51
  reqBody = {:site_url => site_url, :site_email => site_email,
44
52
  :analyst_email => analyst_email, :password => password}
45
53
  begin
@@ -70,7 +78,10 @@ module SiftPartner
70
78
  # The value of the notification_url will be a url containing the string '%s' exactly once.
71
79
  # This allows the url to be used as a template, into which a merchant account id can be substituted.
72
80
  # The notification threshold should be a floating point number between 0.0 and 1.0
73
- def update_notification_config(cfg)
81
+ def update_notification_config(cfg = nil)
82
+
83
+ raise("configuration must be a hash") unless cfg.is_a? Hash
84
+
74
85
  http_put(notification_config_url(), cfg)
75
86
  end
76
87
 
@@ -79,12 +90,20 @@ module SiftPartner
79
90
  URI("#{API_ENDPOINT}/partners/#{@id}/accounts")
80
91
  end
81
92
 
93
+ def user_agent
94
+ "SiftScience/v#{API_VERSION} sift-partner-ruby/#{VERSION}"
95
+ end
96
+
82
97
  def notification_config_url
83
98
  URI("#{API_ENDPOINT}/accounts/#{@id}/config")
84
99
  end
85
100
 
86
101
  def safe_json(http_response)
87
- response = Sift::Response.new(http_response.body, http_response.code)
102
+ response = Sift::Response.new(
103
+ http_response.body,
104
+ http_response.code,
105
+ http_response.response
106
+ )
88
107
  if !response.nil? and response.ok?
89
108
  response.json
90
109
  else
@@ -100,23 +119,32 @@ module SiftPartner
100
119
  end
101
120
 
102
121
  def http_get(uri)
103
- header = {"Authorization" => "Basic #{@api_key}"}
122
+ header = {"Authorization" => "Basic #{@api_key}",
123
+ "User-Agent" => user_agent}
124
+
104
125
  http_response = HTTParty.get(uri, :headers =>header)
105
126
  safe_json(http_response)
106
127
  end
107
128
 
108
129
  def http_put(uri, bodyObj)
109
130
  header = {"Content-Type" => "application/json",
110
- "Authorization" => "Basic #{@api_key}"}
131
+ "Authorization" => "Basic #{@api_key}",
132
+ "User-Agent" => user_agent}
133
+
111
134
  http_response = HTTParty.put(uri, :body => bodyObj.to_json, :headers => header)
112
135
  safe_json(http_response)
113
136
  end
114
137
 
115
138
  def http_post(uri, bodyObj)
116
139
  header = {"Content-Type" => "application/json",
117
- "Authorization" => "Basic #{@api_key}"}
140
+ "Authorization" => "Basic #{@api_key}",
141
+ "User-Agent" => user_agent}
118
142
  http_response = HTTParty.post(uri, :body => bodyObj.to_json, :headers => header)
119
143
  safe_json(http_response)
120
144
  end
145
+
146
+ def valid_string?(s)
147
+ s.is_a?(String) && !s.empty?
148
+ end
121
149
  end
122
150
  end
@@ -1,3 +1,4 @@
1
1
  module SiftPartner
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
+ API_VERSION = "3"
3
4
  end
@@ -20,13 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  # Gems that must be intalled for sift to compile and build
23
- s.add_development_dependency "rspec", ">=2.14.1"
24
- s.add_development_dependency "webmock", ">= 1.16.0"
23
+ s.add_development_dependency "rspec", "~> 2.0"
24
+ s.add_development_dependency "webmock", "~> 1.0"
25
+ s.add_development_dependency("rake", "~> 11.0")
25
26
 
26
27
  # Gems that must be intalled for sift to work
27
- s.add_dependency "httparty", ">= 0.13.1"
28
- s.add_dependency "multi_json", ">= 1.0"
29
- s.add_dependency "sift", ">= 1.1.6.2"
30
-
31
- s.add_development_dependency("rake")
28
+ s.add_dependency "httparty", "~> 0.13.1"
29
+ s.add_dependency "multi_json", "~> 1.0"
30
+ s.add_dependency "sift", "~> 1.1.7"
32
31
  end
@@ -3,6 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper"))
3
3
  describe SiftPartner::Client do
4
4
  partner_id = "65653548"
5
5
  partner_api_key = "98463454389754"
6
+ site_url = "merchant123.com"
7
+ site_email = "owner@merchant123.com"
8
+ analyst_email = "analyst+merchant123@partner.com"
9
+ password = "s0m3l0ngp455w0rd"
10
+
6
11
  expected_account_body = {
7
12
  "account_id" => "1234567890abcdef",
8
13
  "production" => {
@@ -39,11 +44,63 @@ describe SiftPartner::Client do
39
44
  }
40
45
  }
41
46
 
47
+ it "Cannot instantiate client with nil, empty, or non-string api key" do
48
+ lambda { Sift::Client.new(nil, partner_id) }.should raise_error
49
+ lambda { Sift::Client.new("", partner_id) }.should raise_error
50
+ lambda { Sift::Client.new(123456, partner_id) }.should raise_error
51
+ end
52
+
53
+ it "Cannot instantiate client with nil, empty, or non-string partner id" do
54
+ lambda { Sift::Client.new(partner_api_key, nil) }.should raise_error
55
+ lambda { Sift::Client.new(partner_api_key, "") }.should raise_error
56
+ lambda { Sift::Client.new(partner_api_key, 123456) }.should raise_error
57
+ end
58
+
59
+ it "Can instantiate client with blank api key if Sift.api_key set" do
60
+ lambda { Sift::Client.new(partner_api_key, partner_id) }.should_not raise_error
61
+ end
62
+
63
+ it "account creation fails with nil, empty, or non-string site url" do
64
+ partner_client = SiftPartner::Client.new(partner_api_key, partner_id)
65
+ lambda { partner_client.new_account(nil, site_email, analyst_email,
66
+ password) }.should raise_error
67
+ lambda { partner_client.new_account("", site_email, analyst_email,
68
+ password) }.should raise_error
69
+ lambda { partner_client.new_account(12345, site_email, analyst_email,
70
+ password) }.should raise_error
71
+ end
72
+
73
+ it "account creation fails with nil, empty, or non-string site email" do
74
+ partner_client = SiftPartner::Client.new(partner_api_key, partner_id)
75
+ lambda { partner_client.new_account(site_url, nil, analyst_email,
76
+ password) }.should raise_error
77
+ lambda { partner_client.new_account(site_url, "", analyst_email,
78
+ password) }.should raise_error
79
+ lambda { partner_client.new_account(site_url, 12345, analyst_email,
80
+ password) }.should raise_error
81
+ end
82
+
83
+ it "account creation fails with nil, empty, or non-string analyst email" do
84
+ partner_client = SiftPartner::Client.new(partner_api_key, partner_id)
85
+ lambda { partner_client.new_account(site_url, site_email, nil,
86
+ password) }.should raise_error
87
+ lambda { partner_client.new_account(site_url, site_email, "",
88
+ password) }.should raise_error
89
+ lambda { partner_client.new_account(site_url, site_email, 12345,
90
+ password) }.should raise_error
91
+ end
92
+
93
+ it "account creation fails with nil, empty, or non-string password" do
94
+ partner_client = SiftPartner::Client.new(partner_api_key, partner_id)
95
+ lambda { partner_client.new_account(site_url, site_email, analyst_email,
96
+ nil) }.should raise_error
97
+ lambda { partner_client.new_account(site_url, site_email, analyst_email,
98
+ "") }.should raise_error
99
+ lambda { partner_client.new_account(site_url, site_email, analyst_email,
100
+ 12345) }.should raise_error
101
+ end
102
+
42
103
  it "should march through create acct flow" do
43
- site_url = "merchant123.com"
44
- site_email = "owner@merchant123.com"
45
- analyst_email = "analyst+merchant123@partner.com"
46
- password = "s0m3l0ngp455w0rd"
47
104
  # when we receive the mocked url, it will include the basic auth header encoded
48
105
  # and regurgitated before the host name
49
106
  stub_request(:post, /https:\/\/.*\@partner\.siftscience\.com\/v3\/partners\/#{partner_id}\/accounts/).
@@ -82,6 +139,14 @@ describe SiftPartner::Client do
82
139
  response["totalResults"].should eq(1)
83
140
  end
84
141
 
142
+
143
+
144
+ it "config update fails with nil, or non-hash notification threshold" do
145
+ partner_client = SiftPartner::Client.new(partner_api_key, partner_id)
146
+ lambda { partner_client.update_notification_config(nil) }.should raise_error
147
+ lambda { partner_client.update_notification_config("not_a_hash") }.should raise_error
148
+ end
149
+
85
150
  it "should work through config update flow" do
86
151
  stub_request(:put, /https:\/\/.*\@partner\.siftscience\.com\/v3\/accounts\/#{partner_id}\/config/).
87
152
  with { |request|
metadata CHANGED
@@ -1,99 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sift-partner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Beppu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-06 00:00:00.000000000 Z
11
+ date: 2016-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.14.1
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.14.1
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: webmock
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.16.0
33
+ version: '1.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.16.0
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: httparty
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.13.1
48
- type: :runtime
47
+ version: '11.0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.13.1
54
+ version: '11.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: multi_json
56
+ name: httparty
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: 0.13.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: 0.13.1
69
69
  - !ruby/object:Gem::Dependency
70
- name: sift
70
+ name: multi_json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.1.6.2
75
+ version: '1.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.1.6.2
82
+ version: '1.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rake
84
+ name: sift
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
89
+ version: 1.1.7
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 1.1.7
97
97
  description: Sift Science Ruby Partner API. Please see http://siftscience.com for
98
98
  more details.
99
99
  email:
@@ -102,6 +102,7 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".travis.yml"
105
106
  - Gemfile
106
107
  - Gemfile.lock
107
108
  - LICENSE
@@ -122,17 +123,17 @@ require_paths:
122
123
  - lib
123
124
  required_ruby_version: !ruby/object:Gem::Requirement
124
125
  requirements:
125
- - - ! '>='
126
+ - - ">="
126
127
  - !ruby/object:Gem::Version
127
128
  version: '0'
128
129
  required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  requirements:
130
- - - ! '>='
131
+ - - ">="
131
132
  - !ruby/object:Gem::Version
132
133
  version: '0'
133
134
  requirements: []
134
135
  rubyforge_project: sift-partner
135
- rubygems_version: 2.1.11
136
+ rubygems_version: 2.4.6
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: Sift Science Ruby Partner API Gem