Module: LifxHttp::Api

Defined in:
lib/lifx_http/api.rb,
lib/lifx_http/api/with_default_selector.rb

Defined Under Namespace

Classes: WithDefaultSelector

Class Method Summary collapse

Class Method Details

.breathe(selector, color, options = { period: 1.0, cycles: 1.0, persist: false, power_on: true, peak: 0.5 }) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lifx_http/api.rb', line 48

def breathe(selector, color, options =  {
                                period:     1.0,
                                cycles:     1.0,
                                persist:    false,
                                power_on:   true,
                                peak:       0.5 })
  HTTParty.post(breathe_url(selector),
               headers: authorization_headers,
               query: options.merge({
                 color: color
               }))
end

.get_info(selector) ⇒ Object



30
31
32
33
# File 'lib/lifx_http/api.rb', line 30

def get_info(selector)
  HTTParty.get(info_url(selector),
               headers: authorization_headers)
end

.pulse(selector, color, options = { # from_color: current_bulb_color, period: 1.0, cycles: 1.0, persist: false, power_on: true, peak: 1.0 }) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lifx_http/api.rb', line 61

def pulse(selector, color, options = {
                              # from_color: current_bulb_color,
                                period:     1.0,
                                cycles:     1.0,
                                persist:    false,
                                power_on:   true,
                                peak:       1.0 })
  HTTParty.post(pulse_url(selector),
               headers: authorization_headers,
               query: options.merge({
                 color: color
               }))
end

.set_color(selector, color, options = { duration: 2.0, power_on: true}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lifx_http/api.rb', line 12

def set_color(selector, color, options = { duration: 2.0,
                                           power_on: true})
  HTTParty.put(color_url(selector),
               headers: authorization_headers,
               query: options.merge({
                 color: color
               })).tap do |response|
if response.success?
  puts "info: set #{selector} to #{color}" if ENV["DEBUG"]
  puts response.to_s if ENV["DEBUG"]
  nil
else
  puts "warning: light status - #{response}"
  -1
end
               end
end

.set_power_state(selector, state, options = {duration: 2}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/lifx_http/api.rb', line 35

def set_power_state(selector, state, options = {duration: 2})
  HTTParty.put(power_url(selector),
               headers: authorization_headers,
               query: options.merge({
                 state: state
               }))
end

.toggle_power_state(selector) ⇒ Object



43
44
45
46
# File 'lib/lifx_http/api.rb', line 43

def toggle_power_state(selector)
  HTTParty.post(toggle_power_url(selector),
               headers: authorization_headers)
end

.with_default_selector(selector) ⇒ Object



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

def with_default_selector(selector)
  WithDefaultSelector.new(selector)
end