Module: BerkeleyLibrary::Util::URIs

Extended by:
URIs
Included in:
TIND::Config, 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

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.

Parameters:

  • uri (URI, String)

    the original URI

  • elements (Array<String, Symbol>)

    the URI elements to join.

Returns:

  • (URI)

    a new URI appending the joined path elements.

Raises:

  • URI::InvalidComponentError if appending the specified elements would create an invalid URI



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

def append(uri, *elements)
  Appender.new(uri, *elements).to_uri
end

#get(uri, params = {}, headers = {}) ⇒ String

Performs a GET request.

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.



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

def get(uri, params = {}, headers = {})
  Requester.get(uri, params, headers)
end

#uri_or_nil(url) ⇒ URI

Returns the specified URL as a URI.

Parameters:

  • url (String, URI)

    the URL.

Returns:

  • (URI)

    the URI.

Raises:

  • (URI::InvalidURIError)

    if url cannot be parsed as a URI.



39
40
41
# File 'lib/berkeley_library/util/uris.rb', line 39

def uri_or_nil(url)
  Validator.uri_or_nil(url)
end