Class: LedgerSync::Ledgers::Request
- Inherits:
-
Object
- Object
- LedgerSync::Ledgers::Request
- Defined in:
- lib/ledger_sync/ledgers/request.rb
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.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#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(args = {}) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
- #performed? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 |
# File 'lib/ledger_sync/ledgers/request.rb', line 13 def initialize(args = {}) @body = args.fetch(:body, nil) @headers = args.fetch(:headers, {}) @method = args.fetch(:method, nil) @params = args.fetch(:params, {}) @url = args.fetch(:url, nil) @faraday_client = args.fetch(:faraday_client, Faraday.new) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/ledger_sync/ledgers/request.rb', line 6 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/ledger_sync/ledgers/request.rb', line 6 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/ledger_sync/ledgers/request.rb', line 6 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/ledger_sync/ledgers/request.rb', line 6 def params @params end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/ledger_sync/ledgers/request.rb', line 6 def response @response end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/ledger_sync/ledgers/request.rb', line 6 def url @url end |
Class Method Details
.delete(**keywords) ⇒ Object
41 42 43 |
# File 'lib/ledger_sync/ledgers/request.rb', line 41 def self.delete(**keywords) new(keywords.merge(method: :delete)) end |
.get(**keywords) ⇒ Object
45 46 47 |
# File 'lib/ledger_sync/ledgers/request.rb', line 45 def self.get(**keywords) new(keywords.merge(method: :get)) end |
.post(**keywords) ⇒ Object
49 50 51 |
# File 'lib/ledger_sync/ledgers/request.rb', line 49 def self.post(**keywords) new(keywords.merge(method: :post)) end |
.put(**keywords) ⇒ Object
53 54 55 |
# File 'lib/ledger_sync/ledgers/request.rb', line 53 def self.put(**keywords) new(keywords.merge(method: :put)) end |
Instance Method Details
#perform ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ledger_sync/ledgers/request.rb', line 22 def perform raise 'Request already performed' if performed? url_with_params = Util::URLHelpers.merge_params_in_url(params: params, url: url) faraday_response = @faraday_client.send(method, url_with_params) 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
37 38 39 |
# File 'lib/ledger_sync/ledgers/request.rb', line 37 def performed? @performed == true end |