Skip to content

Commit b3f39dd

Browse files
authored
Merge pull request #30 from quaderno/connect-features
Add support for connect features
2 parents 658d3a5 + 01395f9 commit b3f39dd

File tree

75 files changed

+7111
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+7111
-30
lines changed

README.md

+181-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Quaderno-ruby is a ruby wrapper for the [Quaderno API](https://developers.quaderno.io/api).
44

5-
Current version is 2.2.0 → See the changelog [here](https://github.com/quaderno/quaderno-ruby/blob/master/changelog.md).
5+
Current version is 3.0.0 → See the changelog [here](https://github.com/quaderno/quaderno-ruby/blob/master/changelog.md).
66

77
To learn more about our API and ecosystem, check [developers.quaderno.io](https://developers.quaderno.io).
88

@@ -132,8 +132,6 @@ will return the contact with the id passed as parameter.
132132

133133
will return the contact with the customer id passed as parameter.
134134

135-
*_Note_: `Quaderno::Contact.retrieve_customer` has been deprecated in favor of `Quaderno::Contact.retrieve`
136-
137135
### Creating a new contact
138136

139137
```ruby
@@ -567,23 +565,101 @@ will update the specified webhook with the data of the hash passed as second par
567565

568566
will delete the webhook with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::Webhook` with the `deleted` attribute set to `true` will be returned.
569567

570-
## Taxes
568+
## Tax rates
571569

572570
### Calculating taxes
573571

574572
```ruby
575-
Quaderno::Tax.calculate(params) #=> Quaderno::Tax
573+
Quaderno::TaxRate.calculate(params) #=> Quaderno::TaxRate
576574
```
577575

578576
will calculate the taxes applied for a customer based on the data pased as parameters.
579577

580-
### Validate tax ID
578+
## Tax jurisdictions
579+
580+
### Listing tax jurisdictions
581+
582+
```ruby
583+
Quaderno::TaxJurisdiction.all #=> Array
584+
```
585+
586+
will return an array with all the tax jurisdictions supported in Quaderno.
587+
588+
### Finding a tax jurisdiction
589+
590+
```ruby
591+
Quaderno::TaxJurisdiction.find(id) #=> Quaderno::TaxJurisdiction
592+
```
593+
594+
will return the tax jurisdiction with the id passed as parameter.
595+
596+
## Tax codes
597+
598+
### Listing tax codes
599+
600+
```ruby
601+
Quaderno::TaxCode.all #=> Array
602+
```
603+
604+
will return an array with all the tax codes supported in Quaderno.
605+
606+
### Finding a tax jurisdiction
607+
608+
```ruby
609+
Quaderno::TaxCode.find(id) #=> Quaderno::TaxCode
610+
```
611+
612+
will return the tax code with the id passed as parameter.
613+
614+
## Managing Tax ids
615+
616+
### Getting tax ids
617+
618+
```ruby
619+
Quaderno::TaxId.all #=> Array
620+
```
621+
622+
will return an array with all the tax ids in the target account.
623+
624+
### Finding a tax id
625+
626+
```ruby
627+
Quaderno::TaxId.find(id) #=> Quaderno::TaxId
628+
```
629+
630+
will return the tax id with the id passed as parameter.
631+
632+
### Adding a new tax id
633+
634+
```ruby
635+
Quaderno::TaxId.create(params) #=> Quaderno::TaxId
636+
```
637+
638+
will create a tax id using the information of the hash passed as parameter and return an instance of Quaderno::TaxId with the created tax id.
639+
640+
### Updating an existing tax id
641+
642+
```ruby
643+
Quaderno::TaxId.update(id, params) #=> Quaderno::TaxId
644+
```
645+
646+
will update the specified tax id with the data of the hash passed as second parameter.
647+
648+
### Deleting a tax id
649+
650+
```ruby
651+
Quaderno::TaxId.delete(id) #=> Quaderno::TaxId
652+
```
653+
654+
will delete the tax id with the id passed as parameter. If the deletion was successful, an instance of `Quaderno::TaxId` with the `deleted` attribute set to `true` will be returned.
655+
656+
### Validate a tax id
581657

582658
```ruby
583659
country = 'IE'
584660
tax_id = 'IE6388047V'
585661

586-
result = Quaderno::Tax.validate_tax_id(country, tax_id) #=> Quaderno::Tax
662+
result = Quaderno::TaxId.validate(country, tax_id) #=> Quaderno::TaxId
587663

588664
result.valid #=> Boolean or nil
589665
```
@@ -667,6 +743,91 @@ will return the report request with the id passed as parameter.
667743

668744
will create a report request using the information of the hash passed as parameter and return an instance of Quaderno::ReportRequest with the created report request.
669745

746+
## Connect: Managing custom accounts
747+
748+
### Getting custom accounts
749+
750+
```ruby
751+
Quaderno::Account.all #=> Array
752+
```
753+
754+
will return an array with all your custom accounts
755+
756+
### Finding a custom account
757+
758+
```ruby
759+
Quaderno::Account.find(id) #=> Quaderno::Account
760+
```
761+
762+
will return the account with the id passed as parameter.
763+
764+
### Creating a new custom account
765+
766+
```ruby
767+
Quaderno::Account.create(params) #=> Quaderno::Account
768+
```
769+
770+
will create a custom account using the information of the hash passed as parameter.
771+
772+
### Updating an existing custom account
773+
774+
```ruby
775+
Quaderno::Account.update(id, params) #=> Quaderno::Account
776+
```
777+
778+
will update the specified custom account with the data of the hash passed as second parameter.
779+
780+
### Deactivating a custom account
781+
782+
```ruby
783+
Quaderno::Account.deactivate(id) #=> Quaderno::Account
784+
```
785+
786+
will deactivate the custom account with the id passed as parameter.
787+
788+
### Activating a custom account
789+
790+
```ruby
791+
Quaderno::Account.activate(id) #=> Quaderno::Account
792+
```
793+
794+
will activate the custom account with the id passed as parameter.
795+
796+
## Connect: Managing addresses
797+
798+
### Getting addresses
799+
800+
```ruby
801+
Quaderno::Address.all(access_token: ACCESS_TOKEN) #=> Array
802+
```
803+
804+
will return an array with all the addresses of the target custom account
805+
806+
### Finding a address
807+
808+
```ruby
809+
Quaderno::Address.find(id, access_token: ACCESS_TOKEN) #=> Quaderno::Address
810+
```
811+
812+
will return the address with the id passed as parameter.
813+
814+
### Creating a new address
815+
816+
```ruby
817+
Quaderno::Address.create(params.merge(access_token: ACCESS_TOKEN)) #=> Quaderno::Address
818+
```
819+
820+
will add an address on the target custom account using the information of the hash passed as parameter.
821+
822+
### Updating an existing address
823+
824+
```ruby
825+
Quaderno::Address.update(id, params.merge(access_token: ACCESS_TOKEN)) #=> Quaderno::Address
826+
```
827+
828+
will update the specified address with the data of the hash passed as second parameter.
829+
830+
670831
## Exceptions
671832

672833
Quaderno-ruby exceptions raise depending on the type of error:
@@ -678,6 +839,8 @@ Quaderno-ruby exceptions raise depending on the type of error:
678839

679840
Quaderno::Exceptions::InvalidID # Raised when the requested resource by ID does not exist in the account context.
680841

842+
Quaderno::Exceptions::InvalidRequest # Raised when the requested requirements are not fulfilled.
843+
681844
Quaderno::Exceptions::ThrottleLimitExceeded # Raised when the throttle limit is exceeded.
682845

683846
Quaderno::Exceptions::RateLimitExceeded # Raised when the rate limit is exceeded.
@@ -691,6 +854,17 @@ Quaderno-ruby exceptions raise depending on the type of error:
691854

692855
All those exceptions inherit from `Quaderno::Exceptions::BaseException`.
693856

857+
You can inspect a the error response from the API by rescuing the exception and checking `response_body`:
858+
859+
```ruby
860+
begin
861+
Quaderno::Invoice.find WRONG_ID
862+
rescue Quaderno::Exceptions::BaseException => e
863+
e.response_body # => {"error"=>"Unauthorized access or document does not exist."}
864+
end
865+
```
866+
867+
694868
### Pagination information
695869

696870
Whenever you call the `all` method on one of the classes, the result will be a `Quaderno::Collection`. For example:

changelog.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## 3.0.0
4+
* Added support for accounts API
5+
* Added support for addresses API
6+
* Added support for tax rates API
7+
* Added support for tax jurisdictions API
8+
* Added support for tax codes API
9+
* Clean parameters sent in the create request
10+
* Phase out legacy `Quaderno::Tax` class in favour of `Quaderno::TaxRate` (the class will be removed in the next release)
11+
* Relaxed httparty requirements
12+
* Detect and handle `bad_request` response codes
13+
* Added `Quaderno::Exceptions::InvalidRequest` to handle `not_acceptable` response codes
14+
* Added `Quaderno::Exceptions::BaseException#response_body` to check the API response error
15+
* Removed legacy `Quaderno::Contact.retrieve_customer` in favor of `Quaderno::Contact.retrieve`
16+
317
## 2.2.0
418
* Added support for transactions API
519
* Bumped webmock to 3.18

lib/quaderno-ruby.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class Quaderno
77

88
require 'quaderno-ruby/version'
99
require 'quaderno-ruby/helpers/rate_limit'
10+
require 'quaderno-ruby/helpers/response'
1011
require 'quaderno-ruby/exceptions/exceptions'
1112
require 'quaderno-ruby/helpers/authentication'
1213
require 'quaderno-ruby/collection'
1314

14-
%w(block crud deliver payment retrieve).each { |filename| require "quaderno-ruby/behavior/#{filename}" }
15-
%w(base contact item transaction invoice receipt credit income estimate expense recurring document_item report report_request evidence payment webhook tax checkout_session).each { |filename| require "quaderno-ruby/#{filename}" }
15+
%w[block crud deliver payment retrieve].each { |filename| require "quaderno-ruby/behavior/#{filename}" }
16+
%w[base account address contact item transaction invoice receipt credit income estimate expense recurring document_item report report_request evidence payment webhook tax tax_id tax_rate tax_code tax_jurisdiction checkout_session].each { |filename| require "quaderno-ruby/#{filename}" }

lib/quaderno-ruby/account.rb

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
class Quaderno::Account < Quaderno::Base
4+
class << self
5+
undef :delete
6+
end
7+
8+
api_model Quaderno::Account
9+
api_path 'accounts'
10+
11+
def self.activate(id, options = {})
12+
setup_account('activate', id, options)
13+
end
14+
15+
def self.deactivate(id, options = {})
16+
setup_account('deactivate', id, options)
17+
end
18+
19+
private_class_method def self.setup_account(mode, id, options)
20+
authentication = get_authentication(options.merge(api_model: api_model))
21+
22+
response = put("#{authentication[:url]}#{api_model.api_path}/#{id}/#{mode}.json", {
23+
basic_auth: authentication[:basic_auth],
24+
headers: default_headers.merge(authentication[:headers]).merge('Content-Type' => 'application/json')
25+
})
26+
27+
check_exception_for(response, { rate_limit: true, required_fields: true, subdomain_or_token: true, id: true })
28+
29+
hash = response.parsed_response
30+
hash[:authentication_data] = authentication
31+
32+
object = new hash
33+
object.rate_limit_info = response
34+
35+
object
36+
end
37+
end

lib/quaderno-ruby/address.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class Quaderno::Address < Quaderno::Base
4+
api_model Quaderno::Address
5+
api_path 'addresses'
6+
7+
class << self
8+
undef :delete
9+
end
10+
end

lib/quaderno-ruby/behavior/crud.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
module Quaderno::Behavior
44
module Crud
5-
65
def self.included(receiver)
76
receiver.send :extend, ClassMethods
87
end
@@ -71,7 +70,7 @@ def find(id, options = {})
7170

7271
def create(params = {})
7372
authentication = get_authentication(params.merge(api_model: api_model))
74-
params.dup.delete_if { |k, _| %w[auth_token access_token api_url mode api_model].include? k.to_s }
73+
params = params.dup.delete_if { |k, _| %w[auth_token access_token api_url mode api_model].include? k.to_s }
7574

7675
response = post("#{authentication[:url]}#{api_model.api_path}.json",
7776
body: params.to_json,

lib/quaderno-ruby/behavior/retrieve.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# frozen_string_literal: true
2+
13
module Quaderno::Behavior
24
module Retrieve
3-
45
def self.included(receiver)
56
receiver.send :extend, ClassMethods
67
end
@@ -25,9 +26,9 @@ def retrieve(gateway_id, gateway = 'stripe', options = {})
2526

2627
object
2728
end
28-
alias_method :retrieve_customer, :retrieve
2929

3030
private
31+
3132
def retrieve_path(path)
3233
@_retrieve_path = path
3334
end

0 commit comments

Comments
 (0)