Skip to content

Commit

Permalink
Add support for addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
xxswingxx committed Jul 21, 2023
1 parent 7dabf56 commit c47e426
Show file tree
Hide file tree
Showing 15 changed files with 931 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

## 3.0.0
* Added support for accounts API
* Added support for addresses API
* Added support for tax rates API
* Added support for tax jurisdictions API
* Added support for tax codes API
* Clean parameters sent in the create request
* Phase out legacy `Quaderno::Tax` class in favour of `Quaderno::TaxRate` (the class will be removed in the next release)
* Relaxed httparty requirements
* Detect and handle `bad_request` response codes
* Added `Quaderno::Exceptions::InvalidRequest` to handle `not_acceptable` response codes
* Added `BaseException#response_body` to check the API response error

## 2.2.0
* Added support for transactions API
Expand Down
3 changes: 2 additions & 1 deletion lib/quaderno-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class Quaderno

require 'quaderno-ruby/version'
require 'quaderno-ruby/helpers/rate_limit'
require 'quaderno-ruby/helpers/response'
require 'quaderno-ruby/exceptions/exceptions'
require 'quaderno-ruby/helpers/authentication'
require 'quaderno-ruby/collection'

%w[block crud deliver payment retrieve].each { |filename| require "quaderno-ruby/behavior/#{filename}" }
%w[base account 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}" }
%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}" }
10 changes: 10 additions & 0 deletions lib/quaderno-ruby/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class Quaderno::Address < Quaderno::Base
api_model Quaderno::Address
api_path 'addresses'

class << self
undef :delete
end
end
1 change: 0 additions & 1 deletion lib/quaderno-ruby/behavior/crud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Quaderno::Behavior
module Crud

def self.included(receiver)
receiver.send :extend, ClassMethods
end
Expand Down
8 changes: 8 additions & 0 deletions lib/quaderno-ruby/exceptions/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

module Quaderno::Exceptions
class BaseException < StandardError
include Quaderno::Helpers::RateLimit
include Quaderno::Helpers::Response
end

class InvalidSubdomainOrToken < BaseException
Expand All @@ -9,6 +12,9 @@ class InvalidSubdomainOrToken < BaseException
class InvalidID < BaseException
end

class InvalidRequest < BaseException
end

class RateLimitExceeded < BaseException
end

Expand Down Expand Up @@ -63,12 +69,14 @@ def check_exception_for(party_response, params = {})
raise_exception(Quaderno::Exceptions::HasAssociatedDocuments, party_response.body, party_response)
end

raise_exception(Quaderno::Exceptions::InvalidRequest, 'Invalid request', party_response) if party_response.response.instance_of?(Net::HTTPNotAcceptable)
raise_exception(Quaderno::Exceptions::ServerError, 'Server error', party_response) if party_response.response.is_a?(Net::HTTPServerError)
end

def raise_exception(klass, message, response)
exception = klass.new(message)
exception.rate_limit_info = response
exception.response_body = response.parsed_response

raise exception
end
Expand Down
13 changes: 13 additions & 0 deletions lib/quaderno-ruby/helpers/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Quaderno::Helpers
module Response
def response_body=(response)
@response_body = response
end

def response_body
@response_body
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions spec/fixtures/quaderno_cassettes/found_address_by_access_token.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c47e426

Please sign in to comment.