summaryrefslogtreecommitdiff
path: root/lib/super_good
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2020-07-08 18:35:03 -0700
committerJared Norman <jared@super.gd>2020-07-14 13:07:55 -0700
commitbec2e97f97c5abafaa7704d562cde2e21ddb6fb3 (patch)
tree2168adadb97a5d02d2bc9626f59cb31bf5fafe66 /lib/super_good
parent68b29ea1afbb9339865493016fe196464b7ee1f4 (diff)
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.
Diffstat (limited to 'lib/super_good')
-rw-r--r--lib/super_good/solidus_taxjar.rb4
-rw-r--r--lib/super_good/solidus_taxjar/calculator_helper.rb6
-rw-r--r--lib/super_good/solidus_taxjar/tax_calculator.rb2
-rw-r--r--lib/super_good/solidus_taxjar/tax_rate_calculator.rb2
4 files changed, 6 insertions, 8 deletions
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