square 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96deb675316127d8568b8c0788d070f74095a0d6
4
- data.tar.gz: 39cfdba4095dae9efa6570390b41834838500332
3
+ metadata.gz: 97640cf10444f7f9e41bb8fc733f6e4a058a5334
4
+ data.tar.gz: f564a55d6901749b0955f43e0d7fa69aa1f1e4c4
5
5
  SHA512:
6
- metadata.gz: 1e3834e7da8769dce73df9146cab2622688680063a55b6950cee39ace4898b74a3bb60ea6dfcf6084538ff24dc4ee68a2af37b39ab9e9c17398b8a604a72de4a
7
- data.tar.gz: db5dfacd28eff34a3010ba0468e3231888fd64cc197831acbef286442f0193084cf9fc09c36beed7fdde2f61a7fd2a9b34f2399e8caa5f2a690cb0172836f8f5
6
+ metadata.gz: 6ca3a04861c402d4770a156b4a0c371d449e75519a352ab67f95e70bccebdca813f825c4396f32ebbb23ae6f7f85201956d8f9949e6d204a60421c76f7a23655
7
+ data.tar.gz: 8c6f1eb1b9f612bb30f4c3655ca7c371ebc2e45d6336a67863102fb7fdbdb1f7081df2f055e70238d1a7d92bdade5a5fe7626fae49a5702564b8a88acdecf6be
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Square
2
2
 
3
- TODO: Write a gem description
3
+ Square API Client
4
+
5
+ https://connect.squareup.com
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,7 +20,44 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ ### OAuth 2.0
24
+
25
+ client = Square::Client.new(
26
+ '<your-client-id>',
27
+ redirect_uri: 'https://example.client.com/callback'
28
+ )
29
+
30
+ ## Authorization Request
31
+ redirect_to client.authorization_uri
32
+
33
+ ## Token Request
34
+ client.authorization_code = '<your-authorization-code>'
35
+ access_token = client.access_token!
36
+
37
+ ### Connect API
38
+
39
+ me = Square::Connect::Merchant.me access_token
40
+
41
+ ## Merchant API
42
+ me = me.fetch
43
+
44
+ ## Payments API
45
+ payments = me.payments
46
+
47
+ ## Payment API
48
+ payment = me.payment '<payment-id>'
49
+
50
+ ## Refunds API
51
+ refunds = me.refunds
52
+
53
+ ## Settlements API
54
+ settlements = me.settlements
55
+
56
+ ## Settlement API
57
+ settlement = me.settlement '<settlement-id>'
58
+
59
+ ## Bank Account API
60
+ bank_account = me.bank_account '<bank-accout-id>'
22
61
 
23
62
  ## Contributing
24
63
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -6,9 +6,9 @@ module Square
6
6
  def initialize(*args)
7
7
  super do |attributes|
8
8
  self.merchant = if attributes[:merchant_id]
9
- Merchant.new attributes[:merchant_id]
9
+ Merchant.new attributes[:merchant_id], access_token
10
10
  else
11
- Merchant.new :me
11
+ Merchant.me access_token
12
12
  end
13
13
  self.bank_name = attributes[:bank_name]
14
14
  self.name = attributes[:name]
@@ -16,6 +16,7 @@ module Square
16
16
  self.routing_number = attributes[:routing_number]
17
17
  self.account_number_suffix = attributes[:account_number_suffix]
18
18
  self.currency_code = attributes[:currency_code]
19
+ self.endpoint = endpoint_for merchant.identifier, :bank_accounts, identifier
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,16 @@
1
+ module Square
2
+ module Connect
3
+ module Connections
4
+ module BankAccounts
5
+ def bank_account(bank_account_id, params = nil)
6
+ access_token_required!
7
+ BankAccount.new(
8
+ bank_account_id,
9
+ merchant_id: identifier,
10
+ access_token: access_token
11
+ ).fetch
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -13,6 +13,15 @@ module Square
13
13
  )
14
14
  end
15
15
  end
16
+
17
+ def payment(payment_id, params = nil)
18
+ access_token_required!
19
+ Payment.new(
20
+ payment_id,
21
+ merchant_id: identifier,
22
+ access_token: access_token
23
+ ).fetch
24
+ end
16
25
  end
17
26
  end
18
27
  end
@@ -13,6 +13,15 @@ module Square
13
13
  )
14
14
  end
15
15
  end
16
+
17
+ def settlement(settlement_id, params = nil)
18
+ access_token_required!
19
+ Settlement.new(
20
+ settlement_id,
21
+ merchant_id: identifier,
22
+ access_token: access_token
23
+ ).fetch
24
+ end
16
25
  end
17
26
  end
18
27
  end
@@ -1,11 +1,10 @@
1
- require 'square/connect/connections'
2
-
3
1
  module Square
4
2
  module Connect
5
3
  class Merchant < Node
6
4
  include Connections::Payments
7
5
  include Connections::Refunds
8
6
  include Connections::Settlements
7
+ include Connections::BankAccounts
9
8
 
10
9
  attr_accessor :name, :email, :country_code, :language_code
11
10
 
@@ -7,8 +7,8 @@ module Square
7
7
  attributes = args.extract_options!
8
8
  self.identifier = attributes[:id] || attributes[:identifier] || args.first
9
9
  self.access_token = tokenize attributes[:access_token] || args.second
10
- self.endpoint = endpoint_for identifier
11
10
  yield attributes if block_given?
11
+ self.endpoint ||= endpoint_for identifier
12
12
  end
13
13
 
14
14
  def fetch
@@ -26,12 +26,12 @@ module Square
26
26
  def initialize(*args)
27
27
  super do |attributes|
28
28
  self.merchant = if attributes[:merchant_id]
29
- Merchant.new attributes[:merchant_id]
29
+ Merchant.new attributes[:merchant_id], access_token
30
30
  else
31
- Merchant.new :me
31
+ Merchant.me access_token
32
32
  end
33
33
  self.creator = if attributes[:creator_id]
34
- Merchant.new attributes[:creator_id]
34
+ Merchant.new attributes[:creator_id], access_token
35
35
  end
36
36
  self.created_at = if attributes[:created_at]
37
37
  Time.parse attributes[:created_at]
@@ -1,27 +1,26 @@
1
1
  module Square
2
2
  module Connect
3
- class Refund < Node
4
- attr_accessor :type, :reason, :refunded_money, :created_at, :processed_at, :payment
3
+ class Refund
4
+ attr_accessor :identifier, :type, :reason, :refunded_money, :created_at, :processed_at, :payment
5
5
 
6
- def initialize(*args)
7
- super do |attributes|
8
- self.type = attributes[:type]
9
- self.reason = attributes[:reason]
10
- self.refunded_money = if attributes[:refunded_money].present?
11
- Money.new attributes[:refunded_money]
12
- end
13
- [
14
- :created_at,
15
- :processed_at
16
- ].each do |time_key|
17
- if attributes[time_key]
18
- self.send "#{time_key}=", Time.parse(attributes[time_key])
19
- end
20
- end
21
- self.payment = if attributes[:payment_id]
22
- Payment.new attributes[:payment_id]
6
+ def initialize(attributes = {})
7
+ self.identifier = attributes[:id]
8
+ self.type = attributes[:type]
9
+ self.reason = attributes[:reason]
10
+ self.refunded_money = if attributes[:refunded_money].present?
11
+ Money.new attributes[:refunded_money]
12
+ end
13
+ [
14
+ :created_at,
15
+ :processed_at
16
+ ].each do |time_key|
17
+ if attributes[time_key]
18
+ self.send "#{time_key}=", Time.parse(attributes[time_key])
23
19
  end
24
20
  end
21
+ self.payment = if attributes[:payment_id]
22
+ Payment.new attributes[:payment_id]
23
+ end
25
24
  end
26
25
  end
27
26
  end
@@ -10,7 +10,7 @@ module Square
10
10
  Time.parse attributes[:initiated_at]
11
11
  end
12
12
  self.bank_account = if attributes[:bank_account_id]
13
- BankAccount.new attributes[:bank_account_id]
13
+ BankAccount.new attributes[:bank_account_id], access_token
14
14
  end
15
15
  self.total_money = if attributes[:total_money]
16
16
  Money.new attributes[:total_money]
@@ -18,6 +18,9 @@ module Square
18
18
  self.entries = Array(attributes[:entries]).collect do |entry_attributes|
19
19
  SettlementEntry.new entry_attributes
20
20
  end
21
+
22
+ merchnat_id = attributes[:merchant_id] || :me
23
+ self.endpoint = endpoint_for merchnat_id, :settlements, identifier
21
24
  end
22
25
  end
23
26
  end
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "JGHJ0343",
3
+ "merchant_id": "AV76FTXT15L",
4
+ "bank_name": "Chase",
5
+ "name": "Dave's Business Account",
6
+ "type": "CHECKING",
7
+ "routing_number": "012345678",
8
+ "account_number_suffix": "1234",
9
+ "currency_code": "USD"
10
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "C:34GEWHCJGPR40",
3
+ "status": "SENT",
4
+ "bank_account_id": "JGHJ0343",
5
+ "initiated_at": "2013-01-02T08:00:00.000Z",
6
+ "type": "CREDIT",
7
+ "total_money": {
8
+ "amount": 5981,
9
+ "currency_code": "USD"
10
+ }
11
+ }
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Square::Connect::BankAccount do
4
+ let(:klass) { Square::Connect::BankAccount }
5
+ let(:identifier) { 'bank_account_id' }
6
+ let(:merchant_id) { 'merchant_id' }
7
+ let(:access_token) { 'access_token' }
8
+
9
+ describe '#initialize' do
10
+ context 'when merchant_id given' do
11
+ subject { klass.new identifier, merchant_id: merchant_id }
12
+ its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "#{merchant_id}/bank_accounts/#{identifier}") }
13
+ end
14
+
15
+ context 'otherwise' do
16
+ subject { klass.new identifier }
17
+ its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "me/bank_accounts/#{identifier}") }
18
+ end
19
+ end
20
+
21
+ describe '#fetch' do
22
+ let(:instance) { klass.new identifier, access_token }
23
+
24
+ it do
25
+ settlement = mock_request "me/bank_accounts/#{identifier}", 'bank_account/mine' do
26
+ instance.fetch
27
+ end
28
+ settlement.should be_a klass
29
+ end
30
+ end
31
+ end
@@ -42,6 +42,16 @@ describe Square::Connect::Merchant do
42
42
  end
43
43
  end
44
44
 
45
+ describe '#fetch' do
46
+ it do
47
+ merchant = mock_request identifier, 'merchant/me' do
48
+ instance = klass.new identifier, access_token
49
+ instance.fetch
50
+ end
51
+ merchant.should be_a klass
52
+ end
53
+ end
54
+
45
55
  describe '.me' do
46
56
  subject { klass.me access_token }
47
57
  its(:identifier) { should == :me }
@@ -63,8 +63,4 @@ describe Square::Connect::Node do
63
63
  end
64
64
  end
65
65
  end
66
-
67
- describe '.me' do
68
-
69
- end
70
66
  end
@@ -41,7 +41,7 @@ describe Square::Connect::Payment do
41
41
  fetched = mock_request instance.endpoint, 'payments/single' do
42
42
  instance.fetch
43
43
  end
44
- fetched.should be_a Square::Connect::Payment
44
+ fetched.should be_a klass
45
45
  end
46
46
  end
47
47
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Square::Connect::Settlement do
4
+ let(:klass) { Square::Connect::Settlement }
5
+ let(:identifier) { 'settlement_id' }
6
+ let(:merchant_id) { 'merchant_id' }
7
+ let(:access_token) { 'access_token' }
8
+
9
+ describe '#initialize' do
10
+ context 'when merchant_id given' do
11
+ subject { klass.new identifier, access_token, merchant_id: merchant_id }
12
+ its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "#{merchant_id}/settlements/#{identifier}") }
13
+ end
14
+
15
+ context 'otherwise' do
16
+ subject { klass.new identifier, access_token }
17
+ its(:endpoint) { should == File.join(Square::Connect::ROOT_URL, "me/settlements/#{identifier}") }
18
+ end
19
+ end
20
+
21
+ describe '#fetch' do
22
+ let(:instance) { klass.new identifier, access_token }
23
+
24
+ it do
25
+ settlement = mock_request "me/settlements/#{identifier}", 'settlements/single' do
26
+ instance.fetch
27
+ end
28
+ settlement.should be_a klass
29
+ end
30
+ end
31
+ end
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
  gem.add_development_dependency 'rake'
20
20
  gem.add_development_dependency 'rspec'
21
21
  gem.add_development_dependency 'cover_me'
22
+ gem.add_development_dependency 'webmock'
22
23
  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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Square API client
84
98
  email:
85
99
  - nov@matake.jp
@@ -98,6 +112,7 @@ files:
98
112
  - lib/square/connect.rb
99
113
  - lib/square/connect/bank_account.rb
100
114
  - lib/square/connect/connections.rb
115
+ - lib/square/connect/connections/bank_accounts.rb
101
116
  - lib/square/connect/connections/payments.rb
102
117
  - lib/square/connect/connections/refunds.rb
103
118
  - lib/square/connect/connections/settlements.rb
@@ -118,6 +133,7 @@ files:
118
133
  - lib/square/oauth2/access_token.rb
119
134
  - lib/square/oauth2/client.rb
120
135
  - spec/helpers/webmock_helper.rb
136
+ - spec/mock_response/bank_account/mine.json
121
137
  - spec/mock_response/error/unauthorized.json
122
138
  - spec/mock_response/invalid_grant.json
123
139
  - spec/mock_response/merchant/me.json
@@ -125,14 +141,17 @@ files:
125
141
  - spec/mock_response/payments/single.json
126
142
  - spec/mock_response/refunds/list.json
127
143
  - spec/mock_response/settlements/list.json
144
+ - spec/mock_response/settlements/single.json
128
145
  - spec/mock_response/token.json
129
146
  - spec/spec_helper.rb
147
+ - spec/square/connect/bank_account_spec.rb
130
148
  - spec/square/connect/connections/payments_spec.rb
131
149
  - spec/square/connect/connections/refunds_spec.rb
132
150
  - spec/square/connect/connections/settlements_spec.rb
133
151
  - spec/square/connect/merchant_spec.rb
134
152
  - spec/square/connect/node_spec.rb
135
153
  - spec/square/connect/payment_spec.rb
154
+ - spec/square/connect/settlement_spec.rb
136
155
  - spec/square/oauth2/access_token_spec.rb
137
156
  - spec/square/oauth2/client_spec.rb
138
157
  - square.gemspec