sesame-ruby 0.1.2 → 1.0.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
- SHA1:
3
- metadata.gz: 081f92b213e23a8c277f645f5e12c36cf8cfad72
4
- data.tar.gz: f2ef6fa38cfcb145621ca1fd872d55764ab31223
2
+ SHA256:
3
+ metadata.gz: 2fc54666ff84ba64050d56a9e709518af3d1d9b987e2043faf2fe9569648187e
4
+ data.tar.gz: a87fcae71e0d571d1f52b21e260cda68d2a561100c55ae6de77fb3c27330ac0b
5
5
  SHA512:
6
- metadata.gz: 4b634285cb4210d1b201e5d71feb158e69a2e4522f1db9c42c06ef5fc354b7895fbc3d1e154deeb8309d470cd0020a2bd828cb82b1a21f73cba99350b262d7c8
7
- data.tar.gz: 6c861edb1b86e1dcff6eec9a4d196a7356a67e2a5ea1de989d23dd739403e0481a52275e8078683564a566912285e6ad4e83580f901dfd90c40446dbadd977e1
6
+ metadata.gz: e4a8c929f826776b4862de1a4ab5a9c5d988902470937ae008fafdef4d80bc434ca8adcd0d63e2838b5033c3dd52bc56c95730a2df338586d3134483a3f2b21b
7
+ data.tar.gz: eae3efe057655f100512f5d46354017834a5595da65d3360a1c4ca7573ae7c6395c7bed1bc4155f790f2ece123a96f39d7ea1380ccc2748db46e69408fd427c2
@@ -7,10 +7,19 @@ Naming/AccessorMethodName:
7
7
  Exclude:
8
8
  - 'lib/sesame/api.rb'
9
9
 
10
- Style/MethodMissing:
10
+ Style/MethodMissingSuper:
11
+ Exclude:
12
+ - 'spec/*.rb'
13
+
14
+ Style/MissingRespondToMissing:
11
15
  Exclude:
12
16
  - 'spec/*.rb'
13
17
 
14
18
  Metrics/BlockLength:
15
19
  Exclude:
16
20
  - 'spec/*.rb'
21
+ Style/FrozenStringLiteralComment:
22
+ Enabled: false
23
+
24
+ Style/NumericPredicate:
25
+ Enabled: false
@@ -10,7 +10,7 @@
10
10
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
11
  # URISchemes: http, https
12
12
  Metrics/LineLength:
13
- Max: 100
13
+ Max: 115
14
14
 
15
15
  # Offense count: 5
16
16
  Style/Documentation:
data/README.md CHANGED
@@ -25,18 +25,19 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- # Log into the API
29
- > client = Sesame::Client.new(email: 'abc@i-lovecandyhouse.co', password: 'super-strong-password')
30
- => #<Sesame::Client:0x007fa1a81771d0 user: abc@i-lovecandyhouse.co>
28
+ Please create the your auth token by logging into the [CANDY HOUSE Dashboard](https://my.candyhouse.co/) with your CANDY HOUSE account.
31
29
 
32
- # Get an array of all API-enabled devices associated with the account
30
+ > client = Sesame::Client.new(auth_token: 'your_auth_token')
31
+ => #<Sesame::Client:0x007fa1a81771d0>
32
+
33
+ # Get an array of all devices associated with the account
33
34
  > client.sesames
34
- => [#<Sesame::Sesame:0x007fa1aa3bb188 device_id: ABC1234567, nickname: Front door, is_unlocked: true, api_enabled: true, battery: 100>,
35
- #<Sesame::Sesame:0x007fa1aa3bb160 device_id: DEF7654321, nickname: Back door, is_unlocked: false, api_enabled: false, battery: 80>]
35
+ => [#<Sesame::Sesame:0x007fa1aa3bb188 device_id: ABC1234567>,
36
+ #<Sesame::Sesame:0x007fa1aa3bb160 device_id: DEF7654321>]
36
37
 
37
38
  # Get a single device
38
39
  > sesame = client.sesame(device_id: 'ABC1234567')
39
- => #<Sesame::Sesame:0x007fa1aa3bb188 device_id: ABC1234567, nickname: Front door, is_unlocked: true, api_enabled: true, battery: 100>
40
+ => [#<Sesame::Sesame:0x007fa1aa3bb188 device_id: ABC1234567>
40
41
 
41
42
  # Control the device
42
43
  > sesame.unlock
@@ -44,6 +45,16 @@ Or install it yourself as:
44
45
  > sesame.lock
45
46
  => true
46
47
 
48
+ # Show the device status
49
+ > sesame.locked?
50
+ => true
51
+ > sesame.battery
52
+ => 100
53
+
54
+ # Sync the device status
55
+ > sesame.refresh!
56
+ => [#<Sesame::Sesame:0x007fa1aa3bb188 device_id: ABC1234567>
57
+
47
58
  ## Contributing
48
59
 
49
60
  1. Fork it
@@ -1 +1 @@
1
- require File.expand_path('../sesame', __FILE__)
1
+ require File.expand_path('sesame', __dir__)
@@ -3,11 +3,7 @@ require 'json'
3
3
 
4
4
  module Sesame
5
5
  module Api
6
- ENDPOINT_URL = 'https://api.candyhouse.co/v1/'.freeze
7
-
8
- def authorized?
9
- !@auth_token.nil?
10
- end
6
+ ENDPOINT_URL = 'https://api.candyhouse.co/public'.freeze
11
7
 
12
8
  def client
13
9
  @client ||= Faraday.new(url: ENDPOINT_URL)
@@ -18,21 +14,16 @@ module Sesame
18
14
  self
19
15
  end
20
16
 
21
- def login(email:, password:)
22
- auth_response = post('accounts/login', email: email, password: password)
23
- auth_token(auth_response['authorization'])
24
- end
25
-
26
17
  def get_sesames
27
18
  get('sesames')
28
19
  end
29
20
 
30
21
  def get_sesame(device_id:)
31
- get("sesames/#{device_id}")
22
+ get("sesame/#{device_id}")
32
23
  end
33
24
 
34
- def control_sesame(device_id:, type:)
35
- post("sesames/#{device_id}/control", type: type)
25
+ def control_sesame(device_id:, command:)
26
+ post("sesame/#{device_id}", command: command)
36
27
  end
37
28
 
38
29
  def get(path)
@@ -47,7 +38,7 @@ module Sesame
47
38
  response = client.send(method) do |req|
48
39
  req.url path
49
40
  req.headers['Content-Type'] = 'application/json'
50
- req.headers['X-Authorization'] = @auth_token unless @auth_token.nil?
41
+ req.headers['Authorization'] = @auth_token unless @auth_token.nil?
51
42
  req.body = params.to_json unless params.nil?
52
43
  end
53
44
  parse_response(response)
@@ -56,6 +47,7 @@ module Sesame
56
47
  def parse_response(response)
57
48
  parsed_response = response.headers['Content-Length'].to_i > 0 ? JSON.parse(response.body) : ''
58
49
  raise Error.new(response.status, parsed_response) if response.status >= 400
50
+
59
51
  parsed_response
60
52
  end
61
53
  end
@@ -2,13 +2,12 @@ module Sesame
2
2
  class Client
3
3
  include Api
4
4
 
5
- def initialize(email:, password:)
6
- login(email: email, password: password)
7
- @email = email
5
+ def initialize(auth_token:)
6
+ auth_token(auth_token)
8
7
  end
9
8
 
10
9
  def sesames
11
- get_sesames['sesames'].collect do |sesame_attrs|
10
+ get_sesames.collect do |sesame_attrs|
12
11
  Sesame.new(sesame_attrs).auth_token(@auth_token)
13
12
  end
14
13
  end
@@ -18,7 +17,7 @@ module Sesame
18
17
  end
19
18
 
20
19
  def inspect
21
- %(#<#{self.class.name}:#{format('0x%.14x', (object_id << 1))} user: #{@email}>)
20
+ %(#<#{self.class.name}:#{format('0x%<object_id>.14x', object_id: (object_id << 1))}>)
22
21
  end
23
22
  end
24
23
  end
@@ -3,14 +3,13 @@ module Sesame
3
3
  attr_reader :status, :code
4
4
 
5
5
  def initialize(status, data)
6
- super(data['message'])
6
+ super(data['error'])
7
7
  @data = data
8
8
  @status = status
9
- @code = data['code'].to_i
10
9
  end
11
10
 
12
11
  def to_s
13
- %(#{@data['message']} HTTP: #{status}, API: #{@data['code']})
12
+ %(#{@data['error']} HTTP: #{status})
14
13
  end
15
14
  end
16
15
  end
@@ -10,39 +10,29 @@ module Sesame
10
10
  @state['device_id']
11
11
  end
12
12
 
13
- def nickname
14
- @state['nickname']
13
+ def locked?
14
+ truthy?(@state['locked'])
15
15
  end
16
-
17
- def unlocked?
18
- truthy?(@state['is_unlocked'])
19
- end
20
- alias is_unlocked unlocked?
16
+ alias locked locked?
21
17
 
22
18
  def state
23
- unlocked? ? 'unlocked' : 'locked'
24
- end
25
-
26
- def api_enabled?
27
- truthy?(@state['api_enabled'])
19
+ locked? ? 'locked' : 'unlocked'
28
20
  end
29
- alias api_enabled api_enabled?
30
21
 
31
22
  def battery
32
23
  @state['battery'].to_i
33
24
  end
34
25
 
35
26
  def lock
36
- control(type: 'lock')
27
+ control(command: 'lock')
37
28
  end
38
29
 
39
30
  def unlock
40
- control(type: 'unlock')
31
+ control(command: 'unlock')
41
32
  end
42
33
 
43
34
  def inspect
44
- details = @state.keys.collect { |k| "#{k}: #{send(k.to_sym)}" }.join(', ')
45
- %(#<#{self.class.name}:#{format('0x%.14x', (object_id << 1))} #{details}>)
35
+ %(#<#{self.class.name}:#{format('0x%<object_id>.14x', object_id: (object_id << 1))} device_id: #{device_id}>)
46
36
  end
47
37
 
48
38
  def refresh!
@@ -56,8 +46,8 @@ module Sesame
56
46
  (value == true) || (value == 'true')
57
47
  end
58
48
 
59
- def control(type:)
60
- control_sesame(device_id: device_id, type: type)
49
+ def control(command:)
50
+ control_sesame(device_id: device_id, command: command)
61
51
  refresh!
62
52
  true
63
53
  end
@@ -1,3 +1,3 @@
1
1
  module Sesame
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -1,5 +1,4 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'sesame/version'
5
4
 
@@ -18,18 +17,18 @@ Gem::Specification.new do |spec|
18
17
  end
19
18
  spec.require_paths = ['lib']
20
19
 
21
- spec.add_dependency 'json'
22
20
  spec.add_dependency 'faraday'
21
+ spec.add_dependency 'json'
23
22
 
24
23
  spec.add_development_dependency 'bundler', '~> 1.15'
25
- spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'coveralls'
25
+ spec.add_development_dependency 'faraday-detailed_logger'
27
26
  spec.add_development_dependency 'pry'
28
27
  spec.add_development_dependency 'pry-byebug'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
30
  spec.add_development_dependency 'rubocop'
30
31
  spec.add_development_dependency 'rubocop-rspec'
31
32
  spec.add_development_dependency 'simplecov'
32
33
  spec.add_development_dependency 'webmock'
33
- spec.add_development_dependency 'coveralls'
34
- spec.add_development_dependency 'faraday-detailed_logger'
35
34
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sesame-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael B. Klein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2019-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -53,33 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.15'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: faraday-detailed_logger
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -109,35 +109,35 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rubocop
112
+ name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '10.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '10.0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rubocop-rspec
126
+ name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '3.0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '3.0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: simplecov
140
+ name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: webmock
154
+ name: rubocop-rspec
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: coveralls
168
+ name: simplecov
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -179,7 +179,7 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: faraday-detailed_logger
182
+ name: webmock
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -235,8 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  requirements: []
238
- rubyforge_project:
239
- rubygems_version: 2.5.1
238
+ rubygems_version: 3.0.1
240
239
  signing_key:
241
240
  specification_version: 4
242
241
  summary: Ruby wrapper for the CANDYHOUSE Sesame API (https://docs.candyhouse.co/)