rtelldus 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f940a6aab779967fee354bcc109c600f0d3d7cc
4
+ data.tar.gz: 1d41eac1fcbfb81361b5b3c6f8b46c838c16f6e5
5
+ SHA512:
6
+ metadata.gz: 9d5733cf53cf602169193146b9e5190e227ea8a787dee98c1b897b648311108696dbbce215f24b6e138578bd1838ea35b364b0ca69566359740db1908e2ee5ac
7
+ data.tar.gz: fe0447ce18710619834bfb5b8d86f307e8fe73ca486e146464384c9b32b9879c483d887c64b696631b092c4d7fef6d8d7cc7e61ca375ffc671b791e5781d9bc8
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ lib/config.yaml
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *sublime*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rtelldus.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eric Ripa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Rtelldus
2
+
3
+ Ruby Framework for accessing the Telldus Live! API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rtelldus'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rtelldus
18
+
19
+ ## Usage
20
+
21
+ Generate your Telldus public and private keys at [api.telldus.com](http://api.telldus.com/keys/index)
22
+
23
+ Use Rtelldus.authorize to authenticate and get an access_token. The first time you run you will have to follow the onscreen instructions to properly authenticate using OAuth, the public and private keys will be saved together with the access token and access secret in ~/.rtelldus
24
+
25
+ Authorize will be run automatically on each call if not manually run before, so you can simply just run the calls if you'd like.
26
+
27
+ ### Example usage:
28
+
29
+ require "rtelldus"
30
+
31
+ # Authorize
32
+ Rtelldus.authorize
33
+
34
+ # List all registered devices:
35
+ Rtelldus.devices_list
36
+
37
+ # Get the ID for the first listed device:
38
+ Rtelldus.devices_list["device"].first["id"]
39
+
40
+ # Turn on device:
41
+ Rtelldus.device_turn_on "330108"
42
+
43
+ # Turn off device:
44
+ Rtelldus.device_turn_off "330108"
45
+
46
+ # Dim a device (value between 0 and 255)L
47
+ Rtelldus.device_dim "330108", 0
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Rtelldus
2
+ VERSION = "1.0.0"
3
+ end
data/lib/rtelldus.rb ADDED
@@ -0,0 +1,113 @@
1
+ require "rtelldus/version"
2
+ require 'oauth'
3
+ require 'json'
4
+ require 'user_config'
5
+
6
+ module Rtelldus
7
+ @uconf = UserConfig.new(".rtelldus")
8
+ def self.authorize
9
+ # Get API settings
10
+ unless File.exists? @uconf['api_settings.yaml'].path
11
+ # No configuration exists, let's request some credentials from the user
12
+ # Fetch the public and private keys from command line
13
+ puts "The first time you use the API you need to enter your Public and Private keys, they can be generated at:"
14
+ puts "\thttp://api.telldus.com/keys/index"
15
+ puts "\nPublic Key:"
16
+ public_key = $stdin.gets.strip
17
+ @uconf["api_settings.yaml"]["consumer_key"] = public_key
18
+ puts "\nPrivate Key:"
19
+ private_key = $stdin.gets.strip
20
+ @uconf["api_settings.yaml"]["consumer_secret"] = private_key
21
+ ## Persistent settings
22
+ @uconf["api_settings.yaml"]["api_host"] = "http://api.telldus.com"
23
+ @uconf["api_settings.yaml"]["request_token_path"] = "/oauth/requestToken"
24
+ @uconf["api_settings.yaml"]["access_token_path"] = "/oauth/accessToken"
25
+ @uconf["api_settings.yaml"]["authorize_path"] = "/oauth/authorize"
26
+ # Save for later use
27
+ @uconf["api_settings.yaml"].save
28
+ end
29
+
30
+ # Setup OAuth
31
+ consumer_options = { :site => @uconf["api_settings.yaml"]['api_host'],
32
+ :authorize_path => @uconf["api_settings.yaml"]['authorize_path'],
33
+ :request_token_path => @uconf["api_settings.yaml"]['request_token_path'],
34
+ :access_token_path => @uconf["api_settings.yaml"]['access_token_path'] }
35
+ consumer = OAuth::Consumer.new(@uconf["api_settings.yaml"]['consumer_key'], @uconf["api_settings.yaml"]['consumer_secret'], consumer_options)
36
+
37
+ if File.exists? @uconf["api_token.yaml"].path
38
+ @access_token = OAuth::AccessToken.new(consumer, @uconf["api_token.yaml"]["access_token"], @uconf["api_token.yaml"]["access_secret"])
39
+ else
40
+ # No configuration exists, let's request some access tokens
41
+ # Fetch a new access token and secret from the command line
42
+ request_token = consumer.get_request_token
43
+ puts "Copy and paste the following URL in your browser:"
44
+ puts "\t#{request_token.authorize_url}"
45
+ puts "When you sign in and accept, press enter.."
46
+ verifier = $stdin.gets.strip
47
+ access_token = request_token.get_access_token(:oauth_verifier => verifier)
48
+ # Save the token and secret so the script can be used automatically in the future
49
+ @uconf["api_token.yaml"]["access_token"] = access_token.token
50
+ @uconf["api_token.yaml"]["access_secret"] = access_token.secret
51
+ @uconf["api_token.yaml"].save
52
+ @access_token = OAuth::AccessToken.new(consumer, @uconf["api_token.yaml"]["access_token"], @uconf["api_token.yaml"]["access_secret"])
53
+ end
54
+ end
55
+
56
+ ## Clients
57
+ def self.clients_list
58
+ authorize unless @access_token
59
+ json_txt = @access_token.get("/json/clients/list", 'x-li-format' => 'json').body
60
+ clients = JSON.parse(json_txt)
61
+ end
62
+
63
+ ## Devices
64
+ def self.devices_list
65
+ authorize unless @access_token
66
+ json_txt = @access_token.get("/json/devices/list", 'x-li-format' => 'json').body
67
+ devices = JSON.parse(json_txt)
68
+ end
69
+
70
+ def self.device_info device_id
71
+ authorize unless @access_token
72
+ json_txt = @access_token.post("/json/device/info", {"id" => device_id}, 'x-li-format' => 'json').body
73
+ status = JSON.parse(json_txt)
74
+ end
75
+
76
+ def self.device_turn_on device_id
77
+ authorize unless @access_token
78
+ json_txt = @access_token.post("/json/device/turnOn", {"id" => device_id}, 'x-li-format' => 'json').body
79
+ status = JSON.parse(json_txt)
80
+ end
81
+
82
+ def self.device_turn_off device_id
83
+ authorize unless @access_token
84
+ json_txt = @access_token.post("/json/device/turnOff", {"id" => device_id}, 'x-li-format' => 'json').body
85
+ status = JSON.parse(json_txt)
86
+ end
87
+
88
+ def self.device_dim device_id, level
89
+ raise "Invalid dimlevel, this value should be 0-255" if level < 0 or level > 255
90
+ authorize unless @access_token
91
+ json_txt = @access_token.post("/json/device/dim", {"id" => device_id, "level" => level}, 'x-li-format' => 'json').body
92
+ status = JSON.parse(json_txt)
93
+ end
94
+
95
+ def self.device_bell device_id
96
+ authorize unless @access_token
97
+ json_txt = @access_token.post("/json/device/bell", {"id" => device_id}, 'x-li-format' => 'json').body
98
+ status = JSON.parse(json_txt)
99
+ end
100
+
101
+ ## Sensors
102
+ def self.sensors_list
103
+ authorize unless @access_token
104
+ json_txt = @access_token.get("/json/sensors/list", 'x-li-format' => 'json').body
105
+ devices = JSON.parse(json_txt)
106
+ end
107
+
108
+ def self.sensor_info sensor_id
109
+ authorize unless @access_token
110
+ json_txt = @access_token.post("/json/sensor/info", {"id" => sensor_id}, 'x-li-format' => 'json').body
111
+ status = JSON.parse(json_txt)
112
+ end
113
+ end
data/rtelldus.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rtelldus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rtelldus"
8
+ spec.version = Rtelldus::VERSION
9
+ spec.authors = ["Eric Ripa"]
10
+ spec.email = ["eric@ripa.io"]
11
+ spec.description = %q{Ruby Framework for Telldus Live! API}
12
+ spec.summary = %q{Ruby Framework for Telldus Live!}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "oauth"
24
+ spec.add_development_dependency "json"
25
+ spec.add_development_dependency "user_config"
26
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtelldus
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Ripa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-07 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: user_config
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby Framework for Telldus Live! API
84
+ email:
85
+ - eric@ripa.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/rtelldus.rb
96
+ - lib/rtelldus/version.rb
97
+ - rtelldus.gemspec
98
+ homepage: ''
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Ruby Framework for Telldus Live!
122
+ test_files: []