Module: BerkeleyLibrary::Util::URIs
- Extended by:
- URIs
- Includes:
- Logging
- Included in:
- URIs
- Defined in:
- lib/berkeley_library/util/uris.rb,
lib/berkeley_library/util/uris/appender.rb,
lib/berkeley_library/util/uris/requester.rb,
lib/berkeley_library/util/uris/validator.rb
Defined Under Namespace
Modules: Requester, Validator Classes: Appender
Instance Method Summary collapse
-
#append(uri, *elements) ⇒ URI
Appends the specified paths to the path of the specified URI, removing any extraneous slashes and merging additional query parameters, and returns a new URI with that path and the same scheme, host, query, fragment, etc.
-
#get(uri, params: {}, headers: {}) ⇒ String
Performs a GET request.
-
#get_response(uri, params: {}, headers: {}) ⇒ RestClient::Response
Performs a GET request and returns the response.
-
#safe_parse_uri(url) ⇒ URI?
Returns the specified URL as a URI, or
nilif the URL cannot be parsed. -
#uri_or_nil(url) ⇒ URI
Returns the specified URL as a URI, or
nilif the URL isnil.
Instance Method Details
#append(uri, *elements) ⇒ URI
Appends the specified paths to the path of the specified URI, removing any extraneous slashes and merging additional query parameters, and returns a new URI with that path and the same scheme, host, query, fragment, etc. as the original.
23 24 25 |
# File 'lib/berkeley_library/util/uris.rb', line 23 def append(uri, *elements) Appender.new(uri, *elements).to_uri end |
#get(uri, params: {}, headers: {}) ⇒ String
Performs a GET request.
34 35 36 |
# File 'lib/berkeley_library/util/uris.rb', line 34 def get(uri, params: {}, headers: {}) Requester.get(uri, params: params, headers: headers) end |
#get_response(uri, params: {}, headers: {}) ⇒ RestClient::Response
Performs a GET request and returns the response.
44 45 46 |
# File 'lib/berkeley_library/util/uris.rb', line 44 def get_response(uri, params: {}, headers: {}) Requester.get_response(uri, params: params, headers: headers) end |
#safe_parse_uri(url) ⇒ URI?
Returns the specified URL as a URI, or nil if the URL cannot
be parsed.
61 62 63 64 65 66 67 |
# File 'lib/berkeley_library/util/uris.rb', line 61 def safe_parse_uri(url) # noinspection RubyMismatchedArgumentType uri_or_nil(url) rescue URI::InvalidURIError => e logger.warn("Error parsing URL #{url.inspect}", e) nil end |
#uri_or_nil(url) ⇒ URI
Returns the specified URL as a URI, or nil if the URL is nil.
53 54 55 |
# File 'lib/berkeley_library/util/uris.rb', line 53 def uri_or_nil(url) Validator.uri_or_nil(url) end |