Class: Fortnox::Request
- Inherits:
-
Object
- Object
- Fortnox::Request
- Defined in:
- lib/fortnox/request.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #auth_headers ⇒ Object
- #client ⇒ Object
- #content ⇒ Object
- #execute ⇒ Object
-
#initialize(type, url, params = {}) ⇒ Request
constructor
A new instance of Request.
- #raise_from(response) ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(type, url, params = {}) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 |
# File 'lib/fortnox/request.rb', line 5 def initialize(type, url, params = {}) @url = url @type = type @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/fortnox/request.rb', line 3 def params @params end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/fortnox/request.rb', line 3 def type @type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/fortnox/request.rb', line 3 def url @url end |
Instance Method Details
#auth_headers ⇒ Object
34 35 36 |
# File 'lib/fortnox/request.rb', line 34 def auth_headers client.auth_headers end |
#content ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fortnox/request.rb', line 11 def content case type when :post, :put { body: params.to_json } when :get { query: params } when :delete {} end end |
#execute ⇒ Object
22 23 24 |
# File 'lib/fortnox/request.rb', line 22 def execute response.success? ? response.parsed_response : raise_from(response) end |
#raise_from(response) ⇒ Object
26 27 28 |
# File 'lib/fortnox/request.rb', line 26 def raise_from(response) raise Fortnox::Error.from_response(response) end |