Module: BerkeleyLibrary::Util::URIs::Requester
- Extended by:
- Logging
- Defined in:
- lib/berkeley_library/util/uris/requester.rb
Class Method Summary collapse
-
.get(uri, params: {}, headers: {}) ⇒ String
Performs a GET request and returns the response body as a string.
-
.get_response(uri, params: {}, headers: {}) ⇒ RestClient::Response
Performs a GET request and returns the response, even in the event of a failed request.
-
.head(uri, params: {}, headers: {}) ⇒ Integer
Performs a HEAD request and returns the response status as an integer.
-
.head_response(uri, params: {}, headers: {}) ⇒ RestClient::Response
Performs a HEAD request and returns the response, even in the event of a failed request.
Class Method Details
.get(uri, params: {}, headers: {}) ⇒ String
Performs a GET request and returns the response body as a string.
20 21 22 23 |
# File 'lib/berkeley_library/util/uris/requester.rb', line 20 def get(uri, params: {}, headers: {}) resp = make_request(:get, uri, params, headers) resp.body end |
.get_response(uri, params: {}, headers: {}) ⇒ RestClient::Response
Performs a GET request and returns the response, even in the event of a failed request.
44 45 46 47 48 |
# File 'lib/berkeley_library/util/uris/requester.rb', line 44 def get_response(uri, params: {}, headers: {}) make_request(:get, uri, params, headers) rescue RestClient::Exception => e e.response end |
.head(uri, params: {}, headers: {}) ⇒ Integer
Performs a HEAD request and returns the response status as an integer. Note that unlike get, this does not raise an error in the event of an unsuccessful request.
33 34 35 |
# File 'lib/berkeley_library/util/uris/requester.rb', line 33 def head(uri, params: {}, headers: {}) head_response(uri, params: params, headers: headers).code end |
.head_response(uri, params: {}, headers: {}) ⇒ RestClient::Response
Performs a HEAD request and returns the response, even in the event of a failed request.
57 58 59 60 61 |
# File 'lib/berkeley_library/util/uris/requester.rb', line 57 def head_response(uri, params: {}, headers: {}) make_request(:head, uri, params, headers) rescue RestClient::Exception => e e.response end |