switchbot 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cb3387bfe82f6fc5c092ba2f6b668c0480715cfc3e581ffd2999440aaab6998
4
- data.tar.gz: a4968d05dd35cbfe7e744a3cbfcde6d48a9c1cc3881ec7ef5d55c1027a6a408b
3
+ metadata.gz: 990f1f755928da1c7b552986461ef23fe759e174fa3bfac50e71c302a1602769
4
+ data.tar.gz: cf07e66ff95980862c53a24cda08c930d0e5b51f4c3b08bf17b663198294a5af
5
5
  SHA512:
6
- metadata.gz: f27d2fc65ac8c77f98d4fc0cc3d8b629acb703a73132e02c8452397ee9fd619b57d0731f83b743a43e3190f79292647d70d55e7775f20490393816133b859494
7
- data.tar.gz: 58752367da471d48b7c8b0e5f743600d2c83b69b079005791168e927906cda137626fa5e50a826eb05da5cc123349ffa577d455c82b76508b60ac0223016138b
6
+ metadata.gz: c1aadb12d0af5102103b9304aeae71300ca75e7828552bb43ed778a91c39e6b38999a00717e1e090cc7f388dd7ce024f7ca5b6bb0aa3af562be05b1598c6cf04
7
+ data.tar.gz: 774fbf9e8bb38df81d15af448c29aa0b0b1b10a1523f24b545e1181736f2b6692dc0d44a4d34f82e2e3c452aeab34218a63564e3423a1c020384cdf10c83774f
data/.rubocop.yml CHANGED
@@ -3,3 +3,8 @@ AllCops:
3
3
 
4
4
  Style/Documentation:
5
5
  Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - switchbot.gemspec
10
+ - spec/**/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## Unreleased
2
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.2.0...main)
3
+
4
+ ## v0.2.0
5
+ [full changelog](http://github.com/ytkg/switchbot/compare/v0.1.0...v0.2.0)
6
+
7
+ * Add resource methods
8
+ * https://github.com/ytkg/switchbot/pull/2
9
+ * Support scenes endpoint
10
+ * https://github.com/ytkg/switchbot/pull/1
11
+
12
+ ## v0.1.0
13
+ * first release
data/README.md CHANGED
@@ -46,6 +46,8 @@ client.devices
46
46
  # Get device status
47
47
  # GET https://api.switch-bot.com/v1.0/devices/C271111EC0AB/status
48
48
  client.status(device_id: 'C271111EC0AB')
49
+ # or
50
+ client.device('C271111EC0AB').status
49
51
  #=> {:status_code=>100,
50
52
  # :body=>
51
53
  # {:device_id=>"C271111EC0AB",
@@ -61,6 +63,32 @@ client.commands(device_id: '210', command: 'turnOn')
61
63
  #=> {:status_code=>100,
62
64
  # :body=>{},
63
65
  # :message=>"success"}
66
+
67
+ # Get scene list
68
+ # GET https://api.switch-bot.com/v1.0/scenes
69
+ client.scenes
70
+ #=> {:status_code=>100,
71
+ # :body=>
72
+ # [{:scene_id=>"T02-20200804130110",
73
+ # :scene_name=>"Close Office Devices"},
74
+ # {:scene_id=>"T02-202009221414-48924101",
75
+ # :scene_name=>"Set Office AC to 25"},
76
+ # {:scene_id=>"T02-202011051830-39363561",
77
+ # :scene_name=>"Set Bedroom to 24"},
78
+ # {:scene_id=>"T02-202011051831-82928991",
79
+ # :scene_name=>"Turn off home devices"},
80
+ # {:scene_id=>"T02-202011062059-26364981",
81
+ # :scene_name=>"Set Bedroom to 26 degree"}],
82
+ # :message=>"success"}
83
+
84
+ # Execute manual scenes
85
+ # POST https://api.switch-bot.com/v1.0/scenes/T02-202009221414-48924101/execute
86
+ client.execute(scene_id: 'T02-202009221414-48924101')
87
+ # or
88
+ client.scene('T02-202009221414-48924101').execute
89
+ #=> {:status_code=>100,
90
+ # :body=>{},
91
+ # :message=>"success"}
64
92
  ```
65
93
 
66
94
  ## Development
data/lib/switchbot.rb CHANGED
@@ -6,6 +6,8 @@ require 'json'
6
6
  require 'active_support/all'
7
7
  require_relative 'switchbot/version'
8
8
  require_relative 'switchbot/client'
9
+ require_relative 'switchbot/device'
10
+ require_relative 'switchbot/scene'
9
11
 
10
12
  module Switchbot
11
13
  class Error < StandardError; end
@@ -15,6 +15,10 @@ module Switchbot
15
15
  )
16
16
  end
17
17
 
18
+ def device(device_id)
19
+ Device.new(client: self, device_id: device_id)
20
+ end
21
+
18
22
  def status(device_id:)
19
23
  request(
20
24
  http_method: :get,
@@ -34,6 +38,24 @@ module Switchbot
34
38
  )
35
39
  end
36
40
 
41
+ def scenes
42
+ request(
43
+ http_method: :get,
44
+ endpoint: 'v1.0/scenes'
45
+ )
46
+ end
47
+
48
+ def scene(scene_id)
49
+ Scene.new(client: self, scene_id: scene_id)
50
+ end
51
+
52
+ def execute(scene_id:)
53
+ request(
54
+ http_method: :post,
55
+ endpoint: "/v1.0/scenes/#{scene_id}/execute"
56
+ )
57
+ end
58
+
37
59
  private
38
60
 
39
61
  def headers
@@ -44,7 +66,7 @@ module Switchbot
44
66
  end
45
67
 
46
68
  def connection
47
- @connection ||= Faraday.new(url: API_ENDPOINT, headers: headers) do |conn|
69
+ Faraday.new(url: API_ENDPOINT, headers: headers) do |conn|
48
70
  conn.request :json
49
71
  end
50
72
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Switchbot
4
+ class Device
5
+ attr_reader :client, :device_id
6
+
7
+ def initialize(client:, device_id:)
8
+ @client = client
9
+ @device_id = device_id
10
+ end
11
+
12
+ def status
13
+ client.status(device_id: device_id)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Switchbot
4
+ class Scene
5
+ attr_reader :client, :scene_id
6
+
7
+ def initialize(client:, scene_id:)
8
+ @client = client
9
+ @scene_id = scene_id
10
+ end
11
+
12
+ def execute
13
+ client.execute(scene_id: scene_id)
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchbot
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/switchbot.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = 'https://github.com/ytkg/switchbot'
21
- # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiki Takagi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -133,6 +133,7 @@ files:
133
133
  - ".gitignore"
134
134
  - ".rspec"
135
135
  - ".rubocop.yml"
136
+ - CHANGELOG.md
136
137
  - CODE_OF_CONDUCT.md
137
138
  - Gemfile
138
139
  - LICENSE.txt
@@ -142,6 +143,8 @@ files:
142
143
  - bin/setup
143
144
  - lib/switchbot.rb
144
145
  - lib/switchbot/client.rb
146
+ - lib/switchbot/device.rb
147
+ - lib/switchbot/scene.rb
145
148
  - lib/switchbot/version.rb
146
149
  - switchbot.gemspec
147
150
  homepage: https://github.com/ytkg/switchbot
@@ -150,6 +153,7 @@ licenses:
150
153
  metadata:
151
154
  homepage_uri: https://github.com/ytkg/switchbot
152
155
  source_code_uri: https://github.com/ytkg/switchbot
156
+ changelog_uri: https://github.com/ytkg/switchbot/blob/main/CHANGELOG.md
153
157
  post_install_message:
154
158
  rdoc_options: []
155
159
  require_paths: