lono-api 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +39 -0
- data/.rspec +4 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +46 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/bin/setup +7 -0
- data/lib/lono-api.rb +12 -0
- data/lib/lono-api/.DS_Store +0 -0
- data/lib/lono-api/auth_url.rb +9 -0
- data/lib/lono-api/configuration.rb +39 -0
- data/lib/lono-api/device.rb +78 -0
- data/lib/lono-api/errors.rb +17 -0
- data/lib/lono-api/session_token.rb +29 -0
- data/lib/lono-api/version.rb +4 -0
- data/lono-api.gemspec +30 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1f24c0c3d05fab5762530f9241aae42a048ce7f6
|
4
|
+
data.tar.gz: 2542de29c3342991196c347aad5eeb4c0a319f3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa12307c41443b85c58a7c63c41ea0e2f0e7f5e0d1413d09dfee1a4ee424e919166181d5430c726c8df277cc91648b8793c0c67ba849eb2184e77c4e9c5e4e2f
|
7
|
+
data.tar.gz: 7cee3dd038d336c3e3915953337ee252bcf343d08a45bd1e562cab8df1ae0cbe7168e12326cdeabf70ff3ac8644c706dfdb29d6b90a4fe4df995c19e2dbd85d1
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalisation:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
.*.swp
|
39
|
+
.*.swo
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lono-api (0.0.3)
|
5
|
+
unirest (~> 1.1.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.8)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
json (1.8.3)
|
13
|
+
mime-types (1.25.1)
|
14
|
+
rake (10.4.2)
|
15
|
+
rest-client (1.6.9)
|
16
|
+
mime-types (~> 1.16)
|
17
|
+
rspec (3.3.0)
|
18
|
+
rspec-core (~> 3.3.0)
|
19
|
+
rspec-expectations (~> 3.3.0)
|
20
|
+
rspec-mocks (~> 3.3.0)
|
21
|
+
rspec-core (3.3.2)
|
22
|
+
rspec-support (~> 3.3.0)
|
23
|
+
rspec-expectations (3.3.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.3.0)
|
26
|
+
rspec-mocks (3.3.2)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.3.0)
|
29
|
+
rspec-support (3.3.0)
|
30
|
+
unirest (1.1.2)
|
31
|
+
addressable (~> 2.3.5)
|
32
|
+
json (~> 1.8.1)
|
33
|
+
rest-client (~> 1.6.7)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 1.10)
|
40
|
+
lono-api!
|
41
|
+
rake (~> 10.0)
|
42
|
+
rspec (~> 3.3.0)
|
43
|
+
unirest
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 1egoman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Lono::Api
|
2
|
+
|
3
|
+
This gem is used to interface with Lono's public API. For more information, you
|
4
|
+
can take a look at our [documentation](http://make.lono.io/docs).
|
5
|
+
|
6
|
+
Seriously, we owe a lot of this gem's code to [@austinrfnd](//github.com/austinrfnd). Thanks a lot!
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'lono-api'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install lono-api
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Configuration
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Lono.configure do |config|
|
30
|
+
config.client_secret = 'secret'
|
31
|
+
config.client_id = 'id'
|
32
|
+
config.access_token = 'access_token'
|
33
|
+
config.scope = ['write']
|
34
|
+
end
|
35
|
+
```
|
36
|
+
### Generate the Authentication URL
|
37
|
+
```ruby
|
38
|
+
auth_url = Lono::AuthUrl.fetch "http://redirect_here_on_success.com"
|
39
|
+
```
|
40
|
+
|
41
|
+
### Get A Session Token
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
session_token = Lono::SessionToken.fetch()
|
45
|
+
```
|
46
|
+
|
47
|
+
### Turn on a device's zone on and off
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
device = Lono::Device.new('device_id_name', session_token)
|
51
|
+
# turn zone one on
|
52
|
+
device.set_zone(0, true)
|
53
|
+
|
54
|
+
# turn zone one off
|
55
|
+
device.set_zone(0, false)
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
## Running Specs
|
65
|
+
|
66
|
+
```
|
67
|
+
rake
|
68
|
+
```
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lono-devices/lono-ruby
|
73
|
+
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
78
|
+
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/lib/lono-api.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "lono-api/version"
|
2
|
+
require "lono-api/configuration"
|
3
|
+
require "lono-api/errors"
|
4
|
+
require "lono-api/session_token"
|
5
|
+
require "lono-api/auth_url"
|
6
|
+
require "lono-api/device"
|
7
|
+
require "unirest"
|
8
|
+
require "uri"
|
9
|
+
require "json"
|
10
|
+
|
11
|
+
module Lono
|
12
|
+
end
|
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Lono
|
2
|
+
class << self
|
3
|
+
def configure
|
4
|
+
yield self
|
5
|
+
end
|
6
|
+
|
7
|
+
def client_id=(client_id)
|
8
|
+
@@client_id = client_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def client_id
|
12
|
+
@@client_id
|
13
|
+
end
|
14
|
+
|
15
|
+
def client_secret=(client_secret)
|
16
|
+
@@client_secret = client_secret
|
17
|
+
end
|
18
|
+
|
19
|
+
def client_secret
|
20
|
+
@@client_secret
|
21
|
+
end
|
22
|
+
|
23
|
+
def auth_token=(auth_token)
|
24
|
+
@@auth_token = auth_token
|
25
|
+
end
|
26
|
+
|
27
|
+
def auth_token
|
28
|
+
@@auth_token
|
29
|
+
end
|
30
|
+
|
31
|
+
def scope=(scope)
|
32
|
+
@@scope = scope
|
33
|
+
end
|
34
|
+
|
35
|
+
def scope
|
36
|
+
@@scope
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Lono
|
2
|
+
class Device
|
3
|
+
VALID_DEVICE_REGEX = /[a-f0-9]{24}/
|
4
|
+
|
5
|
+
attr_reader :id, :session_token
|
6
|
+
|
7
|
+
def initialize(device_id, session_token)
|
8
|
+
@id = device_id
|
9
|
+
@session_token = session_token
|
10
|
+
validate!
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_zone(zone_id, action)
|
14
|
+
query_device @id, {
|
15
|
+
:url => "zones/#{zone_id}/#{action and "on" or "off"}",
|
16
|
+
:method => "post"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def set_led(color, brightness)
|
21
|
+
query_device @id, {
|
22
|
+
:url => "state",
|
23
|
+
:method => "post",
|
24
|
+
:body => {
|
25
|
+
:color => color,
|
26
|
+
:brightness => brightness
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_led_options(options)
|
32
|
+
query_device @id, {
|
33
|
+
:url => "state",
|
34
|
+
:method => "post",
|
35
|
+
:body => options
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
# other api methods
|
42
|
+
# def something_else do
|
43
|
+
# query_device @id, {
|
44
|
+
# :url => "route/that/does/what/we/want"
|
45
|
+
# :method => "post"
|
46
|
+
# }
|
47
|
+
# end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def query_device(device_id, query)
|
52
|
+
url = "http://make.lono.io/api/#{API_VERSION}/devices/#{device_id}/#{query[:url]}"
|
53
|
+
|
54
|
+
response = Unirest.send(
|
55
|
+
query[:method].downcase,
|
56
|
+
url,
|
57
|
+
headers: {
|
58
|
+
"Accept" => "application/json",
|
59
|
+
"content-type" => "application/json",
|
60
|
+
"Authorization" => "bearer #{@session_token.access_token}"
|
61
|
+
},
|
62
|
+
parameters: query[:body].to_json
|
63
|
+
)
|
64
|
+
|
65
|
+
if response.code == 200 and response.body.has_key? "name" and response.body["name"] =~ /success/
|
66
|
+
true
|
67
|
+
else
|
68
|
+
raise Lono::CloudUnsuccessfulError.new(response.body['error'])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate!
|
73
|
+
unless @id =~ VALID_DEVICE_REGEX
|
74
|
+
raise Lono::InvalidDeviceIdError.new("#{@id} isn't a valid Lono device id")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Lono
|
2
|
+
class ClientError < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class NoTokenError < ClientError
|
6
|
+
end
|
7
|
+
|
8
|
+
class ZoneNonSuccessError < ClientError
|
9
|
+
end
|
10
|
+
|
11
|
+
class CloudUnsuccessfulError < ClientError
|
12
|
+
end
|
13
|
+
|
14
|
+
# This feels right as an ArgumentError as opposed to inheriting from ClientError
|
15
|
+
class InvalidDeviceIdError < ArgumentError
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Lono
|
2
|
+
class SessionToken
|
3
|
+
attr_reader :access_token, :token_type
|
4
|
+
|
5
|
+
def initialize(session_token, token_type)
|
6
|
+
@access_token = session_token
|
7
|
+
@token_type = token_type || "bearer"
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def fetch
|
12
|
+
response = Unirest.post("http://make.lono.io/oauth/token",
|
13
|
+
headers: {Accept: "application/json"},
|
14
|
+
parameters: {
|
15
|
+
grant_type: "authorization_code",
|
16
|
+
client_id: Lono.client_id,
|
17
|
+
client_secret: Lono.client_secret,
|
18
|
+
code: Lono.auth_token
|
19
|
+
}
|
20
|
+
)
|
21
|
+
if response.body['access_token']
|
22
|
+
self.new(response.body['access_token'], response.body['token_type'])
|
23
|
+
else
|
24
|
+
raise Lono::NoTokenError.new(response.body['error'])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lono-api.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lono-api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lono-api"
|
8
|
+
spec.version = Lono::VERSION
|
9
|
+
spec.authors = ["1egoman"]
|
10
|
+
spec.email = ["rsg1egoman@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby client for the lono public api at http://make.lono.io}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "http://make.lono.io"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
# Unit testing
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.3.0"
|
27
|
+
|
28
|
+
# HTTP Library
|
29
|
+
spec.add_dependency "unirest", "~> 1.1.2"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lono-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 1egoman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: unirest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.2
|
69
|
+
description: Ruby client for the lono public api at http://make.lono.io
|
70
|
+
email:
|
71
|
+
- rsg1egoman@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".DS_Store"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/setup
|
85
|
+
- lib/lono-api.rb
|
86
|
+
- lib/lono-api/.DS_Store
|
87
|
+
- lib/lono-api/auth_url.rb
|
88
|
+
- lib/lono-api/configuration.rb
|
89
|
+
- lib/lono-api/device.rb
|
90
|
+
- lib/lono-api/errors.rb
|
91
|
+
- lib/lono-api/session_token.rb
|
92
|
+
- lib/lono-api/version.rb
|
93
|
+
- lono-api.gemspec
|
94
|
+
homepage: http://make.lono.io
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.8
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Ruby client for the lono public api at http://make.lono.io
|
118
|
+
test_files: []
|