medrare-gocardless 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +68 -0
- data/Gemfile +12 -0
- data/Guardfile +6 -0
- data/LICENSE +22 -0
- data/README.md +17 -0
- data/Rakefile +82 -0
- data/gocardless.gemspec +22 -0
- data/lib/gocardless.rb +33 -0
- data/lib/gocardless/bill.rb +48 -0
- data/lib/gocardless/client.rb +393 -0
- data/lib/gocardless/errors.rb +30 -0
- data/lib/gocardless/merchant.rb +50 -0
- data/lib/gocardless/payment.rb +9 -0
- data/lib/gocardless/pre_authorization.rb +30 -0
- data/lib/gocardless/resource.rb +191 -0
- data/lib/gocardless/subscription.rb +31 -0
- data/lib/gocardless/user.rb +8 -0
- data/lib/gocardless/utils.rb +124 -0
- data/lib/gocardless/version.rb +3 -0
- data/spec/bill_spec.rb +27 -0
- data/spec/client_spec.rb +465 -0
- data/spec/gocardless_spec.rb +41 -0
- data/spec/merchant_spec.rb +31 -0
- data/spec/resource_spec.rb +396 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/subscription_spec.rb +18 -0
- data/spec/utils_spec.rb +242 -0
- metadata +152 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mocha'
|
2
|
+
require 'active_support/hash_with_indifferent_access'
|
3
|
+
require 'gocardless'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.mock_with :mocha
|
7
|
+
end
|
8
|
+
|
9
|
+
def stub_get(client, data)
|
10
|
+
response = mock
|
11
|
+
response.stubs(:parsed).returns(data)
|
12
|
+
|
13
|
+
token = client.instance_variable_get(:@access_token)
|
14
|
+
token.stubs(:get).returns response
|
15
|
+
end
|
16
|
+
|
17
|
+
def unset_ivar(obj, var)
|
18
|
+
obj.instance_variable_set "@#{var}", nil if obj.instance_variable_get "@#{var}"
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoCardless::Subscription do
|
4
|
+
before :each do
|
5
|
+
@app_id = 'abc'
|
6
|
+
@app_secret = 'xyz'
|
7
|
+
GoCardless.account_details = {:app_id => @app_id, :app_secret => @app_secret,
|
8
|
+
:token => 'xxx manage_merchant:1'}
|
9
|
+
@client = GoCardless.client
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be cancellable" do
|
13
|
+
s = GoCardless::Subscription.new_with_client(@client, :id => '009988')
|
14
|
+
@client.expects(:api_put).with('/subscriptions/009988/cancel')
|
15
|
+
s.cancel!
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/utils_spec.rb
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe GoCardless::Utils do
|
6
|
+
|
7
|
+
describe "string helpers" do
|
8
|
+
describe ".camelize" do
|
9
|
+
it "converts underscored words to camel case" do
|
10
|
+
GoCardless::Utils.camelize("a_test_string").should == "ATestString"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".underscore" do
|
15
|
+
it "converts camel case words to underscored form" do
|
16
|
+
GoCardless::Utils.underscore("ATestString").should == "a_test_string"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".singularize" do
|
21
|
+
it "removes trailing 's' characters" do
|
22
|
+
GoCardless::Utils.singularize("desks").should == "desk"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "converts 'i' suffix to 'us'" do
|
26
|
+
GoCardless::Utils.singularize("cacti").should == "cactus"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "hash helpers" do
|
32
|
+
describe ".symbolize_keys" do
|
33
|
+
it "converts keys to symbols" do
|
34
|
+
hash = {'string' => true, 123 => true, :symbol => true}
|
35
|
+
keys = GoCardless::Utils.symbolize_keys(hash).keys
|
36
|
+
keys.length.should == 3
|
37
|
+
keys.should include :string
|
38
|
+
keys.should include :'123'
|
39
|
+
keys.should include :symbol
|
40
|
+
end
|
41
|
+
|
42
|
+
it "preserves the original hash" do
|
43
|
+
hash = {'string' => true}
|
44
|
+
GoCardless::Utils.symbolize_keys(hash)
|
45
|
+
hash.keys.should == ['string']
|
46
|
+
end
|
47
|
+
|
48
|
+
it "doesn't overwrite existing symbol keys" do
|
49
|
+
hash = {'x' => 1, :x => 2}
|
50
|
+
GoCardless::Utils.symbolize_keys(hash).should == hash
|
51
|
+
end
|
52
|
+
|
53
|
+
it "works with sinatra params' default proc" do
|
54
|
+
hash = Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
55
|
+
hash['x'] = 1
|
56
|
+
GoCardless::Utils.symbolize_keys(hash).should == {:x => 1}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".symbolize_keys!" do
|
61
|
+
it "modifies the original hash" do
|
62
|
+
hash = {'string' => true}
|
63
|
+
GoCardless::Utils.symbolize_keys!(hash)
|
64
|
+
hash.keys.should == [:string]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "signature helpers" do
|
70
|
+
describe ".percent_encode" do
|
71
|
+
subject { GoCardless::Utils.method(:percent_encode) }
|
72
|
+
|
73
|
+
it "works with empty strings" do
|
74
|
+
subject[""].should == ""
|
75
|
+
end
|
76
|
+
|
77
|
+
it "doesn't encode lowercase alpha characters" do
|
78
|
+
subject["abcxyz"].should == "abcxyz"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "doesn't encode uppercase alpha characters" do
|
82
|
+
subject["ABCXYZ"].should == "ABCXYZ"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "doesn't encode digits" do
|
86
|
+
subject["1234567890"].should == "1234567890"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "doesn't encode unreserved non-alphanumeric characters" do
|
90
|
+
subject["-._~"].should == "-._~"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "encodes non-ascii alpha characters" do
|
94
|
+
subject["å"].should == "%C3%A5"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "encodes reserved ascii characters" do
|
98
|
+
subject[" !\"\#$%&'()"].should == "%20%21%22%23%24%25%26%27%28%29"
|
99
|
+
subject["*+,/{|}:;"].should == "%2A%2B%2C%2F%7B%7C%7D%3A%3B"
|
100
|
+
subject["<=>?@[\\]^`"].should == "%3C%3D%3E%3F%40%5B%5C%5D%5E%60"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "encodes other non-ascii characters" do
|
104
|
+
subject["支払い"].should == "%E6%94%AF%E6%89%95%E3%81%84"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe ".flatten_params" do
|
109
|
+
subject { GoCardless::Utils.method(:flatten_params) }
|
110
|
+
|
111
|
+
it "returns an empty array when provided with an empty hash" do
|
112
|
+
subject[{}].should == []
|
113
|
+
end
|
114
|
+
|
115
|
+
it "converts hashes to key-value arrays" do
|
116
|
+
subject['a' => 'b'].should == [['a', 'b']]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "works with integer keys and values" do
|
120
|
+
subject[123 => 456].should == [['123', '456']]
|
121
|
+
end
|
122
|
+
|
123
|
+
it "converts DateTime objects to ISO8601-fomatted strings" do
|
124
|
+
date = '2001-02-03T12:23:45Z'
|
125
|
+
subject[:date => Time.parse(date)][0][1].should == date
|
126
|
+
end
|
127
|
+
|
128
|
+
it "works with symbol keys and values" do
|
129
|
+
subject[:a => :b].should == [['a', 'b']]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "uses empty-bracket syntax for arrays" do
|
133
|
+
subject['a' => ['b']].should == [['a[]', 'b']]
|
134
|
+
end
|
135
|
+
|
136
|
+
it "includes all array values separately" do
|
137
|
+
result = subject['a' => ['b', 'c']]
|
138
|
+
result.should include ['a[]', 'b']
|
139
|
+
result.should include ['a[]', 'c']
|
140
|
+
result.length.should == 2
|
141
|
+
end
|
142
|
+
|
143
|
+
it "flattens nested arrays" do
|
144
|
+
subject['a' => [['b']]].should == [['a[][]', 'b']]
|
145
|
+
end
|
146
|
+
|
147
|
+
it "uses the bracket-syntax for hashes" do
|
148
|
+
subject['a' => {'b' => 'c'}].should == [['a[b]', 'c']]
|
149
|
+
end
|
150
|
+
|
151
|
+
it "includes all hash k/v pairs separately" do
|
152
|
+
result = subject['a' => {'b' => 'c', 'd' => 'e'}]
|
153
|
+
result.should include ['a[b]', 'c']
|
154
|
+
result.should include ['a[d]', 'e']
|
155
|
+
result.length.should == 2
|
156
|
+
end
|
157
|
+
|
158
|
+
it "flattens nested hashes" do
|
159
|
+
subject['a' => {'b' => {'c' => 'd'}}].should == [['a[b][c]', 'd']]
|
160
|
+
end
|
161
|
+
|
162
|
+
it "works with arrays inside hashes" do
|
163
|
+
subject['a' => {'b' => ['c']}].should == [['a[b][]', 'c']]
|
164
|
+
end
|
165
|
+
|
166
|
+
it "works with hashes inside arrays" do
|
167
|
+
subject['a' => [{'b' => 'c'}]].should == [['a[][b]', 'c']]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe ".normalize_params" do
|
172
|
+
subject { GoCardless::Utils.method(:normalize_params) }
|
173
|
+
|
174
|
+
it "percent encodes keys and values" do
|
175
|
+
subject['!' => '+'].split('=').should == ['%21', '%2B']
|
176
|
+
end
|
177
|
+
|
178
|
+
it "joins items by '=' signs" do
|
179
|
+
subject['a' => 'b'].should == 'a=b'
|
180
|
+
end
|
181
|
+
|
182
|
+
it "joins pairs by '&' signs" do
|
183
|
+
subject['a' => 'b', 'c' => 'd'].should == 'a=b&c=d'
|
184
|
+
end
|
185
|
+
|
186
|
+
it "sorts pairs by name then value" do
|
187
|
+
subject['a0' => 'b', 'a' => 'c'].should == 'a=c&a0=b'
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe ".sign_params" do
|
192
|
+
it "produces the correct hash for the given params and key" do
|
193
|
+
key = 'testsecret'
|
194
|
+
params = {:test => true}
|
195
|
+
sig = '6e4613b729ce15c288f70e72463739feeb05fc0b89b55d248d7f259b5367148b'
|
196
|
+
GoCardless::Utils.sign_params(params, key).should == sig
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "date and time helpers" do
|
202
|
+
describe ".iso_format_time" do
|
203
|
+
it "should work with a Time object" do
|
204
|
+
d = GoCardless::Utils.iso_format_time(Time.parse("1st January 2012"))
|
205
|
+
d.should == "2012-01-01T00:00:00Z"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should work with a DateTime object" do
|
209
|
+
d = GoCardless::Utils.iso_format_time(DateTime.parse("1st January 2012"))
|
210
|
+
d.should == "2012-01-01T00:00:00Z"
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should work with a Date object" do
|
214
|
+
d = GoCardless::Utils.iso_format_time(Date.parse("1st January 2012"))
|
215
|
+
d.should == "2012-01-01T00:00:00Z"
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should leave a string untouched" do
|
219
|
+
date = "1st January 2012"
|
220
|
+
GoCardless::Utils.iso_format_time(date).should == date
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe ".stringify_times" do
|
225
|
+
it "stringifies time objects" do
|
226
|
+
d = GoCardless::Utils.stringify_times(Time.parse("1st Jan 2012"))
|
227
|
+
d.should == "2012-01-01T00:00:00Z"
|
228
|
+
end
|
229
|
+
|
230
|
+
it "stringifies time values in hashes" do
|
231
|
+
d = GoCardless::Utils.stringify_times(:t => Time.parse("1st Jan 2012"))
|
232
|
+
d.should == { :t => "2012-01-01T00:00:00Z" }
|
233
|
+
end
|
234
|
+
|
235
|
+
it "stringifies time values in arrays" do
|
236
|
+
d = GoCardless::Utils.stringify_times([Time.parse("1st Jan 2012")])
|
237
|
+
d.should == ["2012-01-01T00:00:00Z"]
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: medrare-gocardless
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harry Marr
|
8
|
+
- Tom Blomfield
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-07-12 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: oauth2
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.8.0
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: multi_json
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "1.0"
|
35
|
+
version:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
type: :development
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "2.6"
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mocha
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.12
|
55
|
+
version:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: yard
|
58
|
+
type: :development
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.7.3
|
65
|
+
version:
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: activesupport
|
68
|
+
type: :development
|
69
|
+
version_requirement:
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "3.1"
|
75
|
+
version:
|
76
|
+
description: A Ruby wrapper for the GoCardless API
|
77
|
+
email:
|
78
|
+
- developers@gocardless.com
|
79
|
+
executables: []
|
80
|
+
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files: []
|
84
|
+
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- .travis.yml
|
89
|
+
- CHANGELOG.md
|
90
|
+
- Gemfile
|
91
|
+
- Guardfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- gocardless.gemspec
|
96
|
+
- lib/gocardless.rb
|
97
|
+
- lib/gocardless/bill.rb
|
98
|
+
- lib/gocardless/client.rb
|
99
|
+
- lib/gocardless/errors.rb
|
100
|
+
- lib/gocardless/merchant.rb
|
101
|
+
- lib/gocardless/payment.rb
|
102
|
+
- lib/gocardless/pre_authorization.rb
|
103
|
+
- lib/gocardless/resource.rb
|
104
|
+
- lib/gocardless/subscription.rb
|
105
|
+
- lib/gocardless/user.rb
|
106
|
+
- lib/gocardless/utils.rb
|
107
|
+
- lib/gocardless/version.rb
|
108
|
+
- spec/bill_spec.rb
|
109
|
+
- spec/client_spec.rb
|
110
|
+
- spec/gocardless_spec.rb
|
111
|
+
- spec/merchant_spec.rb
|
112
|
+
- spec/resource_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/subscription_spec.rb
|
115
|
+
- spec/utils_spec.rb
|
116
|
+
has_rdoc: true
|
117
|
+
homepage: https://github.com/gocardless/gocardless-ruby
|
118
|
+
licenses: []
|
119
|
+
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: "0"
|
130
|
+
version:
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: "0"
|
136
|
+
version:
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.3.5
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: Ruby wrapper for the GoCardless API
|
144
|
+
test_files:
|
145
|
+
- spec/bill_spec.rb
|
146
|
+
- spec/client_spec.rb
|
147
|
+
- spec/gocardless_spec.rb
|
148
|
+
- spec/merchant_spec.rb
|
149
|
+
- spec/resource_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
- spec/subscription_spec.rb
|
152
|
+
- spec/utils_spec.rb
|