Class: Switchbot::Client

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

Constant Summary collapse

API_ENDPOINT =
'https://api.switch-bot.com'
API_VERSION =
'v1.1'

Instance Method Summary collapse

Constructor Details

#initialize(token, secret) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/switchbot/client.rb', line 8

def initialize(token, secret)
  @token = token
  @secret = secret
end

Instance Method Details

#bot(device_id) ⇒ Object



61
62
63
# File 'lib/switchbot/client.rb', line 61

def bot(device_id)
  Bot.new(client: self, device_id: device_id)
end

#color_bulb(device_id) ⇒ Object



73
74
75
# File 'lib/switchbot/client.rb', line 73

def color_bulb(device_id)
  ColorBulb.new(client: self, device_id: device_id)
end

#commands(device_id:, command:, parameter: 'default', command_type: 'command') ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/switchbot/client.rb', line 31

def commands(device_id:, command:, parameter: 'default', command_type: 'command')
  request(
    http_method: :post,
    endpoint: "/#{API_VERSION}/devices/#{device_id}/commands",
    params: {
      command: command,
      parameter: parameter,
      commandType: command_type
    }
  )
end

#device(device_id) ⇒ Object



20
21
22
# File 'lib/switchbot/client.rb', line 20

def device(device_id)
  Device.new(client: self, device_id: device_id)
end

#devicesObject



13
14
15
16
17
18
# File 'lib/switchbot/client.rb', line 13

def devices
  request(
    http_method: :get,
    endpoint: "/#{API_VERSION}/devices"
  )
end

#execute(scene_id:) ⇒ Object



54
55
56
57
58
59
# File 'lib/switchbot/client.rb', line 54

def execute(scene_id:)
  request(
    http_method: :post,
    endpoint: "/#{API_VERSION}/scenes/#{scene_id}/execute"
  )
end

#humidifier(device_id) ⇒ Object



69
70
71
# File 'lib/switchbot/client.rb', line 69

def humidifier(device_id)
  Humidifier.new(client: self, device_id: device_id)
end

#light(device_id) ⇒ Object



65
66
67
# File 'lib/switchbot/client.rb', line 65

def light(device_id)
  Light.new(client: self, device_id: device_id)
end

#lock(device_id) ⇒ Object



77
78
79
# File 'lib/switchbot/client.rb', line 77

def lock(device_id)
  Lock.new(client: self, device_id: device_id)
end

#plug_mini(device_id) ⇒ Object



81
82
83
# File 'lib/switchbot/client.rb', line 81

def plug_mini(device_id)
  PlugMini.new(client: self, device_id: device_id)
end

#scene(scene_id) ⇒ Object



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

def scene(scene_id)
  Scene.new(client: self, scene_id: scene_id)
end

#scenesObject



43
44
45
46
47
48
# File 'lib/switchbot/client.rb', line 43

def scenes
  request(
    http_method: :get,
    endpoint: "/#{API_VERSION}/scenes"
  )
end

#status(device_id:) ⇒ Object



24
25
26
27
28
29
# File 'lib/switchbot/client.rb', line 24

def status(device_id:)
  request(
    http_method: :get,
    endpoint: "/#{API_VERSION}/devices/#{device_id}/status"
  )
end