Class: HalClient
- Inherits:
-
Object
- Object
- HalClient
- Extended by:
- EntryPointCovenienceMethods
- Defined in:
- lib/hal_client.rb,
lib/hal_client/form.rb,
lib/hal_client/link.rb,
lib/hal_client/errors.rb,
lib/hal_client/version.rb,
lib/hal_client/collection.rb,
lib/hal_client/form/field.rb,
lib/hal_client/interpreter.rb,
lib/hal_client/null_logger.rb,
lib/hal_client/retryinator.rb,
lib/hal_client/links_section.rb,
lib/hal_client/curie_resolver.rb,
lib/hal_client/representation.rb,
lib/hal_client/representation_set.rb,
lib/hal_client/representation_editor.rb,
lib/hal_client/anonymous_resource_locator.rb
Overview
Adapter used to access resources.
Operations on a HalClient instance are not thread-safe. If you’d like to use a HalClient instance in a threaded environment, consider using the method #clone_for_use_in_different_thread to create a copy for each new thread
Defined Under Namespace
Modules: EntryPointCovenienceMethods Classes: AnonymousResourceLocator, Collection, CurieResolver, Form, HttpError, Interpreter, Link, LinksSection, MalformedLink, NullLogger, Representation, RepresentationEditor, RepresentationSet, Retryinator, SimpleLink, TemplatedLink
Constant Summary collapse
- InvalidRepresentationError =
The representation is not a valid HAL document.
Class.new(StandardError)
- NotACollectionError =
The representation is not a HAL collection
Class.new(StandardError)
- HttpClientError =
Server response with a 4xx status code
Class.new(HttpError)
- HttpServerError =
Server responded with a 5xx status code
Class.new(HttpError)
- TimeoutError =
Class.new(StandardError)
- VERSION =
"5.0.0"
Instance Method Summary collapse
-
#clone_for_use_in_different_thread ⇒ Object
Returns a copy of this instance that is safe to use in threaded environments.
-
#delete(url, headers = {}) ⇒ Object
Delete a ‘Representation` or `String` to the resource identified at `url`.
-
#get(url, headers = {}) ⇒ Object
Returns a ‘Representation` of the resource identified by `url`.
Methods included from EntryPointCovenienceMethods
Instance Method Details
#clone_for_use_in_different_thread ⇒ Object
Returns a copy of this instance that is safe to use in threaded environments
90 91 92 |
# File 'lib/hal_client.rb', line 90 def clone_for_use_in_different_thread clone.tap { |c| c.clear_clients! } end |
#delete(url, headers = {}) ⇒ Object
Delete a ‘Representation` or `String` to the resource identified at `url`.
url - The URL of the resource of interest. headers - custom header fields to use for this request
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/hal_client.rb', line 191 def delete(url, headers={}) headers = auth_headers(url).merge(headers) begin client = client_for_post(override_headers: headers) resp = bmtb("DELETE <#{url}>") { .retryable { client.request(:delete, url) } } interpret_response resp rescue HttpError => e fail e.class.new("DELETE <#{url}> failed with code #{e.response.status}", e.response) end end |
#get(url, headers = {}) ⇒ Object
Returns a ‘Representation` of the resource identified by `url`.
url - The URL of the resource of interest. headers - custom header fields to use for this request
98 99 100 101 102 103 104 105 106 |
# File 'lib/hal_client.rb', line 98 def get(url, headers={}) headers = auth_headers(url).merge(headers) client = client_for_get(override_headers: headers) resp = .retryable { bmtb("GET <#{url}>") { client.get(url) } } interpret_response resp rescue HttpError => e fail e.class.new("GET <#{url}> failed with code #{e.response.status}", e.response) end |