Class: HalClient

Inherits:
Object
  • Object
show all
Extended by:
EntryPointCovenienceMethods
Defined in:
lib/hal_client.rb,
lib/hal_client/errors.rb,
lib/hal_client/version.rb,
lib/hal_client/curie_resolver.rb,
lib/hal_client/representation.rb,
lib/hal_client/representation_set.rb

Overview

Adapter used to access resources.

Defined Under Namespace

Modules: EntryPointCovenienceMethods Classes: CurieResolver, Representation, RepresentationSet

Constant Summary collapse

InvalidRepresentationError =
Class.new(StandardError)
VERSION =
"2.0.0"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HalClient

Initializes a new client instance

options - hash of configuration options

:accept - one or more content types that should be 
  prepended to the `Accept` header field of each request.


16
17
18
# File 'lib/hal_client.rb', line 16

def initialize(options={})
  @default_accept = options.fetch(:accept, 'application/hal+json')
end

Instance Method Details

#get(url, options = {}) ⇒ Object

Returns a Representation of the resource identified by url.

url - The URL of the resource of interest. options - set of options to pass to ‘RestClient#get`



24
25
26
27
# File 'lib/hal_client.rb', line 24

def get(url, options={})
  resp = RestClient.get url, rest_client_options(options)
  Representation.new hal_client: self, parsed_json: MultiJson.load(resp)
end