Class: Taxbear::Taxjar

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/taxbear/taxjar.rb

Class Method Summary collapse

Class Method Details

.get_rates_by_zipcode(zipcode) ⇒ Hash

Gets tax rates from TaxJar API based on zipcode.

Parameters:

  • zipcode (Integer)

    the zip code

Returns:

  • (Hash)

    the rates returned by API



16
17
18
19
20
21
22
23
24
25
# File 'lib/taxbear/taxjar.rb', line 16

def get_rates_by_zipcode(zipcode)
  require_api_key()
  response = get("/rates/#{zipcode}", {headers: auth_header})

  if response.success?
    response.fetch("rate")
  else
    raise TaxjarError, "Unable to get tax rates from TaxJar API."
  end
end

.validate_token(token) ⇒ Boolean

Takes a tokens and returns whether the token is valid.

Parameters:

  • token (String)

    the token

Returns:

  • (Boolean)

    whether token is valid



31
32
33
# File 'lib/taxbear/taxjar.rb', line 31

def validate_token(token)
  get("/categories", headers: auth_header(token)).success?
end