Module: BerkeleyLibrary::Util::URIs::Requester

Extended by:
Logging
Defined in:
lib/berkeley_library/util/uris/requester.rb

Class Method Summary collapse

Class Method Details

.get(uri, params: {}, headers: {}) ⇒ String

Performs a GET request and returns the response body as a string.

Parameters:

  • uri (URI, String)

    the URI to GET

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

    the query parameters to add to the URI. (Note that the URI may already include query parameters.)

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

    the request headers.

Returns:

  • (String)

    the body as a string.

Raises:

  • (RestClient::Exception)

    in the event of an error.



20
21
22
23
# File 'lib/berkeley_library/util/uris/requester.rb', line 20

def get(uri, params: {}, headers: {})
  resp = make_get_request(uri, params, headers)
  resp.body
end

.get_response(uri, params: {}, headers: {}) ⇒ RestClient::Response

Performs a GET request and returns the response.

Parameters:

  • uri (URI, String)

    the URI to GET

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

    the query parameters to add to the URI. (Note that the URI may already include query parameters.)

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

    the request headers.

Returns:

  • (RestClient::Response)

    the body as a string.



31
32
33
34
35
# File 'lib/berkeley_library/util/uris/requester.rb', line 31

def get_response(uri, params: {}, headers: {})
  make_get_request(uri, params, headers)
rescue RestClient::Exception => e
  e.response
end