Class: Quaderno::Tax
Constant Summary
Constants inherited from Base
Base::PRODUCTION_URL, Base::SANDBOX_URL
Class Method Summary collapse
- .calculate(options = {}) ⇒ Object
- .reports(options = {}) ⇒ Object
- .validate_tax_id(country, tax_id, options = {}) ⇒ Object
Methods inherited from Base
api_model, api_version=, auth_token=, authorization, configure, me, ping, #to_hash, url=, user_agent_header=
Methods included from Helpers::RateLimit
#rate_limit_info, #rate_limit_info=
Methods included from Helpers::Authentication
Methods included from Behavior::Crud
Methods included from Exceptions
Class Method Details
.calculate(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/quaderno-ruby/tax.rb', line 12 def self.calculate( = {}) authentication = get_authentication(.merge(api_model: api_model)) params = .dup.delete_if { |k,v| %w(auth_token access_token api_url mode api_model).include? k.to_s } response = get("#{authentication[:url]}tax_rates/calculate.json", query: params, basic_auth: authentication[:basic_auth], headers: default_headers.merge(authentication[:headers]) ) check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true }) data = new response.parsed_response data.rate_limit_info = response data end |
.reports(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/quaderno-ruby/tax.rb', line 48 def self.reports( = {}) authentication = get_authentication(.merge(api_model: api_model)) params = .dup.delete_if { |k,v| %w(auth_token access_token api_url mode api_model).include? k.to_s } response = get("#{authentication[:url]}taxes/reports.json", query: params, basic_auth: authentication[:basic_auth], headers: default_headers.merge(authentication[:headers]) ) array = response.parsed_response collection = Quaderno::Collection.new collection.rate_limit_info = response collection.current_page = response.headers['x-pages-currentpage'] collection.total_pages = response.headers['x-pages-totalpages'] array.each { |report| collection << Quaderno::TaxReport.new(report) } check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true }) collection end |
.validate_tax_id(country, tax_id, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/quaderno-ruby/tax.rb', line 29 def self.validate_tax_id(country, tax_id, = {}) authentication = get_authentication(.merge(api_model: api_model)) response = get("#{authentication[:url]}tax_ids/validate.json", query: { country: country, tax_id: tax_id }, basic_auth: authentication[:basic_auth], headers: default_headers.merge(authentication[:headers]) ) check_exception_for(response, { rate_limit: true, subdomain_or_token: true, id: true }) data = new({ valid: response.parsed_response['valid'] }) data.rate_limit_info = response data end |