Class: ScaleDrone

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/scaledrone.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ScaleDrone

Returns a new instance of ScaleDrone.



6
7
8
9
10
11
12
13
14
15
# File 'lib/scaledrone.rb', line 6

def initialize(options = {})
  options = {
    :base_url => 'https://api2.scaledrone.com',
  }.merge(options)
  @channel_id, @base_url = options.values_at(:channel_id, :base_url)
  @options = {
    headers: {'Content-Type' => 'application/json'},
    basic_auth: {username: options[:channel_id], password: options[:secret_key]}
  }
end

Instance Method Details

#channel_statsObject



28
29
30
# File 'lib/scaledrone.rb', line 28

def channel_stats
  self.class.get("#{@base_url}/#{@channel_id}/stats", @options)
end

#publish(data = {}, *rooms) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/scaledrone.rb', line 17

def publish(data = {}, *rooms)
  if rooms.length === 1
    url = "#{@base_url}/#{@channel_id}/#{rooms[0]}/publish"
    options = {body: data.to_json}.merge(@options)
  else
    url = "#{@base_url}/#{@channel_id}/publish/rooms"
    options = {body: data.to_json, query: {:r => rooms}}.merge(@options)
  end
  self.class.post(url, options)
end