quaderno 1.13.2 → 1.17.0

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