From bec2e97f97c5abafaa7704d562cde2e21ddb6fb3 Mon Sep 17 00:00:00 2001 From: Jared Norman Date: Wed, 8 Jul 2020 18:35:03 -0700 Subject: Refactor API class instantiation This is used by any class that interacts with the TaxJar API and is meant to be able to be consumed by applications for custom needs, so let's just make it exposed at the top level. --- lib/super_good/solidus_taxjar.rb | 4 ++++ lib/super_good/solidus_taxjar/calculator_helper.rb | 6 ------ lib/super_good/solidus_taxjar/tax_calculator.rb | 2 +- lib/super_good/solidus_taxjar/tax_rate_calculator.rb | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb index bdd2dcd..f45db80 100644 --- a/lib/super_good/solidus_taxjar.rb +++ b/lib/super_good/solidus_taxjar.rb @@ -25,6 +25,10 @@ module SuperGood attr_accessor :taxable_address_check attr_accessor :taxable_order_check attr_accessor :test_mode + + def api + ::SuperGood::SolidusTaxJar::API.new + end end self.cache_duration = 3.hours diff --git a/lib/super_good/solidus_taxjar/calculator_helper.rb b/lib/super_good/solidus_taxjar/calculator_helper.rb index f8690b5..c4803a4 100644 --- a/lib/super_good/solidus_taxjar/calculator_helper.rb +++ b/lib/super_good/solidus_taxjar/calculator_helper.rb @@ -3,12 +3,6 @@ module SuperGood module CalculatorHelper extend ActiveSupport::Concern - class_methods do - def default_api - ::SuperGood::SolidusTaxJar::API.new - end - end - def incomplete_address?(address) return true if address.is_a?(Spree::Tax::TaxLocation) diff --git a/lib/super_good/solidus_taxjar/tax_calculator.rb b/lib/super_good/solidus_taxjar/tax_calculator.rb index 520fffe..88eee2a 100644 --- a/lib/super_good/solidus_taxjar/tax_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_calculator.rb @@ -3,7 +3,7 @@ module SuperGood class TaxCalculator include CalculatorHelper - def initialize(order, api: self.class.default_api) + def initialize(order, api: SuperGood::SolidusTaxJar.api) @order = order @api = api end diff --git a/lib/super_good/solidus_taxjar/tax_rate_calculator.rb b/lib/super_good/solidus_taxjar/tax_rate_calculator.rb index 8f513a5..f9c996c 100644 --- a/lib/super_good/solidus_taxjar/tax_rate_calculator.rb +++ b/lib/super_good/solidus_taxjar/tax_rate_calculator.rb @@ -2,7 +2,7 @@ module SuperGood module SolidusTaxJar class TaxRateCalculator include CalculatorHelper - def initialize(address, api: self.class.default_api) + def initialize(address, api: SuperGood::SolidusTaxJar.api) @address = address @api = api end -- cgit v1.2.3