Module: Request

Constant Summary

Constants included from Blockfrostruby

Blockfrostruby::VERSION

Class Method Summary collapse

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.

Parameters:

  • url (String)

    the url to request.

  • project_id (String)

    the project_id to pass to url in headers.

  • params (Hash) (defaults to: {})

    params to add to request, allowed :order, :page, :count, :from, :to.

Returns:

  • (Hash)

    formatted result with status and body keys.



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.

Parameters:

  • url (String)

    the url to request.

  • project_id (String)

    the project_id to pass to url in headers.

  • filepath (String)

    path to file for uploading.

Returns:

  • (Hash)

    formatted result with status and body keys.



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.

Parameters:

  • url (String)

    the url to request.

  • project_id (String)

    the project_id to pass to url in headers.

  • body (String)

    for pass to url.

Returns:

  • (Hash)

    formatted result with status and body keys.



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.

Parameters:

  • url (String)

    the url to request.

  • project_id (String)

    the project_id to pass to url in headers.

Returns:

  • (Hash)

    formatted result with status and body keys.



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