Sha256: 122be2c03aee11a88825594319a4ae18b204826feb35d421112af7f6382973e7

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Helium
  class Client
    module Elements
      def elements
        Element.all(client: self)
      end

      def element(id)
        Element.find(id, client: self)
      end

      def element_sensors(element)
        path = "/element/#{element.id}/sensor"
        response = get(path)
        sensors_data = JSON.parse(response.body)["data"]

        sensors = sensors_data.map do |sensor|
          Sensor.new(client: self, params: sensor)
        end

        return sensors
      end

      def element_timeseries(element, opts = {})
        path = "/element/#{element.id}/timeseries"

        params = {
          "page[size]"    => opts.fetch(:size, nil),
          "filter[port]"  => opts.fetch(:port, nil),
          "filter[start]" => datetime_to_iso(opts.fetch(:start_time, nil)),
          "filter[end]"   => datetime_to_iso(opts.fetch(:end_time, nil)),
          "agg[type]"     => opts.fetch(:aggtype),
          "agg[size]"     => opts.fetch(:aggsize)
        }.delete_if { |_key, value| value.to_s.empty? }

        paginated_get(path,
          klass:        Helium::DataPoint,
          cursor_klass: Helium::Timeseries,
          params:       params
        )
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
helium-ruby-0.17.0 lib/helium/client/elements.rb
helium-ruby-0.16.0 lib/helium/client/elements.rb
helium-ruby-0.15.0 lib/helium/client/elements.rb
helium-ruby-0.14.0 lib/helium/client/elements.rb
helium-ruby-0.13.0 lib/helium/client/elements.rb