gocardless 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/gocardless.gemspec +5 -5
- data/lib/gocardless.rb +1 -0
- data/lib/gocardless/client.rb +3 -2
- data/lib/gocardless/errors.rb +2 -2
- data/lib/gocardless/resource.rb +1 -1
- data/lib/gocardless/subscription.rb +6 -0
- data/lib/gocardless/utils.rb +26 -8
- data/lib/gocardless/version.rb +1 -1
- data/spec/resource_spec.rb +4 -3
- data/spec/spec_helper.rb +0 -1
- data/spec/subscription_spec.rb +18 -0
- data/spec/utils_spec.rb +41 -12
- metadata +12 -11
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,5 +13,5 @@ you want to support multiple merchant accounts, see the
|
|
13
13
|
The full API reference is available at on
|
14
14
|
[rubydoc.info](http://rubydoc.info/github/gocardless/gocardless-ruby/master/frames).
|
15
15
|
|
16
|
-
[![Build Status](https://secure.travis-ci.org/gocardless/gocardless-ruby.png)](http://travis-ci.org/gocardless/gocardless-ruby)
|
16
|
+
[![Build Status](https://secure.travis-ci.org/gocardless/gocardless-ruby.png?branch=master)](http://travis-ci.org/gocardless/gocardless-ruby)
|
17
17
|
|
data/gocardless.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.expand_path('../lib/gocardless/version', __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
|
-
gem.add_runtime_dependency
|
5
|
-
gem.add_runtime_dependency
|
4
|
+
gem.add_runtime_dependency 'oauth2', '~> 0.5.0.rc1'
|
5
|
+
gem.add_runtime_dependency 'multi_json', '~> 1.2'
|
6
6
|
|
7
7
|
gem.add_development_dependency 'rspec', '~> 2.6'
|
8
8
|
gem.add_development_dependency 'mocha', '~> 0.9.12'
|
9
|
-
gem.add_development_dependency
|
10
|
-
gem.add_development_dependency
|
9
|
+
gem.add_development_dependency 'yard', '~> 0.7.3'
|
10
|
+
gem.add_development_dependency 'activesupport', '~> 3.1'
|
11
11
|
|
12
|
-
gem.authors = [
|
12
|
+
gem.authors = ['Harry Marr', 'Tom Blomfield']
|
13
13
|
gem.description = %q{A Ruby wrapper for the GoCardless API}
|
14
14
|
gem.email = ['developers@gocardless.com']
|
15
15
|
gem.files = `git ls-files`.split("\n")
|
data/lib/gocardless.rb
CHANGED
data/lib/gocardless/client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'multi_json'
|
3
3
|
require 'oauth2'
|
4
4
|
require 'openssl'
|
5
5
|
require 'uri'
|
@@ -270,7 +270,8 @@ module GoCardless
|
|
270
270
|
opts[:headers] = {} if opts[:headers].nil?
|
271
271
|
opts[:headers]['Accept'] = 'application/json'
|
272
272
|
opts[:headers]['Content-Type'] = 'application/json' unless method == :get
|
273
|
-
opts[:
|
273
|
+
opts[:headers]['User-Agent'] = "gocardless-ruby-v#{GoCardless::VERSION}"
|
274
|
+
opts[:body] = MultiJson.encode(opts[:data]) if !opts[:data].nil?
|
274
275
|
|
275
276
|
# Reset the URL in case the environment / base URL has been changed.
|
276
277
|
@oauth_client.site = self.class.base_url
|
data/lib/gocardless/errors.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'multi_json'
|
3
3
|
|
4
4
|
module GoCardless
|
5
5
|
class Error < StandardError
|
@@ -11,7 +11,7 @@ module GoCardless
|
|
11
11
|
def initialize(response)
|
12
12
|
@response = response
|
13
13
|
@code = response.status
|
14
|
-
body =
|
14
|
+
body = MultiJson.decode(response.body) rescue nil
|
15
15
|
if body.is_a? Hash
|
16
16
|
@description = body["error"] || response.body.strip || "Unknown error"
|
17
17
|
end
|
data/lib/gocardless/resource.rb
CHANGED
data/lib/gocardless/utils.rb
CHANGED
@@ -39,14 +39,6 @@ module GoCardless
|
|
39
39
|
URI.encode(str, /[^a-zA-Z0-9\-\.\_\~]/)
|
40
40
|
end
|
41
41
|
|
42
|
-
# Format a Time object according to ISO 8601, and convert to UTC.
|
43
|
-
#
|
44
|
-
# @param [Time] time the time object to format
|
45
|
-
# @return [String] the ISO-formatted time
|
46
|
-
def iso_format_time(time)
|
47
|
-
time.is_a?(Time) ? time.getutc.strftime('%Y-%m-%dT%H:%M:%SZ') : time
|
48
|
-
end
|
49
|
-
|
50
42
|
# Flatten a hash containing nested hashes and arrays to a non-nested array
|
51
43
|
# of key-value pairs.
|
52
44
|
#
|
@@ -101,6 +93,32 @@ module GoCardless
|
|
101
93
|
digest = OpenSSL::Digest::Digest.new('sha256')
|
102
94
|
OpenSSL::HMAC.hexdigest(digest, key, msg)
|
103
95
|
end
|
96
|
+
|
97
|
+
# Format a Time object according to ISO 8601, and convert to UTC.
|
98
|
+
#
|
99
|
+
# @param [Time] time the time object to format
|
100
|
+
# @return [String] the ISO-formatted time
|
101
|
+
def iso_format_time(time)
|
102
|
+
return time unless time.is_a? Time or time.is_a? Date
|
103
|
+
time = time.getutc if time.is_a? Time
|
104
|
+
time = time.new_offset(0) if time.is_a? DateTime
|
105
|
+
time.strftime('%Y-%m-%dT%H:%M:%SZ')
|
106
|
+
end
|
107
|
+
|
108
|
+
# Recursively ISO format all time and date values.
|
109
|
+
#
|
110
|
+
# @param [Hash] obj the object containing date or time objects
|
111
|
+
# @return [Hash] the object with ISO-formatted time stings
|
112
|
+
def stringify_times(obj)
|
113
|
+
case obj
|
114
|
+
when Hash
|
115
|
+
Hash[obj.map { |k,v| [k, stringify_times(v)] }]
|
116
|
+
when Array
|
117
|
+
obj.map { |v| stringify_times(v) }
|
118
|
+
else
|
119
|
+
iso_format_time(obj)
|
120
|
+
end
|
121
|
+
end
|
104
122
|
end
|
105
123
|
end
|
106
124
|
|
data/lib/gocardless/version.rb
CHANGED
data/spec/resource_spec.rb
CHANGED
@@ -293,15 +293,16 @@ describe GoCardless::Resource do
|
|
293
293
|
reference_accessor :person_id
|
294
294
|
end
|
295
295
|
|
296
|
+
time_str = '2012-01-01T00:00:00Z'
|
296
297
|
bill = test_resource.new({
|
297
298
|
:amount => '10',
|
298
|
-
:when =>
|
299
|
+
:when => Time.parse(time_str),
|
299
300
|
:person_id => 15
|
300
301
|
})
|
301
302
|
|
302
|
-
result =
|
303
|
+
result = MultiJson.decode(bill.to_json)
|
303
304
|
result['amount'].should == bill.amount
|
304
|
-
result['when'].should ==
|
305
|
+
result['when'].should == time_str
|
305
306
|
result['person_id'].should == 15
|
306
307
|
end
|
307
308
|
|
data/spec/spec_helper.rb
CHANGED
@@ -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
CHANGED
@@ -105,18 +105,6 @@ describe GoCardless::Utils do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
describe ".iso_format_time" do
|
109
|
-
it "should work with a Time object" do
|
110
|
-
d = GoCardless::Utils.iso_format_time(Time.parse("1st January 2012"))
|
111
|
-
d.should == "2012-01-01T00:00:00Z"
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should leave a string untouched" do
|
115
|
-
date = "1st January 2012"
|
116
|
-
GoCardless::Utils.iso_format_time(date).should == date
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
108
|
describe ".flatten_params" do
|
121
109
|
subject { GoCardless::Utils.method(:flatten_params) }
|
122
110
|
|
@@ -206,4 +194,45 @@ describe GoCardless::Utils do
|
|
206
194
|
end
|
207
195
|
end
|
208
196
|
|
197
|
+
describe "date and time helpers" do
|
198
|
+
describe ".iso_format_time" do
|
199
|
+
it "should work with a Time object" do
|
200
|
+
d = GoCardless::Utils.iso_format_time(Time.parse("1st January 2012"))
|
201
|
+
d.should == "2012-01-01T00:00:00Z"
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should work with a DateTime object" do
|
205
|
+
d = GoCardless::Utils.iso_format_time(DateTime.parse("1st January 2012"))
|
206
|
+
d.should == "2012-01-01T00:00:00Z"
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should work with a Date object" do
|
210
|
+
d = GoCardless::Utils.iso_format_time(Date.parse("1st January 2012"))
|
211
|
+
d.should == "2012-01-01T00:00:00Z"
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should leave a string untouched" do
|
215
|
+
date = "1st January 2012"
|
216
|
+
GoCardless::Utils.iso_format_time(date).should == date
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe ".stringify_times" do
|
221
|
+
it "stringifies time objects" do
|
222
|
+
d = GoCardless::Utils.stringify_times(Time.parse("1st Jan 2012"))
|
223
|
+
d.should == "2012-01-01T00:00:00Z"
|
224
|
+
end
|
225
|
+
|
226
|
+
it "stringifies time values in hashes" do
|
227
|
+
d = GoCardless::Utils.stringify_times(:t => Time.parse("1st Jan 2012"))
|
228
|
+
d.should == { :t => "2012-01-01T00:00:00Z" }
|
229
|
+
end
|
230
|
+
|
231
|
+
it "stringifies time values in arrays" do
|
232
|
+
d = GoCardless::Utils.stringify_times([Time.parse("1st Jan 2012")])
|
233
|
+
d.should == ["2012-01-01T00:00:00Z"]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
209
238
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gocardless
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 2380615109590600174
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Harry Marr
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-04-03 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: oauth2
|
@@ -37,19 +37,18 @@ dependencies:
|
|
37
37
|
type: :runtime
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
|
-
name:
|
40
|
+
name: multi_json
|
41
41
|
prerelease: false
|
42
42
|
requirement: &id002 !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
hash:
|
47
|
+
hash: 3191556116430806706
|
48
48
|
segments:
|
49
49
|
- 1
|
50
|
-
-
|
51
|
-
|
52
|
-
version: 1.5.3
|
50
|
+
- 2
|
51
|
+
version: "1.2"
|
53
52
|
type: :runtime
|
54
53
|
version_requirements: *id002
|
55
54
|
- !ruby/object:Gem::Dependency
|
@@ -152,6 +151,7 @@ files:
|
|
152
151
|
- spec/merchant_spec.rb
|
153
152
|
- spec/resource_spec.rb
|
154
153
|
- spec/spec_helper.rb
|
154
|
+
- spec/subscription_spec.rb
|
155
155
|
- spec/utils_spec.rb
|
156
156
|
homepage: https://github.com/gocardless/gocardless-ruby
|
157
157
|
licenses: []
|
@@ -193,5 +193,6 @@ test_files:
|
|
193
193
|
- spec/merchant_spec.rb
|
194
194
|
- spec/resource_spec.rb
|
195
195
|
- spec/spec_helper.rb
|
196
|
+
- spec/subscription_spec.rb
|
196
197
|
- spec/utils_spec.rb
|
197
198
|
has_rdoc:
|