quaderno 1.13.2 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +56 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -15
- data/README.md +120 -42
- data/Rakefile +4 -50
- data/changelog.md +67 -41
- data/lib/quaderno-ruby.rb +5 -5
- data/lib/quaderno-ruby/base.rb +112 -107
- data/lib/quaderno-ruby/behavior/block.rb +20 -19
- data/lib/quaderno-ruby/behavior/crud.rb +108 -95
- data/lib/quaderno-ruby/behavior/deliver.rb +20 -18
- data/lib/quaderno-ruby/behavior/payment.rb +38 -34
- data/lib/quaderno-ruby/behavior/retrieve.rb +26 -25
- data/lib/quaderno-ruby/checkout_session.rb +4 -0
- data/lib/quaderno-ruby/collection.rb +1 -0
- data/lib/quaderno-ruby/contact.rb +6 -8
- data/lib/quaderno-ruby/credit.rb +10 -12
- data/lib/quaderno-ruby/document_item.rb +1 -3
- data/lib/quaderno-ruby/estimate.rb +5 -7
- data/lib/quaderno-ruby/evidence.rb +5 -7
- data/lib/quaderno-ruby/exceptions/exceptions.rb +50 -44
- data/lib/quaderno-ruby/expense.rb +6 -8
- data/lib/quaderno-ruby/helpers/authentication.rb +16 -18
- data/lib/quaderno-ruby/helpers/rate_limit.rb +12 -0
- data/lib/quaderno-ruby/income.rb +8 -10
- data/lib/quaderno-ruby/invoice.rb +9 -11
- data/lib/quaderno-ruby/item.rb +3 -6
- data/lib/quaderno-ruby/payment.rb +2 -3
- data/lib/quaderno-ruby/receipt.rb +6 -8
- data/lib/quaderno-ruby/recurring.rb +4 -7
- data/lib/quaderno-ruby/report.rb +67 -29
- data/lib/quaderno-ruby/tax.rb +51 -46
- data/lib/quaderno-ruby/version.rb +3 -0
- data/lib/quaderno-ruby/webhook.rb +3 -5
- data/quaderno.gemspec +28 -148
- metadata +92 -92
- data/Gemfile.lock +0 -91
- data/VERSION +0 -1
- data/test/fixtures/quaderno_cassettes/.DS_Store +0 -0
- data/test/fixtures/quaderno_cassettes/all_contacts.yml +0 -52
- data/test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml +0 -56
- data/test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml +0 -57
- data/test/fixtures/quaderno_cassettes/all_estimates.yml +0 -52
- data/test/fixtures/quaderno_cassettes/all_expenses.yml +0 -55
- data/test/fixtures/quaderno_cassettes/all_invoices.yml +0 -56
- data/test/fixtures/quaderno_cassettes/all_items.yml +0 -46
- data/test/fixtures/quaderno_cassettes/all_receipts.yml +0 -53
- data/test/fixtures/quaderno_cassettes/all_webhooks.yml +0 -214
- data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +0 -156
- data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +0 -278
- data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +0 -159
- data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +0 -196
- data/test/fixtures/quaderno_cassettes/deleted_contact.yml +0 -187
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml +0 -199
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml +0 -199
- data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +0 -187
- data/test/fixtures/quaderno_cassettes/deleted_expense.yml +0 -189
- data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +0 -190
- data/test/fixtures/quaderno_cassettes/deleted_item.yml +0 -128
- data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +0 -223
- data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +0 -257
- data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +0 -136
- data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +0 -143
- data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +0 -140
- data/test/fixtures/quaderno_cassettes/evidence_invoice.yml +0 -98
- data/test/fixtures/quaderno_cassettes/found_contact.yml +0 -95
- data/test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml +0 -99
- data/test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml +0 -100
- data/test/fixtures/quaderno_cassettes/found_estimate.yml +0 -97
- data/test/fixtures/quaderno_cassettes/found_expense.yml +0 -99
- data/test/fixtures/quaderno_cassettes/found_invoice.yml +0 -100
- data/test/fixtures/quaderno_cassettes/found_item.yml +0 -91
- data/test/fixtures/quaderno_cassettes/found_receipt.yml +0 -98
- data/test/fixtures/quaderno_cassettes/found_webhook.yml +0 -130
- data/test/fixtures/quaderno_cassettes/new_contact.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_estimate.yml +0 -137
- data/test/fixtures/quaderno_cassettes/new_evidence.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_expense.yml +0 -189
- data/test/fixtures/quaderno_cassettes/new_invoice.yml +0 -137
- data/test/fixtures/quaderno_cassettes/new_item.yml +0 -48
- data/test/fixtures/quaderno_cassettes/new_receipt.yml +0 -173
- data/test/fixtures/quaderno_cassettes/new_webhook.yml +0 -87
- data/test/fixtures/quaderno_cassettes/paid_expense.yml +0 -98
- data/test/fixtures/quaderno_cassettes/paid_invoice.yml +0 -99
- data/test/fixtures/quaderno_cassettes/rate_limit.yml +0 -46
- data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +0 -138
- data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +0 -138
- data/test/fixtures/quaderno_cassettes/updated_contact.yml +0 -97
- data/test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml +0 -101
- data/test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml +0 -102
- data/test/fixtures/quaderno_cassettes/updated_estimate.yml +0 -185
- data/test/fixtures/quaderno_cassettes/updated_expense.yml +0 -184
- data/test/fixtures/quaderno_cassettes/updated_invoice.yml +0 -184
- data/test/fixtures/quaderno_cassettes/updated_item.yml +0 -93
- data/test/fixtures/quaderno_cassettes/updated_receipt.yml +0 -220
- data/test/fixtures/quaderno_cassettes/updated_webhook.yml +0 -175
- data/test/fixtures/quaderno_cassettes/validate_invalid_VAT_number.yml +0 -44
- data/test/fixtures/quaderno_cassettes/validate_valid_VAT_number.yml +0 -44
- data/test/helper.rb +0 -32
- data/test/unit/test_quaderno_contacts.rb +0 -83
- data/test/unit/test_quaderno_contacts_thread_safe.rb +0 -104
- data/test/unit/test_quaderno_estimates.rb +0 -155
- data/test/unit/test_quaderno_evidences.rb +0 -41
- data/test/unit/test_quaderno_expenses.rb +0 -162
- data/test/unit/test_quaderno_invoices.rb +0 -177
- data/test/unit/test_quaderno_items.rb +0 -84
- data/test/unit/test_quaderno_receipts.rb +0 -156
- data/test/unit/test_quaderno_tax.rb +0 -46
- data/test/unit/test_quaderno_webhooks.rb +0 -93
@@ -1,28 +1,29 @@
|
|
1
|
-
module Quaderno
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Quaderno::Behavior
|
2
|
+
module Block
|
3
|
+
def self.included(receiver)
|
4
|
+
receiver.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
include Quaderno::Helpers::Authentication
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
def block(id, options = {})
|
11
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
10
12
|
|
11
|
-
def block(id, options = {})
|
12
|
-
authentication = get_authentication(options.merge(api_model: api_model))
|
13
13
|
|
14
|
+
response = put("#{authentication[:url]}#{api_model.api_path}/#{id}/block.json",
|
15
|
+
basic_auth: authentication[:basic_auth],
|
16
|
+
headers: version_header.merge(authentication[:headers])
|
17
|
+
)
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
headers: version_header.merge(authentication[:headers])
|
18
|
-
)
|
19
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
20
|
+
doc = response.parsed_response
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
object = new doc
|
23
|
+
object.rate_limit_info = response
|
22
24
|
|
23
|
-
|
24
|
-
end
|
25
|
+
object
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
@@ -1,125 +1,138 @@
|
|
1
|
-
module Quaderno
|
2
|
-
module
|
3
|
-
module Crud
|
1
|
+
module Quaderno::Behavior
|
2
|
+
module Crud
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def self.included(receiver)
|
5
|
+
receiver.send :extend, ClassMethods
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
module ClassMethods
|
9
|
+
include Quaderno::Helpers::Authentication
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
def parse_nested(element)
|
12
|
+
if element.has_key?('payments')
|
13
|
+
payments_collection = Array.new
|
14
|
+
(element['payments'] || Array.new).each { |payment| payments_collection << Quaderno::Payment.new(payment) }
|
15
|
+
element['payments'] = payments_collection
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
items_collection = Array.new
|
19
|
+
element['items'].each { |item| items_collection << Quaderno::DocumentItem.new(item) }
|
20
|
+
element['items'] = items_collection
|
21
|
+
element['contact'] = Quaderno::Contact.new(element['contact'])
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
element
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
else
|
48
|
-
array.each { |element| collection << (new element) }
|
26
|
+
def all(options = {})
|
27
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
28
|
+
filter = options.delete_if { |k,v| %w(auth_token access_token api_url mode api_model).include? k.to_s }
|
29
|
+
|
30
|
+
response = get("#{authentication[:url]}#{api_model.api_path}.json",
|
31
|
+
query: filter,
|
32
|
+
basic_auth: authentication[:basic_auth],
|
33
|
+
headers: version_header.merge(authentication[:headers])
|
34
|
+
)
|
35
|
+
|
36
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true })
|
37
|
+
array = response.parsed_response
|
38
|
+
collection = Quaderno::Collection.new
|
39
|
+
|
40
|
+
if is_a_document?
|
41
|
+
array.each do |element|
|
42
|
+
element[:authentication_data] = authentication
|
43
|
+
api_model.parse_nested(element)
|
44
|
+
collection << (new element)
|
49
45
|
end
|
46
|
+
else
|
47
|
+
array.each { |element| collection << (new element) }
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
50
|
+
collection.rate_limit_info = response
|
51
|
+
collection.current_page = response.headers['x-pages-currentpage']
|
52
|
+
collection.total_pages = response.headers['x-pages-totalpages']
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
collection
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
def find(id, options = {})
|
58
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
response = get("#{authentication[:url]}#{api_model.api_path}/#{id}.json",
|
61
|
+
basic_auth: authentication[:basic_auth],
|
62
|
+
headers: version_header.merge(authentication[:headers])
|
63
|
+
)
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
66
|
+
hash = response.parsed_response
|
67
|
+
hash[:authentication_data] = authentication
|
68
68
|
|
69
|
-
|
69
|
+
api_model.parse_nested(hash) if is_a_document?
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
object = new hash
|
72
|
+
object.rate_limit_info = response
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
params.delete_if { |k,v| %w(auth_token access_token api_url mode api_model').include? k.to_s }
|
74
|
+
object
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
headers: version_header.merge(authentication[:headers]).merge('Content-Type' => 'application/json')
|
82
|
-
)
|
77
|
+
def create(params = {})
|
78
|
+
authentication = get_authentication(params.merge(api_model: api_model))
|
79
|
+
params.delete_if { |k,v| %w(auth_token access_token api_url mode api_model').include? k.to_s }
|
83
80
|
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
response = post("#{authentication[:url]}#{api_model.api_path}.json",
|
82
|
+
body: params.to_json,
|
83
|
+
basic_auth: authentication[:basic_auth],
|
84
|
+
headers: version_header.merge(authentication[:headers]).merge('Content-Type' => 'application/json')
|
85
|
+
)
|
87
86
|
|
88
|
-
|
87
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, required_fields: true })
|
88
|
+
hash = response.parsed_response
|
89
|
+
hash[:authentication_data] = authentication
|
89
90
|
|
90
|
-
|
91
|
-
end
|
91
|
+
api_model.parse_nested(hash) if is_a_document?
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
params = params.delete_if { |k,v| %w(auth_token access_token api_url mode api_model').include? k.to_s }
|
93
|
+
object = new hash
|
94
|
+
object.rate_limit_info = response
|
96
95
|
|
97
|
-
|
98
|
-
|
99
|
-
basic_auth: authentication[:basic_auth],
|
100
|
-
headers: version_header.merge(authentication[:headers]).merge('Content-Type' => 'application/json')
|
101
|
-
)
|
96
|
+
object
|
97
|
+
end
|
102
98
|
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
def update(id, params = {})
|
100
|
+
authentication = get_authentication(params.merge(api_model: api_model))
|
101
|
+
params = params.delete_if { |k,v| %w(auth_token access_token api_url mode api_model').include? k.to_s }
|
106
102
|
|
107
|
-
|
103
|
+
response = put("#{authentication[:url]}#{api_model.api_path}/#{id}.json",
|
104
|
+
body: params.to_json,
|
105
|
+
basic_auth: authentication[:basic_auth],
|
106
|
+
headers: version_header.merge(authentication[:headers]).merge('Content-Type' => 'application/json')
|
107
|
+
)
|
108
108
|
|
109
|
-
|
110
|
-
|
109
|
+
check_exception_for(response, { rate_limit: true, required_fields: true, subdomain_or_token: true, id: true })
|
110
|
+
hash = response.parsed_response
|
111
|
+
hash[:authentication_data] = authentication
|
111
112
|
|
112
|
-
|
113
|
-
authentication = get_authentication(options.merge(api_model: api_model))
|
113
|
+
api_model.parse_nested(hash) if is_a_document?
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
headers: version_header.merge(authentication[:headers])
|
118
|
-
)
|
119
|
-
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true, has_documents: true })
|
115
|
+
object = new hash
|
116
|
+
object.rate_limit_info = response
|
120
117
|
|
121
|
-
|
122
|
-
|
118
|
+
object
|
119
|
+
end
|
120
|
+
|
121
|
+
def delete(id, options = {})
|
122
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
123
|
+
|
124
|
+
response = HTTParty.delete("#{authentication[:url]}#{ api_model.api_path }/#{ id }.json",
|
125
|
+
basic_auth: authentication[:basic_auth],
|
126
|
+
headers: version_header.merge(authentication[:headers])
|
127
|
+
)
|
128
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true, has_documents: true })
|
129
|
+
|
130
|
+
hash = { deleted: true, id: id }
|
131
|
+
|
132
|
+
object = new hash
|
133
|
+
object.rate_limit_info = response
|
134
|
+
|
135
|
+
object
|
123
136
|
end
|
124
137
|
end
|
125
138
|
end
|
@@ -1,26 +1,28 @@
|
|
1
|
-
module Quaderno
|
2
|
-
module
|
3
|
-
module Deliver
|
1
|
+
module Quaderno::Behavior
|
2
|
+
module Deliver
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
include Quaderno::Helpers::Authentication
|
10
|
+
|
11
|
+
def deliver(options = nil)
|
12
|
+
self.authentication_data = get_authentication(options.merge(api_model: api_model)) if options.is_a?(Hash)
|
8
13
|
|
9
|
-
|
10
|
-
|
14
|
+
party_response = api_model.get("#{authentication_data[:url]}#{api_model.api_path}/#{id}/deliver.json",
|
15
|
+
basic_auth: authentication_data[:basic_auth],
|
16
|
+
headers: self.class.version_header.merge(authentication_data[:headers])
|
17
|
+
)
|
11
18
|
|
12
|
-
|
13
|
-
self.authentication_data = get_authentication(options.merge(api_model: api_model)) if options.is_a?(Hash)
|
19
|
+
api_model.check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, id: true, required_fields: true })
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
headers: self.class.version_header.merge(authentication_data[:headers])
|
18
|
-
)
|
21
|
+
data = Quaderno::Base.new(success: true)
|
22
|
+
data.rate_limit_info = party_response
|
19
23
|
|
20
|
-
|
21
|
-
{ limit: party_response.headers["x-ratelimit-limit"].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
|
22
|
-
end
|
24
|
+
data
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
26
|
-
end
|
28
|
+
end
|
@@ -1,50 +1,54 @@
|
|
1
|
-
module Quaderno
|
2
|
-
module
|
3
|
-
module Payment
|
1
|
+
module Quaderno::Behavior
|
2
|
+
module Payment
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def self.included(base)
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
module InstanceMethods
|
9
|
+
include Quaderno::Helpers::Authentication
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
def add_payment(params = {})
|
12
|
+
if (params.keys.map(&:to_s) & %w(auth_token access_token api_url mode api_model)).any?
|
13
|
+
self.authentication_data = get_authentication(params.merge(api_model: api_model))
|
14
|
+
params = params.delete_if { |k, _| %w(auth_token access_token api_url mode api_model).include? k.to_s }
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
response = api_model.post("#{authentication_data[:url]}#{api_model.api_path}/#{id}/payments.json",
|
18
|
+
body: params,
|
19
|
+
basic_auth: authentication_data[:basic_auth],
|
20
|
+
headers: self.class.version_header.merge(authentication_data[:headers])
|
21
|
+
)
|
23
22
|
|
24
|
-
|
23
|
+
api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, required_fields: true })
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
instance = Quaderno::Payment.new(response.parsed_response)
|
26
|
+
self.payments << instance
|
28
27
|
|
29
|
-
|
30
|
-
end
|
28
|
+
instance.rate_limit_info = response
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
instance
|
31
|
+
end
|
34
32
|
|
33
|
+
def remove_payment(payment_id, options = nil)
|
34
|
+
self.authentication_data = get_authentication(options.merge(api_model: api_model)) if options.is_a?(Hash)
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
response = HTTParty.delete("#{authentication_data[:url]}#{api_model.api_path}/#{id}/payments/#{payment_id}.json",
|
37
|
+
basic_auth: authentication_data[:basic_auth],
|
38
|
+
headers: self.class.version_header.merge(authentication_data[:headers])
|
39
|
+
)
|
40
40
|
|
41
|
-
|
41
|
+
api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
42
42
|
|
43
|
-
|
43
|
+
self.payments.delete_if { |payment| payment.id == payment_id }
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
hash = { deleted: true, id: payment_id}
|
46
|
+
|
47
|
+
object = Quaderno::Payment.new(hash)
|
48
|
+
object.rate_limit_info = response
|
49
|
+
|
50
|
+
object
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
50
|
-
end
|
54
|
+
end
|
@@ -1,35 +1,36 @@
|
|
1
|
-
module Quaderno
|
2
|
-
module
|
3
|
-
module Retrieve
|
1
|
+
module Quaderno::Behavior
|
2
|
+
module Retrieve
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def self.included(receiver)
|
5
|
+
receiver.send :extend, ClassMethods
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
module ClassMethods
|
9
|
+
include Quaderno::Helpers::Authentication
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
def retrieve(gateway_id, gateway = 'stripe', options = {})
|
12
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
response = get("#{authentication[:url]}#{gateway}/#{@_retrieve_path}/#{gateway_id}.json",
|
15
|
+
basic_auth: authentication[:basic_auth],
|
16
|
+
headers: version_header.merge(authentication[:headers])
|
17
|
+
)
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
20
|
+
hash = response.parsed_response
|
21
|
+
hash[:authentication_data] = authentication
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
object = new hash
|
24
|
+
object.rate_limit_info = response
|
25
|
+
|
26
|
+
object
|
27
|
+
end
|
28
|
+
alias_method :retrieve_customer, :retrieve
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
30
|
+
private
|
31
|
+
def retrieve_path(path)
|
32
|
+
@_retrieve_path = path
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
35
|
-
end
|
36
|
+
end
|