Class: SamsaraSDK::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/samsara_sdk/publisher.rb

Overview

Physical connector that Publishes messages to Samsara Ingestion API.

Instance Method Summary collapse

Instance Method Details

#post(data) ⇒ Boolean

Sends message to Ingestion API.

Parameters:

  • data (Array<Hash>)

    List of events.

Returns:

  • (Boolean)

    Success or failure of HTTP POST call.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/samsara_sdk/publisher.rb', line 15

def post(data)
  url = URI.parse(Config.get[:url].chomp('/') + Config::API_PATH)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = url.scheme == 'https'
  http.read_timeout = Config.get[:send_timeout_ms] / 1000
  request = Net::HTTP::Post.new(url, headers)
  request.body = prepare data
  http.request(request).instance_of? Net::HTTPAccepted
rescue RuntimeError
  FALSE
end