Module: Request
- Includes:
- Blockfrostruby
- Included in:
- AccountsEndpoints, AddressesEndpoints, AssetsEndpoints, BlocksEndpoints, CustomEndpoints, EpochsEndpoints, HealthEndpoints, IPFSEndpoints, LedgerEndpoints, MetadataEndpoints, MetricsEndpoints, NetworkEndpoints, NutlinkEndpoints, PoolsEndpoints, TransactionsEndpoints
- Defined in:
- lib/blockfrostruby/request.rb
Constant Summary
Constants included from Blockfrostruby
Class Method Summary collapse
-
.get_response(url, project_id, params = {}) ⇒ Hash
Get response from passed URL, add params to request, add specific headers and format the response.
-
.post_file(url, project_id, filepath) ⇒ Hash
Post file to url, in multipart/form-data.
-
.post_request_cbor(url, project_id, body) ⇒ Hash
Post request to url, in application/cbor format with body.
-
.post_request_raw(url, project_id) ⇒ Hash
Post raw request to url, with no body or params.
Class Method Details
.get_response(url, project_id, params = {}) ⇒ Hash
Get response from passed URL, add params to request, add specific headers and format the response. If [:from_page] specified, calls the concurrent fetching process, else get response from single page.
20 21 22 |
# File 'lib/blockfrostruby/request.rb', line 20 def get_response(url, project_id, params = {}) params[:from_page] ? get_pages_multi(url, project_id, params) : get_response_from_url(url, project_id, params) end |
.post_file(url, project_id, filepath) ⇒ Hash
Post file to url, in multipart/form-data.
58 59 60 61 62 63 64 65 |
# File 'lib/blockfrostruby/request.rb', line 58 def post_file(url, project_id, filepath) uri = URI(url) file = [['upload', File.open(filepath)]] request = create_post_request(uri, project_id) request.set_form file, 'multipart/form-data' response = send_request(uri, request) format_response(response) end |
.post_request_cbor(url, project_id, body) ⇒ Hash
Post request to url, in application/cbor format with body.
43 44 45 46 47 48 49 50 |
# File 'lib/blockfrostruby/request.rb', line 43 def post_request_cbor(url, project_id, body) uri = URI(url) request = create_post_request(uri, project_id) request['Content-Type'] = 'application/cbor' request.body = body response = send_request(uri, request) format_response(response) end |
.post_request_raw(url, project_id) ⇒ Hash
Post raw request to url, with no body or params.
29 30 31 32 33 34 35 |
# File 'lib/blockfrostruby/request.rb', line 29 def post_request_raw(url, project_id) uri = URI(url) request = create_post_request(uri, project_id) request['Content-Type'] = 'text/plain' response = send_request(uri, request) format_response(response) end |