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



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

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



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

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



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

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
# File 'lib/lifx_http/api.rb', line 12

def set_color(selector, color, options = { duration: 2.0,
                                           power_on: true})
  response = HTTParty.put(color_url(selector),
               headers: authorization_headers,
               query: options.merge({
                 color: color
               }))
  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

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



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

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



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

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