irkit 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 4e995782033d14e6589ddf02df38cf7eccb8fa9b
4
- data.tar.gz: 43f37c11ae7a5c379c3b77be2203291196105de7
3
+ metadata.gz: 495dc7b5f1bd1ea2ce202c6ed9751743fdc5dd66
4
+ data.tar.gz: 3912b50c735eb862a1e9f98c4904a4766147bfc7
5
5
  SHA512:
6
- metadata.gz: 60b51d5dbf004ab1ee1a7b9069ec6e1129c7d01863cf42d89c00084e90239416b86156222090322d6042cfafae6ab70d5fb3a7d059c6b28cba3fbce9ffa7ad96
7
- data.tar.gz: c2cdb0d42918061cda7821c3dd858b726ac28dc5ff6a51b46980292352a42072e5df3654ffcfbded4f1bc184611f41ad4ac9bca43d1ec2ae52086ade715f54c3
6
+ metadata.gz: 83d087a4cd98abae59dc8256e385a71490c1a74e1833d2bb00bd33c5a03153b393561912ffcb19c8ba67a005372e335370bcfb55b3f94bd4d40c03808507b7fe
7
+ data.tar.gz: 0eb6c6e7d51b781ad8d728e0baa095c69c1d2b192199a85438a09a778fa6af900331e72d63656fb90ec250ee81e0cf072696b2891400d884a0c20e2060aa3c7b
@@ -1,3 +1,7 @@
1
+ === 0.0.2 2014-03-17
2
+
3
+ * add executable "irkit" command
4
+
1
5
  === 0.0.1 2014-03-16
2
6
 
3
7
  * first release
data/README.md CHANGED
@@ -20,6 +20,21 @@ for Debian/Ubuntu Linux
20
20
  % sudo apt-get install libavahi-compat-libdnssd-dev
21
21
  % gem install irkit
22
22
 
23
+ ## irkit command
24
+
25
+ % irkit --help
26
+ % irkit --get tv_on
27
+ % irkit --post tv_on
28
+ % irkit --post tv_on --address 192.168.0.123
29
+ % irkit --list
30
+ % irkit --delete tv_on
31
+
32
+ use Internet API
33
+
34
+ % irkit --device:add myhouse
35
+ % irkit --post tv_on --device myhouse
36
+ % irkit --device:delete myhouse
37
+
23
38
 
24
39
  ## Usage
25
40
 
@@ -32,11 +47,11 @@ IRKit has a HTTP-API that can be used from within the same LAN.
32
47
  ```ruby
33
48
  require 'irkit'
34
49
 
35
- # find IRKit with Bonjour
50
+ ## find IRKit with Bonjour
36
51
  irkit = IRKit::Device.find.first
37
52
 
38
- # or, specify with IP-Address
39
- # irkit = IRKit::Device.new(address: '192.168.0.123')
53
+ ## or, specify with IP-Address
54
+ irkit = IRKit::Device.new(address: '192.168.0.123')
40
55
 
41
56
  unless irkit
42
57
  STDERR.puts 'device not found'
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'irkit'
6
+ require 'args_parser'
7
+
8
+ args = ArgsParser.parse ARGV do
9
+ arg :get, "get IR Data", :alias => :read
10
+ arg :post, "post IR Data", :alias => :write
11
+ arg :delete, "delete IR Data"
12
+ arg :list, "show list of IR Data and Devices"
13
+ arg :address, "IRKit IP Address"
14
+ arg :device, "use Internet API"
15
+ arg "device:add", "save clientkey and deviceid for Internet API"
16
+ arg "device:delete", "delete clientkey and deviceid"
17
+ arg :version, "show version", :alias => :v
18
+ arg :help, "show help", :alias => :h
19
+ end
20
+
21
+ if args.has_option? :version
22
+ puts "IRKit Client for Ruby v#{IRKit::VERSION}"
23
+ exit
24
+ end
25
+
26
+ binname = File.basename __FILE__
27
+ if args.has_option? :help or
28
+ (!args.has_param?(:get) and !args.has_param?(:post) and
29
+ !args.has_option?(:list) and !args.has_param?(:delete) and
30
+ !args.has_param?(:device) and !args.has_param?("device:add") and
31
+ !args.has_param?("device:delete"))
32
+ STDERR.puts "IRKit v#{IRKit::VERSION}"
33
+ STDERR.puts " https://github.com/shokai/ruby-irkit"
34
+ STDERR.puts
35
+ STDERR.puts args.help
36
+ STDERR.puts
37
+ STDERR.puts "e.g."
38
+ STDERR.puts " % #{binname} --get tv_on"
39
+ STDERR.puts " % #{binname} --post tv_on"
40
+ STDERR.puts " % #{binname} --post tv_on --address 192.168.0.123"
41
+ STDERR.puts " % #{binname} --delete tv_on"
42
+ STDERR.puts " % #{binname} --device:add myhouse"
43
+ STDERR.puts " % #{binname} --post tv_on --device myhouse"
44
+ STDERR.puts " % #{binname} --device:delete myhouse"
45
+ exit
46
+ end
47
+
48
+ if args.has_option? :list
49
+ puts "== Data"
50
+ IRKit::App::Data.IR.each do |k,v|
51
+ puts k
52
+ end
53
+ puts "== Devices"
54
+ IRKit::App::Data.Device.each do |k,v|
55
+ puts "#{k}\tInternet API"
56
+ end
57
+ IRKit::Device.find.each do |device|
58
+ puts "#{device.address}\t#{device.bonjour_name}"
59
+ end
60
+ exit
61
+ end
62
+
63
+ if args.has_param? :delete
64
+ name = args[:delete]
65
+ print %Q{delete IR-Data "#{name}"? [Y/n] > }
66
+ exit 1 if STDIN.gets.strip.downcase =~ /n/
67
+ IRKit::App::Data.IR.delete name
68
+ IRKit::App::Data.save
69
+ puts %Q{"#{name}" delete!}
70
+ exit
71
+ end
72
+
73
+ if args.has_param? "device:delete"
74
+ name = args["device:delete"]
75
+ print %Q{delete Device "#{name}"? [Y/n] > }
76
+ exit 1 if STDIN.gets.strip.downcase =~ /n/
77
+ IRKit::App::Data.Device.delete name
78
+ IRKit::App::Data.save
79
+ puts %Q{"#{name}" delete!}
80
+ exit
81
+ end
82
+
83
+ if args.has_param? :address
84
+ irkit = IRKit::Device.new(address: args[:address])
85
+ elsif args.has_param? :device
86
+ info = IRKit::App::Data.Device[ args[:device] ]
87
+ irkit = IRKit::InternetAPI.new(clientkey: info.clientkey, deviceid: info.deviceid)
88
+ else
89
+ irkit = IRKit::Device.find.first
90
+ end
91
+
92
+ unless irkit
93
+ STDERR.puts "IRKit not found"
94
+ exit 1
95
+ end
96
+
97
+ p irkit
98
+
99
+ if args.has_param? :get
100
+ name = args[:get]
101
+ if IRKit::App::Data.IR.has_key? name
102
+ print %Q{overwrite "#{name}"? [Y/n] > }
103
+ exit 1 if STDIN.gets.strip.downcase =~ /n/
104
+ end
105
+ unless res = irkit.get_messages
106
+ STDERR.puts "IR data not found"
107
+ exit 1
108
+ end
109
+ if irkit.kind_of? IRKit::InternetAPI
110
+ ir_data = res.message
111
+ else
112
+ ir_data = res
113
+ end
114
+ puts ir_data.to_json
115
+ IRKit::App::Data.IR[name] = ir_data
116
+ IRKit::App::Data.save
117
+ puts %Q{"#{name}" saved!}
118
+ exit
119
+ end
120
+
121
+ if args.has_param? :post
122
+ name = args[:post]
123
+ puts %Q{post "#{name}"}
124
+ ir_data = IRKit::App::Data.IR[name]
125
+ res = irkit.post_messages ir_data
126
+ case res.code
127
+ when 200
128
+ puts "success!"
129
+ else
130
+ STDERR.puts res
131
+ end
132
+ end
133
+
134
+ if args.has_param? "device:add"
135
+ name = args["device:add"]
136
+ if IRKit::App::Data.Device.has_key? name
137
+ print %Q{overwrite "#{name}"? [Y/n] > }
138
+ exit 1 if STDIN.gets.strip.downcase =~ /n/
139
+ end
140
+ token = irkit.get_token
141
+ puts "token:\t#{token}"
142
+ res = irkit.get_key_and_deviceid(token)
143
+
144
+ puts "clientkey:\t#{res.clientkey}"
145
+ puts "deviceid:\t#{res.deviceid}"
146
+ IRKit::App::Data.Device[name] = res
147
+ IRKit::App::Data.save
148
+ puts %Q{"#{name}" saved!}
149
+ exit
150
+ end
@@ -12,5 +12,7 @@ require "irkit/device"
12
12
  require "irkit/find"
13
13
  require "irkit/internet_api"
14
14
 
15
+ require "irkit/app/data"
16
+
15
17
  module IRKit
16
18
  end
@@ -0,0 +1,21 @@
1
+ require 'yaml'
2
+
3
+ module IRKit
4
+ module App
5
+
6
+ DATA_FILE = ENV["IRKIT_DATA_FILE"] || File.expand_path('.irkit.json', ENV['HOME'])
7
+
8
+ if File.exists?(DATA_FILE)
9
+ Data = Hashie::Mash.new JSON.parse(File.open(DATA_FILE).read)
10
+ else
11
+ Data = Hashie::Mash.new("IR" => {}, "Device" => {})
12
+ end
13
+
14
+ def Data.save
15
+ File.open DATA_FILE, "w+" do |f|
16
+ f.write self.to_json
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module IRKit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
@@ -111,7 +111,8 @@ dependencies:
111
111
  description: IRKit Client for Ruby
112
112
  email:
113
113
  - hashimoto@shokai.org
114
- executables: []
114
+ executables:
115
+ - irkit
115
116
  extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
@@ -121,8 +122,10 @@ files:
121
122
  - LICENSE.txt
122
123
  - README.md
123
124
  - Rakefile
125
+ - bin/irkit
124
126
  - irkit.gemspec
125
127
  - lib/irkit.rb
128
+ - lib/irkit/app/data.rb
126
129
  - lib/irkit/device.rb
127
130
  - lib/irkit/error.rb
128
131
  - lib/irkit/find.rb