square 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Rakefile +17 -0
- data/VERSION +1 -1
- data/lib/square.rb +6 -1
- data/lib/square/connect.rb +15 -0
- data/lib/square/connect/connections.rb +10 -0
- data/lib/square/connect/connections/bank_accounts.rb +8 -0
- data/lib/square/connect/connections/payments.rb +19 -0
- data/lib/square/connect/connections/refunds.rb +8 -0
- data/lib/square/connect/connections/settlements.rb +8 -0
- data/lib/square/connect/device.rb +12 -0
- data/lib/square/connect/error.rb +13 -0
- data/lib/square/connect/itemization.rb +11 -0
- data/lib/square/connect/merchant.rb +29 -0
- data/lib/square/connect/money.rb +12 -0
- data/lib/square/connect/node.rb +79 -0
- data/lib/square/connect/payment.rb +75 -0
- data/lib/square/connect/refund.rb +26 -0
- data/lib/square/connect/tax.rb +16 -0
- data/lib/square/connect/tender.rb +25 -0
- data/lib/square/exception.rb +4 -0
- data/lib/square/oauth2.rb +8 -0
- data/lib/square/oauth2/access_token.rb +11 -0
- data/lib/square/oauth2/client.rb +24 -0
- data/spec/helpers/webmock_helper.rb +58 -0
- data/spec/mock_response/error/unauthorized.json +4 -0
- data/spec/mock_response/invalid_grant.json +3 -0
- data/spec/mock_response/merchant/me.json +7 -0
- data/spec/mock_response/payments/list.json +185 -0
- data/spec/mock_response/payments/single.json +61 -0
- data/spec/mock_response/token.json +6 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/square/connect/connections/payments_spec.rb +19 -0
- data/spec/square/connect/merchant_spec.rb +50 -0
- data/spec/square/connect/node_spec.rb +70 -0
- data/spec/square/connect/payment_spec.rb +58 -0
- data/spec/square/oauth2/access_token_spec.rb +31 -0
- data/spec/square/oauth2/client_spec.rb +90 -0
- data/square.gemspec +13 -9
- metadata +82 -5
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Square::Connect::Node do
|
4
|
+
let(:klass) { Square::Connect::Node }
|
5
|
+
let(:identifier) { 'node_id' }
|
6
|
+
let(:access_token) { 'access_token' }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
subject { klass.new identifier }
|
10
|
+
its(:identifier) { should == identifier }
|
11
|
+
its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, identifier) }
|
12
|
+
|
13
|
+
context 'when access_token given' do
|
14
|
+
subject { klass.new identifier, access_token }
|
15
|
+
|
16
|
+
context 'as String' do
|
17
|
+
let(:access_token) { 'access_token' }
|
18
|
+
its(:access_token) { should be_a Square::OAuth2::AccessToken }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'as Square::OAuth2::AccessToken' do
|
22
|
+
let(:access_token) { Square::OAuth2::AccessToken.new 'access_token' }
|
23
|
+
its(:access_token) { should be_a Square::OAuth2::AccessToken }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#fetch' do
|
29
|
+
context 'when valid access_token given' do
|
30
|
+
let(:instance) { klass.new identifier, access_token }
|
31
|
+
|
32
|
+
it do
|
33
|
+
merchant = mock_request identifier, 'merchant/me', request_header: {'Authorization' => "Bearer #{access_token}"} do
|
34
|
+
instance.fetch
|
35
|
+
end
|
36
|
+
merchant.should be_a klass
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when invalid access_token given' do
|
41
|
+
let(:instance) { klass.new identifier, access_token }
|
42
|
+
|
43
|
+
it 'should reaise Square::Connect::Error' do
|
44
|
+
expect do
|
45
|
+
mock_request identifier, 'error/unauthorized', request_header: {'Authorization' => "Bearer #{access_token}"}, status: [401, 'Unauthorized'] do
|
46
|
+
instance.fetch
|
47
|
+
end
|
48
|
+
end.to raise_error(Square::Connect::Error) { |e|
|
49
|
+
e.status.should == 401
|
50
|
+
e.type.should == 'service.unauthorized'
|
51
|
+
e.message.should == 'Unauthorized'
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'otherwise' do
|
57
|
+
let(:instance) { klass.new identifier }
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect do
|
61
|
+
instance.fetch
|
62
|
+
end.to raise_error Square::Exception, 'access_token required'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '.me' do
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Square::Connect::Payment do
|
4
|
+
let(:klass) { Square::Connect::Payment }
|
5
|
+
let(:identifier) { 'payment_id' }
|
6
|
+
let(:merchant_id) { 'merchant_id' }
|
7
|
+
let(:creator_id) { 'creator_id' }
|
8
|
+
let(:access_token) { 'access_token' }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
describe 'merchant' do
|
12
|
+
context 'when merchant given' do
|
13
|
+
subject { klass.new identifier, merchant: Square::Connect::Merchant.new(merchant_id) }
|
14
|
+
its(:merchant) { should be_a Square::Connect::Merchant }
|
15
|
+
its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "#{merchant_id}/payments/#{identifier}") }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when merchant_id given' do
|
19
|
+
subject { klass.new identifier, merchant_id: merchant_id }
|
20
|
+
its(:merchant) { should be_a Square::Connect::Merchant }
|
21
|
+
its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "#{merchant_id}/payments/#{identifier}") }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'otherwise' do
|
25
|
+
subject { klass.new identifier }
|
26
|
+
its(:merchant) { should be_a Square::Connect::Merchant }
|
27
|
+
its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "me/payments/#{identifier}") }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'creator' do
|
32
|
+
context 'when creator given' do
|
33
|
+
subject { klass.new identifier, creator: Square::Connect::Merchant.new(creator_id) }
|
34
|
+
its(:creator) { should be_a Square::Connect::Merchant }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when creator_id given' do
|
38
|
+
subject { klass.new identifier, creator_id: creator_id }
|
39
|
+
its(:creator) { should be_a Square::Connect::Merchant }
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'otherwise' do
|
43
|
+
subject { klass.new identifier }
|
44
|
+
its(:creator) { should be_nil }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#fetch' do
|
50
|
+
let(:instance) { klass.new identifier, access_token }
|
51
|
+
it do
|
52
|
+
fetched = mock_request instance.endpoint, 'payments/single' do
|
53
|
+
instance.fetch
|
54
|
+
end
|
55
|
+
fetched.should be_a Square::Connect::Payment
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Square::OAuth2::AccessToken do
|
4
|
+
let(:klass) { Square::OAuth2::AccessToken }
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
let(:access_token) { 'access_token' }
|
8
|
+
|
9
|
+
describe 'access_token' do
|
10
|
+
context 'when missing' do
|
11
|
+
it do
|
12
|
+
expect do
|
13
|
+
klass.new
|
14
|
+
end.to raise_error AttrRequired::AttrMissing
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when given' do
|
19
|
+
context 'as the first arg' do
|
20
|
+
subject { klass.new access_token }
|
21
|
+
its(:access_token) { should == access_token }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'as Hash' do
|
25
|
+
subject { klass.new access_token: access_token }
|
26
|
+
its(:access_token) { should == access_token }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Square::OAuth2::Client do
|
4
|
+
let(:client_id) { 'client_id' }
|
5
|
+
let(:client_secret) { 'client_secret' }
|
6
|
+
let(:klass) { Square::OAuth2::Client }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
subject { klass.new client_id }
|
10
|
+
|
11
|
+
it { should be_a Rack::OAuth2::Client }
|
12
|
+
|
13
|
+
describe 'identifier' do
|
14
|
+
context 'when missing' do
|
15
|
+
it do
|
16
|
+
expect do
|
17
|
+
klass.new
|
18
|
+
end.to raise_error AttrRequired::AttrMissing
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when given' do
|
23
|
+
context 'as the first arg' do
|
24
|
+
subject { klass.new client_id }
|
25
|
+
its(:identifier) { should == client_id }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'as Hash' do
|
29
|
+
subject { klass.new identifier: client_id }
|
30
|
+
its(:identifier) { should == client_id }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'secret' do
|
36
|
+
context 'when missing' do
|
37
|
+
subject { klass.new client_id }
|
38
|
+
its(:secret) { should be_nil }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when given' do
|
42
|
+
context 'as the second arg' do
|
43
|
+
subject { klass.new client_id, client_secret }
|
44
|
+
its(:secret) { should == client_secret }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'as Hash' do
|
48
|
+
subject { klass.new identifier: client_id, secret: client_secret }
|
49
|
+
its(:secret) { should == client_secret }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'other attributes' do
|
55
|
+
its(:host) { should == 'squareup.com' }
|
56
|
+
its(:authorization_uri) { should == "https://squareup.com/oauth2/authorize?client_id=#{client_id}&response_type=code" }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'access_token!' do
|
61
|
+
let(:authorization_code) { 'authorization_code' }
|
62
|
+
let(:redirect_uri) { 'https://client.example.com/callback' }
|
63
|
+
let(:token_uri) { File.join(Square::OAuth2::ROOT_URL, 'oauth2/token') }
|
64
|
+
|
65
|
+
it "should access to '#{Square::OAuth2::ROOT_URL}' with client_auth_method as body" do
|
66
|
+
mock_request token_uri, 'token', method: :post, params: {
|
67
|
+
grant_type: 'authorization_code',
|
68
|
+
client_id: client_id,
|
69
|
+
code: authorization_code,
|
70
|
+
redirect_uri: redirect_uri
|
71
|
+
} do
|
72
|
+
client = klass.new client_id, redirect_uri: redirect_uri
|
73
|
+
client.authorization_code = authorization_code
|
74
|
+
client.access_token!
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when invalid grant' do
|
79
|
+
it do
|
80
|
+
expect do
|
81
|
+
mock_request token_uri, 'invalid_grant', method: :post, status: [400, 'Bad Request'] do
|
82
|
+
client = klass.new client_id, redirect_uri: redirect_uri
|
83
|
+
client.authorization_code = authorization_code
|
84
|
+
client.access_token!
|
85
|
+
end
|
86
|
+
end.to raise_error Rack::OAuth2::Client::Error
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/square.gemspec
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
|
-
gem.name =
|
3
|
-
gem.version = File.read(
|
4
|
-
gem.authors = [
|
5
|
-
gem.email = [
|
2
|
+
gem.name = 'square'
|
3
|
+
gem.version = File.read('VERSION').delete("\n\r")
|
4
|
+
gem.authors = ['nov']
|
5
|
+
gem.email = ['nov@matake.jp']
|
6
6
|
gem.description = %q{Square API client}
|
7
7
|
gem.summary = %q{Square API Client}
|
8
|
-
gem.homepage =
|
9
|
-
gem.license =
|
8
|
+
gem.homepage = 'https://github.com/nov/square'
|
9
|
+
gem.license = 'MIT'
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($/)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
14
|
-
gem.require_paths = [
|
14
|
+
gem.require_paths = ['lib']
|
15
15
|
|
16
|
-
gem.
|
17
|
-
|
16
|
+
gem.add_runtime_dependency 'rack-oauth2'
|
17
|
+
|
18
|
+
gem.add_development_dependency 'bundler'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'cover_me'
|
18
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: square
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov
|
@@ -10,20 +10,34 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- -
|
31
|
+
- - '>='
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- -
|
38
|
+
- - '>='
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,34 @@ dependencies:
|
|
38
52
|
- - '>='
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cover_me
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
description: Square API client
|
42
84
|
email:
|
43
85
|
- nov@matake.jp
|
@@ -46,12 +88,47 @@ extensions: []
|
|
46
88
|
extra_rdoc_files: []
|
47
89
|
files:
|
48
90
|
- .gitignore
|
91
|
+
- .rspec
|
49
92
|
- Gemfile
|
50
93
|
- LICENSE.txt
|
51
94
|
- README.md
|
52
95
|
- Rakefile
|
53
96
|
- VERSION
|
54
97
|
- lib/square.rb
|
98
|
+
- lib/square/connect.rb
|
99
|
+
- lib/square/connect/connections.rb
|
100
|
+
- lib/square/connect/connections/bank_accounts.rb
|
101
|
+
- lib/square/connect/connections/payments.rb
|
102
|
+
- lib/square/connect/connections/refunds.rb
|
103
|
+
- lib/square/connect/connections/settlements.rb
|
104
|
+
- lib/square/connect/device.rb
|
105
|
+
- lib/square/connect/error.rb
|
106
|
+
- lib/square/connect/itemization.rb
|
107
|
+
- lib/square/connect/merchant.rb
|
108
|
+
- lib/square/connect/money.rb
|
109
|
+
- lib/square/connect/node.rb
|
110
|
+
- lib/square/connect/payment.rb
|
111
|
+
- lib/square/connect/refund.rb
|
112
|
+
- lib/square/connect/tax.rb
|
113
|
+
- lib/square/connect/tender.rb
|
114
|
+
- lib/square/exception.rb
|
115
|
+
- lib/square/oauth2.rb
|
116
|
+
- lib/square/oauth2/access_token.rb
|
117
|
+
- lib/square/oauth2/client.rb
|
118
|
+
- spec/helpers/webmock_helper.rb
|
119
|
+
- spec/mock_response/error/unauthorized.json
|
120
|
+
- spec/mock_response/invalid_grant.json
|
121
|
+
- spec/mock_response/merchant/me.json
|
122
|
+
- spec/mock_response/payments/list.json
|
123
|
+
- spec/mock_response/payments/single.json
|
124
|
+
- spec/mock_response/token.json
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- spec/square/connect/connections/payments_spec.rb
|
127
|
+
- spec/square/connect/merchant_spec.rb
|
128
|
+
- spec/square/connect/node_spec.rb
|
129
|
+
- spec/square/connect/payment_spec.rb
|
130
|
+
- spec/square/oauth2/access_token_spec.rb
|
131
|
+
- spec/square/oauth2/client_spec.rb
|
55
132
|
- square.gemspec
|
56
133
|
homepage: https://github.com/nov/square
|
57
134
|
licenses:
|