Class: Taxjar::API::Request
- Inherits:
-
Object
- Object
- Taxjar::API::Request
- Defined in:
- lib/taxjar/api/request.rb
Constant Summary collapse
- DEFAULT_API_URL =
'https://api.taxjar.com'
- SANDBOX_API_URL =
'https://api.sandbox.taxjar.com'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#object_key ⇒ Object
readonly
Returns the value of attribute object_key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(client, request_method, path, object_key, options = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(client, request_method, path, object_key, options = {}) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/taxjar/api/request.rb', line 16 def initialize(client, request_method, path, object_key, = {}) @client = client @request_method = request_method @path = path @base_url = client.api_url ? client.api_url : DEFAULT_API_URL @uri = Addressable::URI.parse(@base_url + path) set_request_headers(client.headers || {}) @object_key = object_key @options = set_http_timeout end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def client @client end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def headers @headers end |
#object_key ⇒ Object (readonly)
Returns the value of attribute object_key.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def object_key @object_key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def path @path end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def request_method @request_method end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/taxjar/api/request.rb', line 10 def uri @uri end |
Instance Method Details
#perform ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/taxjar/api/request.rb', line 28 def perform = [:get, :delete].include?(@request_method) ? :params : :json response = build_http_client.request(request_method, uri.to_s, => @options) response_body = begin symbolize_keys!(response.parse(:json)) rescue JSON::ParserError nil end fail_or_return_response_body(response, response_body) rescue HTTP::Error => e raise Taxjar::Error, e end |