Class: Leftronic

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

Constant Summary collapse

ALLOWED_COLORS =
[:red, :yellow, :green, :blue, :purple]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, url = 'https://beta.leftronic.com/customSend/') ⇒ Leftronic

Returns a new instance of Leftronic.



16
17
18
19
# File 'lib/leftronic.rb', line 16

def initialize(key, url='https://beta.leftronic.com/customSend/')
  @key = key
  self.url = url
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/leftronic.rb', line 8

def key
  @key
end

Instance Method Details

#push(stream, object) ⇒ Object

Push anything to a widget



22
23
24
# File 'lib/leftronic.rb', line 22

def push(stream, object)
  post stream, object
end

#push_geo(stream, lat, long, color = nil) ⇒ Object

Push a geographic location (latitude and longitude) to a Map widget



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

def push_geo(stream, lat, long, color=nil)
  post stream, 'latitude' => lat, 'longitude' => long, 'color' => color
end

#push_leaderboard(stream, hash) ⇒ Object

Push a hash to a Leaderboard widget



42
43
44
45
46
47
# File 'lib/leftronic.rb', line 42

def push_leaderboard(stream, hash)
  leaderboard = hash.inject([]) do |array, (key, value)|
    array << {'name' => key, 'value' => value}
  end
  post stream, 'leaderboard' => leaderboard
end

#push_list(stream, *array) ⇒ Object

Push an array to a List widget



50
51
52
# File 'lib/leftronic.rb', line 50

def push_list(stream, *array)
  post stream, 'list' => array.flatten.map{|item| {'listItem' => item}}
end

#push_number(stream, point) ⇒ Object

Push a Number to a widget



27
28
29
# File 'lib/leftronic.rb', line 27

def push_number(stream, point)
  post stream, point
end

#push_text(stream, title, message) ⇒ Object

Push a title and message to a Text Feed widget



37
38
39
# File 'lib/leftronic.rb', line 37

def push_text(stream, title, message)
  post stream, 'title' => title, 'msg' => message
end

#urlObject



12
13
14
# File 'lib/leftronic.rb', line 12

def url
  @url.to_s
end

#url=(url) ⇒ Object



9
10
11
# File 'lib/leftronic.rb', line 9

def url=(url)
  @url = URI(url.to_s)
end