Class: LedgerSync::Adaptors::Request
- Inherits:
-
Object
- Object
- LedgerSync::Adaptors::Request
- Defined in:
- lib/ledger_sync/adaptors/request.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
- .delete(**keywords) ⇒ Object
- .get(**keywords) ⇒ Object
- .post(**keywords) ⇒ Object
- .put(**keywords) ⇒ Object
Instance Method Summary collapse
-
#initialize(body: nil, headers: {}, method: nil, url: nil) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #performed? ⇒ Boolean
Constructor Details
#initialize(body: nil, headers: {}, method: nil, url: nil) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 |
# File 'lib/ledger_sync/adaptors/request.rb', line 12 def initialize(body: nil, headers: {}, method: nil, url: nil) @body = body @headers = headers @method = method @url = url end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/ledger_sync/adaptors/request.rb', line 6 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/ledger_sync/adaptors/request.rb', line 6 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/ledger_sync/adaptors/request.rb', line 6 def method @method end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/ledger_sync/adaptors/request.rb', line 6 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/ledger_sync/adaptors/request.rb', line 6 def url @url end |
Class Method Details
.delete(**keywords) ⇒ Object
36 37 38 |
# File 'lib/ledger_sync/adaptors/request.rb', line 36 def self.delete(**keywords) new(keywords.merge(method: :delete)) end |
.get(**keywords) ⇒ Object
40 41 42 |
# File 'lib/ledger_sync/adaptors/request.rb', line 40 def self.get(**keywords) new(keywords.merge(method: :get)) end |
.post(**keywords) ⇒ Object
44 45 46 |
# File 'lib/ledger_sync/adaptors/request.rb', line 44 def self.post(**keywords) new(keywords.merge(method: :post)) end |
.put(**keywords) ⇒ Object
48 49 50 |
# File 'lib/ledger_sync/adaptors/request.rb', line 48 def self.put(**keywords) new(keywords.merge(method: :put)) end |
Instance Method Details
#perform ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ledger_sync/adaptors/request.rb', line 19 def perform raise 'Request already performed' if performed? faraday_response = Faraday.send(method, url) do |req| req.headers = headers req.body = body.to_json unless body.nil? end @response = Response.new_from_faraday_response(faraday_response: faraday_response, request: self) @performed = true @response end |
#performed? ⇒ Boolean
32 33 34 |
# File 'lib/ledger_sync/adaptors/request.rb', line 32 def performed? @performed == true end |