Class: ZipTax::SalesTax
- Inherits:
-
Object
- Object
- ZipTax::SalesTax
- Defined in:
- lib/zip_tax/sales_tax.rb
Constant Summary collapse
- BASE_URL =
"http://api.zip-tax.com/request/v20"
Instance Attribute Summary collapse
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#postalcode ⇒ Object
readonly
Returns the value of attribute postalcode.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(postalcode: nil, state: nil, city: nil) ⇒ SalesTax
constructor
A new instance of SalesTax.
- #request_tax ⇒ Object
- #request_url ⇒ Object
Constructor Details
#initialize(postalcode: nil, state: nil, city: nil) ⇒ SalesTax
Returns a new instance of SalesTax.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/zip_tax/sales_tax.rb', line 11 def initialize(postalcode: nil, state: nil, city: nil) fail ArgumentError, 'ZipTax.api_key must be set' if ZipTax.api_key.nil? fail ArgumentError, "postalcode is a required argument" if !postalcode @key = key @postalcode = postalcode.to_s @state = state @city = city @format = 'json' end |
Instance Attribute Details
#city ⇒ Object (readonly)
Returns the value of attribute city.
7 8 9 |
# File 'lib/zip_tax/sales_tax.rb', line 7 def city @city end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/zip_tax/sales_tax.rb', line 7 def format @format end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/zip_tax/sales_tax.rb', line 7 def key @key end |
#postalcode ⇒ Object (readonly)
Returns the value of attribute postalcode.
7 8 9 |
# File 'lib/zip_tax/sales_tax.rb', line 7 def postalcode @postalcode end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
7 8 9 |
# File 'lib/zip_tax/sales_tax.rb', line 7 def state @state end |
Class Method Details
.request_for(postalcode: nil, state: nil, city: nil) ⇒ Object
36 37 38 39 40 |
# File 'lib/zip_tax/sales_tax.rb', line 36 def self.request_for(postalcode: nil, state: nil, city: nil) rt = self.new(postalcode: postalcode, state: state, city: city) rt.request_tax end |
Instance Method Details
#request_tax ⇒ Object
30 31 32 33 34 |
# File 'lib/zip_tax/sales_tax.rb', line 30 def request_tax url = URI(request_url) resp = Net::HTTP.get(url) ZipTax::Response.new_from_http_request(resp) end |