r_aurora 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 343e26bda585adf1932e816d4fea51f467e27ba3
4
+ data.tar.gz: 7e09ab22c848559017573caa17d0e751e246121a
5
+ SHA512:
6
+ metadata.gz: d05aa2a9eee06dc9195fc53584aa4cb712daced52e07d43008c6d971d5495ca2aacd927fc36281cf3e9c0a4b65e0747cdaf36195646a1ce1ef5e3982c004ce38
7
+ data.tar.gz: 47c93895087836441ba7c3971f37951e7027b3b6e0c3130605ab01104d844547555d48604f5cc74e6806bedcc940aee915531579dc93f08f3507ae66c38e2588
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in r_aurora.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 stevestofiel
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.
@@ -0,0 +1,113 @@
1
+ # RAurora
2
+
3
+ This gem provides a simple ruby interface to work with the Aurora OpenAPI.
4
+
5
+ _(See nanoleaf aurora OpenAPI docs in the developers section of their website `https://forum.nanoleaf.me/docs/openapi`)_
6
+ ## Installation
7
+
8
+ SORRY NOT QUITE READY TO INSTALL YET. THIS IS STILL A WIP...
9
+
10
+ ~~$ gem install r_aurora~~
11
+
12
+ ## Usage
13
+
14
+ `require 'r_aurora'`
15
+
16
+ Assuming you already have retrieved your api token, define the following parameters:
17
+
18
+ ```ruby
19
+ base = 'http://10.0.1.72' #put your aurora IP address here
20
+ api = 'api/v1/'
21
+ token = "51zzxpyupomWxisLiyjcVupDLINqqdHL/" #note the trailing slash...
22
+ ```
23
+ Instantiate the class
24
+ ```ruby
25
+ aurora = RAurora::Base.new(base, api, token)
26
+ ```
27
+
28
+ Then call the API:
29
+ ```ruby
30
+ request_type = "put"
31
+ payload = {"on": {"value": true}} #for on
32
+ payload = {"on": {"value": false}} #for off
33
+
34
+ aurora.on(request_type, "state/", payload)
35
+ ```
36
+
37
+ 1. the first parameter is the request type. Typically `get` or `put`.
38
+
39
+ 2. the second parameter below represents the node of the JSON structure as defined in the Open API docs. In this case `state/`
40
+
41
+ 3. The third parameter is the json payload, if needed, to pass with the request.
42
+
43
+
44
+ I used `method_missing` to synthesize the endpoint. This drastically reduced code duplication but I may change this in the future. You simply call the endpoint name as a method on the instance and it will auto generate the correct format for the request. You just need to use underscores in place of the camelcase names the API uses. For example if the endpoint in the API is `rhythmConnected` you would try to call `rhythm_connected` on the instance. See examples below.
45
+
46
+ ---
47
+
48
+ ## Examples of get requests:
49
+
50
+ ```ruby
51
+ request_type = "get"
52
+
53
+ aurora.rhythm_connected(request_type, "rhythm/")
54
+ ```
55
+ returns:
56
+
57
+ `"200"`
58
+
59
+ `"true"`
60
+ ```ruby
61
+ aurora.hardware_version(request_type, "rhythm/")
62
+ ```
63
+ returns:
64
+
65
+ `"200"`
66
+
67
+ `"\"1.4\""`
68
+ ```ruby
69
+ aurora.ct(request_type, "state/")
70
+ ```
71
+ returns:
72
+
73
+ "200"
74
+
75
+ {"value"=>4300, "max"=>6500, "min"=>1200}
76
+
77
+ ---
78
+
79
+ ## Examples of put requests:
80
+
81
+ ```ruby
82
+ request_type = "put"
83
+ ```
84
+ ```ruby
85
+ payload = {"on": {"value": false}}
86
+ aurora.on(request_type, "state/", payload)
87
+ ```
88
+ ```ruby
89
+ payload = {"brightness": {"value": 100, "duration": 1}}
90
+ aurora.brightness(request_type, "state/", payload)
91
+ ```
92
+ ```ruby
93
+ payload = {"hue": {"value": 120}}
94
+ aurora.hue(request_type, "state/", payload)
95
+ ```
96
+
97
+ ---
98
+
99
+ You can get ALL information about your aurora panels with the `info` command:
100
+
101
+ This is the only command that varies from the conventions detailed above.
102
+
103
+ ```ruby
104
+ auroro.info
105
+ ```
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stevestofiel/r_aurora.
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "r_aurora"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,55 @@
1
+ require "r_aurora/version"
2
+
3
+ module RAurora
4
+ class Base
5
+ require 'uri'
6
+ require 'net/http'
7
+ require 'json'
8
+
9
+ attr_reader :api, :token
10
+
11
+ def initialize(base, api, token)
12
+ @uri = URI(base)
13
+ @uri.port = "16021"
14
+ @api = api
15
+ @token = token
16
+ end
17
+
18
+ def info
19
+ req = ::Net::HTTP::Get.new(uri('',''))
20
+ res = ::Net::HTTP.start(@uri.hostname, @uri.port) {|http|
21
+ http.request(req)
22
+ }
23
+ JSON.parse res.body
24
+ end
25
+
26
+ private
27
+ def method_missing(method_name, request_type, domain, payload=nil)
28
+ api_endpoint = camel_case(method_name)
29
+ case request_type
30
+ when "get"
31
+ req = ::Net::HTTP::Get.new(uri(domain, api_endpoint))
32
+ when "put"
33
+ req = ::Net::HTTP::Put.new(uri(domain, api_endpoint))
34
+ req.body = payload.to_json
35
+ end
36
+ res = http_request(req)
37
+ p res.code
38
+ JSON.parse res.body rescue res.body
39
+ end
40
+
41
+ def http_request(req)
42
+ ::Net::HTTP.start(@uri.hostname, @uri.port) {|http|
43
+ http.request(req)
44
+ }
45
+ end
46
+
47
+ def uri(domain, endpoint)
48
+ URI.join(@uri, @api, @token, domain, endpoint)
49
+ end
50
+
51
+ def camel_case(method_name)
52
+ "#{method_name.to_s.split('_').collect(&:capitalize).join.sub(/^\w/) {$&.downcase}}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module RAurora
2
+ VERSION = "0.1.4"
3
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "r_aurora/version"
5
+ require 'net/http'
6
+ require 'json'
7
+ require 'uri'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "r_aurora"
11
+ spec.version = RAurora::VERSION
12
+ spec.authors = ["Steve Stofiel"]
13
+ spec.email = ["stevestofiel@mac.com"]
14
+
15
+ spec.summary = "Ruby Gem for Aurora OpenAPI"
16
+ spec.description = "Gem to work with Nanoleaf Aurora OpenAPI"
17
+ spec.homepage = "http://ds.stofnet.com"
18
+ spec.license = "MIT"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r_aurora
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Steve Stofiel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-29 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.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.0'
55
+ description: Gem to work with Nanoleaf Aurora OpenAPI
56
+ email:
57
+ - stevestofiel@mac.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/r_aurora.rb
72
+ - lib/r_aurora/version.rb
73
+ - r_aurora.gemspec
74
+ homepage: http://ds.stofnet.com
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby Gem for Aurora OpenAPI
99
+ test_files: []