quaderno 1.11.2 → 1.12.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +53 -1
- data/VERSION +1 -1
- data/changelog.md +3 -0
- data/lib/quaderno-ruby/base.rb +12 -2
- data/lib/quaderno-ruby/behavior/crud.rb +56 -11
- data/lib/quaderno-ruby/behavior/deliver.rb +10 -2
- data/lib/quaderno-ruby/behavior/payment.rb +23 -4
- data/lib/quaderno-ruby/behavior/retrieve.rb +11 -2
- data/lib/quaderno-ruby/collection.rb +22 -0
- data/lib/quaderno-ruby/helpers/authentication.rb +26 -0
- data/lib/quaderno-ruby.rb +4 -1
- data/quaderno.gemspec +16 -5
- data/test/fixtures/quaderno_cassettes/all_contacts.yml +11 -282
- data/test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml +56 -0
- data/test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml +57 -0
- data/test/fixtures/quaderno_cassettes/all_estimates.yml +10 -14
- data/test/fixtures/quaderno_cassettes/all_expenses.yml +14 -47
- data/test/fixtures/quaderno_cassettes/all_invoices.yml +13 -2873
- data/test/fixtures/quaderno_cassettes/all_items.yml +8 -8
- data/test/fixtures/quaderno_cassettes/all_receipts.yml +11 -14
- data/test/fixtures/quaderno_cassettes/all_webhooks.yml +40 -36
- data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +46 -318
- data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +125 -357
- data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +45 -318
- data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +56 -53
- data/test/fixtures/quaderno_cassettes/deleted_contact.yml +40 -592
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml +199 -0
- data/test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml +199 -0
- data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +40 -334
- data/test/fixtures/quaderno_cassettes/deleted_expense.yml +43 -364
- data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +44 -3199
- data/test/fixtures/quaderno_cassettes/deleted_item.yml +22 -22
- data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +43 -42
- data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +48 -44
- data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +25 -32
- data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +29 -2888
- data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +29 -29
- data/test/fixtures/quaderno_cassettes/evidence_invoice.yml +19 -354
- data/test/fixtures/quaderno_cassettes/found_contact.yml +19 -291
- data/test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml +99 -0
- data/test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml +100 -0
- data/test/fixtures/quaderno_cassettes/found_estimate.yml +20 -24
- data/test/fixtures/quaderno_cassettes/found_expense.yml +24 -94
- data/test/fixtures/quaderno_cassettes/found_invoice.yml +22 -2886
- data/test/fixtures/quaderno_cassettes/found_item.yml +18 -16
- data/test/fixtures/quaderno_cassettes/found_receipt.yml +21 -24
- data/test/fixtures/quaderno_cassettes/found_webhook.yml +24 -22
- data/test/fixtures/quaderno_cassettes/new_contact.yml +9 -7
- data/test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml +48 -0
- data/test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml +48 -0
- data/test/fixtures/quaderno_cassettes/new_estimate.yml +29 -320
- data/test/fixtures/quaderno_cassettes/new_evidence.yml +10 -8
- data/test/fixtures/quaderno_cassettes/new_expense.yml +42 -363
- data/test/fixtures/quaderno_cassettes/new_invoice.yml +29 -324
- data/test/fixtures/quaderno_cassettes/new_item.yml +10 -8
- data/test/fixtures/quaderno_cassettes/new_receipt.yml +28 -24
- data/test/fixtures/quaderno_cassettes/new_webhook.yml +16 -14
- data/test/fixtures/quaderno_cassettes/paid_expense.yml +22 -52
- data/test/fixtures/quaderno_cassettes/paid_invoice.yml +22 -2879
- data/test/fixtures/quaderno_cassettes/rate_limit.yml +5 -5
- data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +29 -61
- data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +28 -2888
- data/test/fixtures/quaderno_cassettes/updated_contact.yml +22 -292
- data/test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml +101 -0
- data/test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml +102 -0
- data/test/fixtures/quaderno_cassettes/updated_estimate.yml +44 -353
- data/test/fixtures/quaderno_cassettes/updated_expense.yml +43 -346
- data/test/fixtures/quaderno_cassettes/updated_invoice.yml +43 -361
- data/test/fixtures/quaderno_cassettes/updated_item.yml +21 -17
- data/test/fixtures/quaderno_cassettes/updated_receipt.yml +47 -41
- data/test/fixtures/quaderno_cassettes/updated_webhook.yml +35 -31
- data/test/helper.rb +2 -1
- data/test/unit/test_quaderno_contacts.rb +1 -1
- data/test/unit/test_quaderno_contacts_thread_safe.rb +104 -0
- data/test/unit/test_quaderno_expenses.rb +5 -5
- metadata +15 -4
- data/test/fixtures/quaderno_cassettes/calculate_tax.yml +0 -85
- data/test/fixtures/quaderno_cassettes/wrong_token.yml +0 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99d18f2cc67c9df4eb49d8bf5c545a966c6ff520
|
|
4
|
+
data.tar.gz: 2e605b26ce41c9f45b8871852b4cd5251e14f8d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 918acf002048a31ff6f8830d23d72e8ba1a66825aba93322e9a9c1c86e6d8bd4d80ee47f3084bba1bc18c886af56c31f29dd5b6875b675155e3fe4f19b8ca97d
|
|
7
|
+
data.tar.gz: 70fecee7f72f788b1d35c4936199dfae703d89f7b9f824b1c29c266af9af90209f5182867b09ce0790f8be50600b129833db420ff306995c61bc9d13f40f158d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Quaderno-ruby is a ruby wrapper for [Quaderno API] (https://github.com/quaderno/quaderno-api).
|
|
4
4
|
As the API, it's mostly CRUD.
|
|
5
5
|
|
|
6
|
-
Current version is 1.
|
|
6
|
+
Current version is 1.12.0 See the changelog [here](https://github.com/quaderno/quaderno-ruby/blob/master/changelog.md)
|
|
7
7
|
|
|
8
8
|
## Installation & Configuration
|
|
9
9
|
|
|
@@ -588,6 +588,58 @@ Quaderno-ruby exceptions raise depending on the type of error:
|
|
|
588
588
|
|
|
589
589
|
All those exceptions inherit from `Quaderno::Exceptions::BaseException`.
|
|
590
590
|
|
|
591
|
+
### Pagination information
|
|
592
|
+
Whenever you call the `all` method on one of the classes, the result will be a `Quaderno::Collection`. For example:
|
|
593
|
+
|
|
594
|
+
```ruby
|
|
595
|
+
collection = Quaderno::Contact.all(page: 2)
|
|
596
|
+
|
|
597
|
+
collection.class #=> Quaderno::Collection
|
|
598
|
+
collection.pagination_info #=> {:current_page=>"1", :total_pages=>"3"}
|
|
599
|
+
collection.current_page #=> "2"
|
|
600
|
+
collection.total_pages #=> "3"
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
### Thread-safe configuration
|
|
604
|
+
|
|
605
|
+
If you are managing multiple accounts you may need a thread-safe way to configure the credentials. You can do it by passing the credentials on each request:
|
|
606
|
+
|
|
607
|
+
```ruby
|
|
608
|
+
Quaderno::Invoice.all(
|
|
609
|
+
api_url: 'https://my_subdomain.quadernoapp.com/api/',
|
|
610
|
+
auth_token: 'my_authenticate_token'
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
Quaderno::Invoice.find(INVOICE_ID,
|
|
614
|
+
api_url: 'https://my_subdomain.quadernoapp.com/api/',
|
|
615
|
+
auth_token: 'my_authenticate_token'
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
Quaderno::Invoice.update(INVOICE_ID,
|
|
619
|
+
po_number: '12345',
|
|
620
|
+
api_url: 'https://my_subdomain.quadernoapp.com/api/',
|
|
621
|
+
auth_token: 'my_authenticate_token'
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
invoice = Quaderno::Invoice.find(INVOICE_ID,
|
|
625
|
+
api_url: 'https://my_subdomain.quadernoapp.com/api/',
|
|
626
|
+
auth_token: 'my_authenticate_token'
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
invoice.add_payment(params) # Credentials are already stored on the Quaderno::Invoice instance from the first request
|
|
630
|
+
|
|
631
|
+
invoice = Quaderno::Invoice.find(INVOICE_ID,
|
|
632
|
+
api_url: 'https://my_subdomain.quadernoapp.com/api/',
|
|
633
|
+
auth_token: 'my_authenticate_token'
|
|
634
|
+
)
|
|
635
|
+
invoice.remove_payment(PAYMENT_ID) # Credentials are already stored on the Quaderno::Invoice instance from the first request
|
|
636
|
+
|
|
637
|
+
Quaderno::Invoice.delete(INVOICE_ID,
|
|
638
|
+
api_url: 'https://my_subdomain.quadernoapp.com/api/',
|
|
639
|
+
auth_token: 'my_authenticate_token'
|
|
640
|
+
)
|
|
641
|
+
```
|
|
642
|
+
|
|
591
643
|
## More information
|
|
592
644
|
|
|
593
645
|
Remember this is only a ruby wrapper for the original API. If you want more information about the API itself, head to the original [API documentation](https://quaderno.io/docs/api/).
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.12.0
|
data/changelog.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#Changelog
|
|
2
|
+
##1.12.0
|
|
3
|
+
* Added thread-safe credentials configuration.
|
|
4
|
+
* `all` methods returns a `Quaderno::Object` with pagination info instead of an `Array`
|
|
2
5
|
|
|
3
6
|
##1.11.2
|
|
4
7
|
* Specify `Content-Type` header so `HTTParty` don't merge the elements within the body content.
|
data/lib/quaderno-ruby/base.rb
CHANGED
|
@@ -6,6 +6,7 @@ module Quaderno
|
|
|
6
6
|
include HTTParty
|
|
7
7
|
include Quaderno::Exceptions
|
|
8
8
|
include Quaderno::Behavior::Crud
|
|
9
|
+
include Quaderno::Helpers::Authentication
|
|
9
10
|
|
|
10
11
|
PRODUCTION_URL = 'https://quadernoapp.com/api/'
|
|
11
12
|
SANDBOX_URL = 'http://sandbox-quadernoapp.com/api/'
|
|
@@ -58,9 +59,18 @@ module Quaderno
|
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
#Check the connection
|
|
61
|
-
def self.ping
|
|
62
|
+
def self.ping(options = {})
|
|
62
63
|
begin
|
|
63
|
-
|
|
64
|
+
options[:auth_token] ||= auth_token
|
|
65
|
+
options[:url] ||= url
|
|
66
|
+
|
|
67
|
+
authentication = get_authentication(options)
|
|
68
|
+
|
|
69
|
+
party_response = get("#{authentication[:url]}ping.json",
|
|
70
|
+
basic_auth: authentication[:basic_auth],
|
|
71
|
+
headers: version_header.merge(authentication[:headers])
|
|
72
|
+
)
|
|
73
|
+
|
|
64
74
|
check_exception_for(party_response, { subdomain_or_token: true })
|
|
65
75
|
rescue Errno::ECONNREFUSED
|
|
66
76
|
return false
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
module Quaderno
|
|
2
2
|
module Behavior
|
|
3
3
|
module Crud
|
|
4
|
+
|
|
4
5
|
def self.included(receiver)
|
|
5
6
|
receiver.send :extend, ClassMethods
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
module ClassMethods
|
|
10
|
+
include Quaderno::Helpers::Authentication
|
|
11
|
+
|
|
9
12
|
def parse_nested(element)
|
|
10
13
|
if element.has_key?('payments')
|
|
11
14
|
payments_collection = Array.new
|
|
@@ -21,14 +24,23 @@ module Quaderno
|
|
|
21
24
|
element
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
def all(
|
|
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
|
+
|
|
26
37
|
check_exception_for(response, { rate_limit: true, subdomain_or_token: true })
|
|
27
38
|
array = response.parsed_response
|
|
28
|
-
collection =
|
|
39
|
+
collection = Quaderno::Collection.new
|
|
29
40
|
|
|
30
41
|
if is_a_document?
|
|
31
42
|
array.each do |element|
|
|
43
|
+
element[:authentication_data] = authentication
|
|
32
44
|
api_model.parse_nested(element)
|
|
33
45
|
collection << (new element)
|
|
34
46
|
end
|
|
@@ -36,41 +48,74 @@ module Quaderno
|
|
|
36
48
|
array.each { |element| collection << (new element) }
|
|
37
49
|
end
|
|
38
50
|
|
|
51
|
+
collection.current_page = response.headers['x-pages-currentpage']
|
|
52
|
+
collection.total_pages = response.headers['x-pages-totalpages']
|
|
53
|
+
|
|
39
54
|
collection
|
|
40
55
|
end
|
|
41
56
|
|
|
42
|
-
def find(id)
|
|
43
|
-
|
|
57
|
+
def find(id, options = {})
|
|
58
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
|
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
|
+
)
|
|
64
|
+
|
|
44
65
|
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
|
45
66
|
hash = response.parsed_response
|
|
67
|
+
hash[:authentication_data] = authentication
|
|
46
68
|
|
|
47
69
|
api_model.parse_nested(hash) if is_a_document?
|
|
48
70
|
|
|
49
71
|
new hash
|
|
50
72
|
end
|
|
51
73
|
|
|
52
|
-
def create(params)
|
|
53
|
-
|
|
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 }
|
|
77
|
+
|
|
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
|
+
)
|
|
83
|
+
|
|
54
84
|
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, required_fields: true })
|
|
55
85
|
hash = response.parsed_response
|
|
86
|
+
hash[:authentication_data] = authentication
|
|
56
87
|
|
|
57
88
|
api_model.parse_nested(hash) if is_a_document?
|
|
58
89
|
|
|
59
90
|
new hash
|
|
60
91
|
end
|
|
61
92
|
|
|
62
|
-
def update(id, params)
|
|
63
|
-
|
|
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 }
|
|
96
|
+
|
|
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
|
+
)
|
|
102
|
+
|
|
64
103
|
check_exception_for(response, { rate_limit: true, required_fields: true, subdomain_or_token: true, id: true })
|
|
65
104
|
hash = response.parsed_response
|
|
105
|
+
hash[:authentication_data] = authentication
|
|
66
106
|
|
|
67
107
|
api_model.parse_nested(hash) if is_a_document?
|
|
68
108
|
|
|
69
109
|
new hash
|
|
70
110
|
end
|
|
71
111
|
|
|
72
|
-
def delete(id)
|
|
73
|
-
|
|
112
|
+
def delete(id, options = {})
|
|
113
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
|
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
|
+
)
|
|
74
119
|
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true, has_documents: true })
|
|
75
120
|
|
|
76
121
|
true
|
|
@@ -7,8 +7,16 @@ module Quaderno
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
module InstanceMethods
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
include Quaderno::Helpers::Authentication
|
|
11
|
+
|
|
12
|
+
def deliver(options = nil)
|
|
13
|
+
self.authentication_data = get_authentication(options.merge(api_model: api_model)) if options.is_a?(Hash)
|
|
14
|
+
|
|
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
|
+
)
|
|
19
|
+
|
|
12
20
|
api_model.check_exception_for(party_response, { rate_limit: true, subdomain_or_token: true, id: true, required_fields: true })
|
|
13
21
|
{ limit: party_response.headers["x-ratelimit-limit"].to_i, remaining: party_response.headers["x-ratelimit-remaining"].to_i }
|
|
14
22
|
end
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
module Quaderno
|
|
2
2
|
module Behavior
|
|
3
3
|
module Payment
|
|
4
|
+
|
|
4
5
|
def self.included(base)
|
|
5
6
|
base.send :include, InstanceMethods
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
module InstanceMethods
|
|
10
|
+
include Quaderno::Helpers::Authentication
|
|
11
|
+
|
|
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
|
|
17
|
+
|
|
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
|
+
)
|
|
9
23
|
|
|
10
|
-
def add_payment(params)
|
|
11
|
-
response = api_model.post "#{api_model.url}#{ api_model.api_path }/#{ id }/payments.json", body: params, basic_auth: { username: api_model.auth_token }, headers: self.class.version_header
|
|
12
24
|
api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, required_fields: true })
|
|
13
25
|
|
|
14
26
|
instance = Quaderno::Payment.new(response.parsed_response)
|
|
@@ -17,8 +29,15 @@ module Quaderno
|
|
|
17
29
|
Quaderno::Payment.new instance
|
|
18
30
|
end
|
|
19
31
|
|
|
20
|
-
def remove_payment(payment_id)
|
|
21
|
-
|
|
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)
|
|
34
|
+
|
|
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
|
+
)
|
|
40
|
+
|
|
22
41
|
api_model.check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
|
23
42
|
|
|
24
43
|
self.payments.delete_if { |payment| payment.id == payment_id }
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
module Quaderno
|
|
2
2
|
module Behavior
|
|
3
3
|
module Retrieve
|
|
4
|
+
|
|
4
5
|
def self.included(receiver)
|
|
5
6
|
receiver.send :extend, ClassMethods
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
module ClassMethods
|
|
10
|
+
include Quaderno::Helpers::Authentication
|
|
11
|
+
|
|
12
|
+
def retrieve(gateway_id, gateway = 'stripe', options = {})
|
|
13
|
+
authentication = get_authentication(options.merge(api_model: api_model))
|
|
14
|
+
|
|
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
|
+
)
|
|
9
19
|
|
|
10
|
-
def retrieve(gateway_id, gateway = nil)
|
|
11
|
-
response = get "#{api_model.url}#{gateway || 'stripe'}/#{@_retrieve_path}/#{gateway_id}.json", basic_auth: { username: api_model.auth_token }, headers: version_header
|
|
12
20
|
check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true })
|
|
13
21
|
hash = response.parsed_response
|
|
22
|
+
hash[:authentication_data] = authentication
|
|
14
23
|
|
|
15
24
|
new hash
|
|
16
25
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class Quaderno::Collection < Array
|
|
2
|
+
|
|
3
|
+
def current_page=(page_number)
|
|
4
|
+
@page = page_number
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def current_page
|
|
8
|
+
@page || 1
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def total_pages=(total_pages)
|
|
12
|
+
@total_pages = total_pages
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def total_pages
|
|
16
|
+
@total_pages || 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def pagination_info
|
|
20
|
+
{ current_page: current_page, total_pages: total_pages }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Quaderno
|
|
2
|
+
module Helpers
|
|
3
|
+
module Authentication
|
|
4
|
+
|
|
5
|
+
def get_authentication(options = {})
|
|
6
|
+
mode = options[:mode] || :production
|
|
7
|
+
|
|
8
|
+
local_api_model = options[:api_model]
|
|
9
|
+
url = options[:api_url] || (local_api_model && local_api_model.url) || (mode == :production ? 'https://quadernoapp.com/api/' : 'http://sandbox-quadernoapp.com/api/')
|
|
10
|
+
|
|
11
|
+
auth_token = options[:auth_token] || options['auth_token'] || (local_api_model && local_api_model.auth_token)
|
|
12
|
+
access_token = options[:access_token] || options['access_token']
|
|
13
|
+
|
|
14
|
+
authentication = { url: url, headers: {}, basic_auth: nil }
|
|
15
|
+
|
|
16
|
+
if access_token
|
|
17
|
+
authentication[:headers] = { 'Authorization' => "Bearer #{access_token}" }
|
|
18
|
+
elsif auth_token
|
|
19
|
+
authentication[:basic_auth] = { username: auth_token }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
authentication
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/quaderno-ruby.rb
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
require 'ostruct'
|
|
2
2
|
|
|
3
3
|
require 'quaderno-ruby/exceptions/exceptions'
|
|
4
|
-
|
|
4
|
+
require 'quaderno-ruby/helpers/authentication'
|
|
5
|
+
require 'quaderno-ruby/collection'
|
|
6
|
+
|
|
7
|
+
%w(crud deliver payment retrieve).each { |filename| require "quaderno-ruby/behavior/#{filename}" }
|
|
5
8
|
%w(base contact item invoice receipt credit estimate expense recurring document_item evidence payment webhook tax).each { |filename| require "quaderno-ruby/#{ filename }" }
|
|
6
9
|
|
|
7
10
|
module Quaderno
|
data/quaderno.gemspec
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: quaderno 1.
|
|
5
|
+
# stub: quaderno 1.12.0 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "quaderno"
|
|
9
|
-
s.version = "1.
|
|
9
|
+
s.version = "1.12.0"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib"]
|
|
13
13
|
s.authors = ["Recrea"]
|
|
14
|
-
s.date = "2017-
|
|
14
|
+
s.date = "2017-06-14"
|
|
15
15
|
s.description = " A ruby wrapper for Quaderno API "
|
|
16
16
|
s.email = "carlos@recrea.es"
|
|
17
17
|
s.extra_rdoc_files = [
|
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
|
33
33
|
"lib/quaderno-ruby/behavior/deliver.rb",
|
|
34
34
|
"lib/quaderno-ruby/behavior/payment.rb",
|
|
35
35
|
"lib/quaderno-ruby/behavior/retrieve.rb",
|
|
36
|
+
"lib/quaderno-ruby/collection.rb",
|
|
36
37
|
"lib/quaderno-ruby/contact.rb",
|
|
37
38
|
"lib/quaderno-ruby/credit.rb",
|
|
38
39
|
"lib/quaderno-ruby/document_item.rb",
|
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
|
40
41
|
"lib/quaderno-ruby/evidence.rb",
|
|
41
42
|
"lib/quaderno-ruby/exceptions/exceptions.rb",
|
|
42
43
|
"lib/quaderno-ruby/expense.rb",
|
|
44
|
+
"lib/quaderno-ruby/helpers/authentication.rb",
|
|
43
45
|
"lib/quaderno-ruby/invoice.rb",
|
|
44
46
|
"lib/quaderno-ruby/item.rb",
|
|
45
47
|
"lib/quaderno-ruby/payment.rb",
|
|
@@ -50,18 +52,21 @@ Gem::Specification.new do |s|
|
|
|
50
52
|
"quaderno.gemspec",
|
|
51
53
|
"test/fixtures/quaderno_cassettes/.DS_Store",
|
|
52
54
|
"test/fixtures/quaderno_cassettes/all_contacts.yml",
|
|
55
|
+
"test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml",
|
|
56
|
+
"test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml",
|
|
53
57
|
"test/fixtures/quaderno_cassettes/all_estimates.yml",
|
|
54
58
|
"test/fixtures/quaderno_cassettes/all_expenses.yml",
|
|
55
59
|
"test/fixtures/quaderno_cassettes/all_invoices.yml",
|
|
56
60
|
"test/fixtures/quaderno_cassettes/all_items.yml",
|
|
57
61
|
"test/fixtures/quaderno_cassettes/all_receipts.yml",
|
|
58
62
|
"test/fixtures/quaderno_cassettes/all_webhooks.yml",
|
|
59
|
-
"test/fixtures/quaderno_cassettes/calculate_tax.yml",
|
|
60
63
|
"test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml",
|
|
61
64
|
"test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml",
|
|
62
65
|
"test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml",
|
|
63
66
|
"test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml",
|
|
64
67
|
"test/fixtures/quaderno_cassettes/deleted_contact.yml",
|
|
68
|
+
"test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml",
|
|
69
|
+
"test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml",
|
|
65
70
|
"test/fixtures/quaderno_cassettes/deleted_estimate.yml",
|
|
66
71
|
"test/fixtures/quaderno_cassettes/deleted_expense.yml",
|
|
67
72
|
"test/fixtures/quaderno_cassettes/deleted_invoice.yml",
|
|
@@ -73,6 +78,8 @@ Gem::Specification.new do |s|
|
|
|
73
78
|
"test/fixtures/quaderno_cassettes/delivered_receipt.yml",
|
|
74
79
|
"test/fixtures/quaderno_cassettes/evidence_invoice.yml",
|
|
75
80
|
"test/fixtures/quaderno_cassettes/found_contact.yml",
|
|
81
|
+
"test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml",
|
|
82
|
+
"test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml",
|
|
76
83
|
"test/fixtures/quaderno_cassettes/found_estimate.yml",
|
|
77
84
|
"test/fixtures/quaderno_cassettes/found_expense.yml",
|
|
78
85
|
"test/fixtures/quaderno_cassettes/found_invoice.yml",
|
|
@@ -80,6 +87,8 @@ Gem::Specification.new do |s|
|
|
|
80
87
|
"test/fixtures/quaderno_cassettes/found_receipt.yml",
|
|
81
88
|
"test/fixtures/quaderno_cassettes/found_webhook.yml",
|
|
82
89
|
"test/fixtures/quaderno_cassettes/new_contact.yml",
|
|
90
|
+
"test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml",
|
|
91
|
+
"test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml",
|
|
83
92
|
"test/fixtures/quaderno_cassettes/new_estimate.yml",
|
|
84
93
|
"test/fixtures/quaderno_cassettes/new_evidence.yml",
|
|
85
94
|
"test/fixtures/quaderno_cassettes/new_expense.yml",
|
|
@@ -93,6 +102,8 @@ Gem::Specification.new do |s|
|
|
|
93
102
|
"test/fixtures/quaderno_cassettes/unpay_an_expense.yml",
|
|
94
103
|
"test/fixtures/quaderno_cassettes/unpay_an_invoice.yml",
|
|
95
104
|
"test/fixtures/quaderno_cassettes/updated_contact.yml",
|
|
105
|
+
"test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml",
|
|
106
|
+
"test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml",
|
|
96
107
|
"test/fixtures/quaderno_cassettes/updated_estimate.yml",
|
|
97
108
|
"test/fixtures/quaderno_cassettes/updated_expense.yml",
|
|
98
109
|
"test/fixtures/quaderno_cassettes/updated_invoice.yml",
|
|
@@ -101,9 +112,9 @@ Gem::Specification.new do |s|
|
|
|
101
112
|
"test/fixtures/quaderno_cassettes/updated_webhook.yml",
|
|
102
113
|
"test/fixtures/quaderno_cassettes/validate_invalid_VAT_number.yml",
|
|
103
114
|
"test/fixtures/quaderno_cassettes/validate_valid_VAT_number.yml",
|
|
104
|
-
"test/fixtures/quaderno_cassettes/wrong_token.yml",
|
|
105
115
|
"test/helper.rb",
|
|
106
116
|
"test/unit/test_quaderno_contacts.rb",
|
|
117
|
+
"test/unit/test_quaderno_contacts_thread_safe.rb",
|
|
107
118
|
"test/unit/test_quaderno_estimates.rb",
|
|
108
119
|
"test/unit/test_quaderno_evidences.rb",
|
|
109
120
|
"test/unit/test_quaderno_expenses.rb",
|