Module: Winker::ApiMethods
- Included in:
- Winker
- Defined in:
- lib/winker/api_methods.rb
Instance Method Summary collapse
-
#activate_scene(scene_id) ⇒ Object
def update_scene(scene_id, options) response = put(“/scenes/#scene_id”) parse(response.body).data end.
- #authorize ⇒ Object
- #channels ⇒ Object
- #devices ⇒ Object
- #get(path, params = nil) ⇒ Object
- #get_device(type, id) ⇒ Object
- #get_scene(scene_id) ⇒ Object
- #groups ⇒ Object
- #icons ⇒ Object
- #post(path, params = nil) ⇒ Object
- #put(path, params = nil) ⇒ Object
- #scenes ⇒ Object
- #update_device(type, id, options) ⇒ Object
- #update_group(id, options) ⇒ Object
Instance Method Details
#activate_scene(scene_id) ⇒ Object
def update_scene(scene_id, options)
response = put("/scenes/#{scene_id}")
parse(response.body).data
end
65 66 67 68 |
# File 'lib/winker/api_methods.rb', line 65 def activate_scene(scene_id) response = post("/scenes/#{scene_id}/activate") parse(response.body).data end |
#authorize ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/winker/api_methods.rb', line 21 def response = post("/oauth2/token", {client_id: Winker.client_id, client_secret: Winker.client_secret, username: Winker.username, password: Winker.password, grant_type: "password"}) @access_token = response.body["access_token"] @refresh_token = response.body["refresh_token"] @connection = nil response end |
#channels ⇒ Object
45 46 47 48 |
# File 'lib/winker/api_methods.rb', line 45 def channels response = get("/channels") parse(response.body).data end |
#devices ⇒ Object
29 30 31 32 33 |
# File 'lib/winker/api_methods.rb', line 29 def devices response = get("/users/me/wink_devices") Winker::Device.load_devices(parse(response.body).data) end |
#get(path, params = nil) ⇒ Object
3 4 5 6 7 |
# File 'lib/winker/api_methods.rb', line 3 def get(path, params = nil) response = super @server_time_dif = Time.parse(response.headers["date"]) - Time.now return response end |
#get_device(type, id) ⇒ Object
70 71 72 73 |
# File 'lib/winker/api_methods.rb', line 70 def get_device(type, id) response = get("/#{type}s/#{id}") parse(response.body).data end |
#get_scene(scene_id) ⇒ Object
55 56 57 58 |
# File 'lib/winker/api_methods.rb', line 55 def get_scene(scene_id) response = get("/scenes/#{scene_id}") parse(response.body).data end |
#groups ⇒ Object
35 36 37 38 |
# File 'lib/winker/api_methods.rb', line 35 def groups response = get("/users/me/groups") Winker::Group.load_groups(parse(response.body).data) end |
#icons ⇒ Object
40 41 42 43 |
# File 'lib/winker/api_methods.rb', line 40 def icons response = get("/icons") parse(response.body).data end |
#post(path, params = nil) ⇒ Object
15 16 17 18 19 |
# File 'lib/winker/api_methods.rb', line 15 def post(path, params = nil) response = super @server_time_dif = Time.parse(response.headers["date"]) - Time.now return response end |
#put(path, params = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/winker/api_methods.rb', line 9 def put(path, params = nil) response = super @server_time_dif = Time.parse(response.headers["date"]) - Time.now return response end |
#scenes ⇒ Object
50 51 52 53 |
# File 'lib/winker/api_methods.rb', line 50 def scenes response = get("/users/me/scenes") Winker::Scene.load_scenes(parse(response.body).data) end |
#update_device(type, id, options) ⇒ Object
75 76 77 78 |
# File 'lib/winker/api_methods.rb', line 75 def update_device(type, id, ) response = put("/#{type}s/#{id}", ) parse(response.body).data end |
#update_group(id, options) ⇒ Object
80 81 82 83 |
# File 'lib/winker/api_methods.rb', line 80 def update_group(id, ) response = post("/groups/#{id}/activate", ) parse(response.body).data end |