Module: Bayarcash::MakesHttpRequests
- Included in:
- Client
- Defined in:
- lib/bayarcash/makes_http_requests.rb
Overview
HTTP transport for the Bayarcash API.
Requests default to form-urlencoded bodies (matching the PHP SDK's Guzzle
form_params behaviour). To send a JSON body, pass a payload shaped like
{ json: {...} }. Non-2xx responses are mapped to typed errors.
Instance Attribute Summary collapse
- #connection ⇒ Faraday::Connection readonly
Instance Method Summary collapse
-
#delete(uri, payload = {}) ⇒ Object
Decoded response.
-
#get(uri) ⇒ Object
Decoded response.
-
#post(uri, payload = {}) ⇒ Object
Decoded response.
-
#put(uri, payload = {}) ⇒ Object
Decoded response.
-
#retry_until(timeout, sleep_seconds = 5) { ... } ⇒ Object
Retry a block until it returns a truthy value or the timeout elapses.
Instance Attribute Details
#connection ⇒ Faraday::Connection (readonly)
11 12 13 |
# File 'lib/bayarcash/makes_http_requests.rb', line 11 def connection @connection end |
Instance Method Details
#delete(uri, payload = {}) ⇒ Object
Returns decoded response.
36 37 38 |
# File 'lib/bayarcash/makes_http_requests.rb', line 36 def delete(uri, payload = {}) request(:delete, uri, payload) end |
#get(uri) ⇒ Object
Returns decoded response.
15 16 17 |
# File 'lib/bayarcash/makes_http_requests.rb', line 15 def get(uri) request(:get, uri) end |
#post(uri, payload = {}) ⇒ Object
Returns decoded response.
22 23 24 |
# File 'lib/bayarcash/makes_http_requests.rb', line 22 def post(uri, payload = {}) request(:post, uri, payload) end |
#put(uri, payload = {}) ⇒ Object
Returns decoded response.
29 30 31 |
# File 'lib/bayarcash/makes_http_requests.rb', line 29 def put(uri, payload = {}) request(:put, uri, payload) end |
#retry_until(timeout, sleep_seconds = 5) { ... } ⇒ Object
Retry a block until it returns a truthy value or the timeout elapses.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bayarcash/makes_http_requests.rb', line 47 def retry_until(timeout, sleep_seconds = 5) start = Time.now.to_i loop do output = yield return output if output if Time.now.to_i - start < timeout sleep(sleep_seconds) else output = [] if output.nil? || output == false output = [output] unless output.is_a?(Array) raise Bayarcash::TimeoutError.new(output) end end end |