Class: Helium::Timeseries

Inherits:
Cursor
  • Object
show all
Includes:
Utils
Defined in:
lib/helium/timeseries.rb

Instance Method Summary collapse

Methods included from Utils

#datetime_to_iso, #kebab_case

Methods inherited from Cursor

#each, #initialize, #to_json

Constructor Details

This class inherits a constructor from Helium::Cursor

Instance Method Details

#create(opts = {}) ⇒ DataPoint

Creates a new data point on this timeseries

Parameters:

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

    a customizable set of options

Options Hash (opts):

  • :port (String)

    A port for the data point

  • :value (String)

    A value for the data point

  • :timestamp (DateTime)

    A timestamp for the data point. If not provided, it will default to the current time.

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/helium/timeseries.rb', line 10

def create(opts = {})
  port      = opts.fetch(:port)
  value     = opts.fetch(:value)
  timestamp = opts.fetch(:timestamp, DateTime.now)

  body = {
    data: {
      attributes: {
        port:      port,
        value:     value,
        timestamp: datetime_to_iso(timestamp)
      },
      type: 'data-point'
    }
  }

  response = @client.post(@path, body: body)
  resource_data = JSON.parse(response.body)["data"]

  return DataPoint.new(client: self, params: resource_data)
end