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(key: nil, postalcode: nil, state: nil, city: nil) ⇒ SalesTax
constructor
A new instance of SalesTax.
- #request_tax ⇒ Object
- #request_url ⇒ Object
Constructor Details
#initialize(key: nil, 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(key: nil, postalcode: nil, state: nil, city: nil) fail ArgumentError, "postalcode and key (api key) are required arguments" if !key || !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(key: nil, postalcode: nil, state: nil, city: nil) ⇒ Object
35 36 37 38 39 |
# File 'lib/zip_tax/sales_tax.rb', line 35 def self.request_for(key: nil, postalcode: nil, state: nil, city: nil) rt = self.new(key: key, postalcode: postalcode, state: state, city: city) rt.request_tax end |
Instance Method Details
#request_tax ⇒ Object
29 30 31 32 33 |
# File 'lib/zip_tax/sales_tax.rb', line 29 def request_tax url = URI(request_url) resp = Net::HTTP.get(url) ZipTax::Response.new_from_http_request(resp) end |
#request_url ⇒ Object
24 25 26 27 |
# File 'lib/zip_tax/sales_tax.rb', line 24 def request_url query = {key: @key, postalcode: @postalcode, state: @state, city: @city, format: @format} "#{BASE_URL}?#{Rack::Utils.build_query(query)}" end |