Module: AMON

Extended by:
Forwardable
Defined in:
lib/amon/default_session.rb,
lib/amon.rb,
lib/amon/device.rb,
lib/amon/entity.rb,
lib/amon/reading.rb,
lib/amon/session.rb,
lib/amon/version.rb,
lib/amon/document.rb,
lib/amon/metadata.rb,
lib/amon/json_helper.rb,
lib/amon/measurement.rb,
lib/amon/document_part.rb,
lib/amon/metering_point.rb

Overview

The AMON module responds to the same method names as an Session. When called, these methods use a ‘default’ session returned by AMON.create_default_session. So the following method calls are all equivalent:

AMON::Session.new(AMON.default_session_options).entity("77e50660-93e7-012d-b57d-001c23973687")
AMON.create_default_session.entity("77e50660-93e7-012d-b57d-001c23973687")
AMON.entity("77e50660-93e7-012d-b57d-001c23973687")

Note that using a default session implicitly (as in the final line above) will cause a new session to be created each time the method is called. This means caching will not be used.

If you are likely to be requesting the same resources in short succession, it is advisable to hold on to a session object yourself. For example:

@session = AMON.create_default_session
@session.entity("77e50660-93e7-012d-b57d-001c23973687") # => <AMON::Entity> (from HTTP)
@session.entity("77e50660-93e7-012d-b57d-001c23973687") # => <AMON::Entity> (from cache)

Defined Under Namespace

Modules: JSONHelper, Version Classes: Device, Document, DocumentPart, Entity, Measurement, Metadata, MeteringPoint, Reading, Session

Class Method Summary collapse

Class Method Details

.create_default_sessionSession

Creates a new session using the default_session_options.

Returns:



38
39
40
# File 'lib/amon/default_session.rb', line 38

def create_default_session
  Session.new(default_session_options)
end

.default_session_optionsHash

A hash of options which are used by create_default_session. The values of this hash should be configured by users as appropriate.

Returns:

  • (Hash)

    an options hash, initially empty



25
26
27
# File 'lib/amon/default_session.rb', line 25

def default_session_options
  @default_session_options ||= {}
end

.default_session_options=(options) ⇒ Hash

Assigns a new options hash as the default_session_options.

Parameters:

  • options (Hash)

    the options hash

Returns:

  • (Hash)

    the options hash



32
33
34
# File 'lib/amon/default_session.rb', line 32

def default_session_options=(options)
  @default_session_options = options
end