Class: Atum::Core::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/atum/core/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources, url) ⇒ Client

Returns a new instance of Client.

Parameters:

  • resources (Hash<String,Resource>)

    Methods names -> Resources

  • url (String)

    The URL used by this client.



29
30
31
32
33
34
# File 'lib/atum/core/client.rb', line 29

def initialize(resources, url)
  @url = url
  resources.each do |name, resource|
    define_singleton_method(name) { resource }
  end
end

Class Method Details

.client_from_schema(api_schema, url, options = {}) ⇒ Client

Create an HTTP client from a schema.

Parameters:

  • schema (ApiSchema)

    The schema to build an HTTP client for.

  • url (String)

    The URL the generated client should use

  • options (Hash) (defaults to: {})

    Configuration for links. Possible keys include:

    • default_headers: Optionally, a set of headers to include in every request made by the client. Default is no custom headers.

Returns:

  • (Client)

    A client with resources and links from the schema



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/atum/core/client.rb', line 13

def client_from_schema(api_schema, url, options = {})
  resources = {}
  api_schema.resource_schemas.each do |resource_schema|
    links_hash = {}
    resource_schema.link_schemas.each do |link_schema|
      links_hash[link_schema.name] = Link.new(url, link_schema, options)
    end
    resources[resource_schema.name] = Resource.new(links_hash)
  end

  new(resources, url)
end

Instance Method Details

#inspectObject Also known as: to_s



36
37
38
39
40
# File 'lib/atum/core/client.rb', line 36

def inspect
  url = URI.parse(@url)
  url.password = 'REDACTED' unless url.password.nil?
  "#<Atum::Client url=\"#{url}\">"
end