Class: Fakturoid::Request
- Inherits:
-
Object
- Object
- Fakturoid::Request
- Includes:
- Connection
- Defined in:
- lib/fakturoid/request.rb
Constant Summary collapse
- HTTP_METHODS =
[:get, :post, :patch, :delete]
Instance Attribute Summary collapse
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #call(params = {}) ⇒ Object
-
#initialize(method, path, caller) ⇒ Request
constructor
A new instance of Request.
Methods included from Connection
Constructor Details
#initialize(method, path, caller) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 |
# File 'lib/fakturoid/request.rb', line 8 def initialize(method, path, caller) @method = method @path = path @caller = caller end |
Instance Attribute Details
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
5 6 7 |
# File 'lib/fakturoid/request.rb', line 5 def caller @caller end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/fakturoid/request.rb', line 5 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/fakturoid/request.rb', line 5 def path @path end |
Instance Method Details
#call(params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fakturoid/request.rb', line 14 def call(params = {}) raise ArgumentError, "Unknown http method: #{method}" unless HTTP_METHODS.include?(method.to_sym) request_params = params[:request_params] || {} http_connection = connection(params) response = http_connection.send(method) do |req| req.url path, request_params req.body = MultiJson.dump(params[:payload]) if params.key?(:payload) end Response.new(response, caller, method) end |