dinabaztag 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +16 -0
- data/README.md +4 -0
- data/dinabaztag.gemspec +18 -0
- data/lib/dinabaztag/action/ear_movement.rb +39 -0
- data/lib/dinabaztag/action/led_light.rb +57 -0
- data/lib/dinabaztag/choreography.rb +26 -0
- data/lib/dinabaztag/message.rb +58 -0
- data/lib/dinabaztag/version.rb +3 -0
- data/lib/dinabaztag.rb +8 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
data/dinabaztag.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dinabaztag/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'dinabaztag'
|
7
|
+
s.version = Dinabaztag::VERSION
|
8
|
+
s.date = '2012-11-28'
|
9
|
+
s.summary = "Dinabaztag is a Ruby Wrapper for Nabaztag API!"
|
10
|
+
s.description = "Dinabaztag is a Ruby Wrapper for Nabaztag API!"
|
11
|
+
s.authors = ["Miklós Beöthy"]
|
12
|
+
s.email = 'beothy.miklos@digitalnatives.hu'
|
13
|
+
s.homepage = 'https://github.com/digitalnatives/dinabaztag'
|
14
|
+
s.files = `git ls-files`.split("\n").sort
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Dinabaztag
|
2
|
+
module Action
|
3
|
+
class EarMovement
|
4
|
+
|
5
|
+
attr_accessor :ear, :angle, :direction
|
6
|
+
|
7
|
+
def initialize( attrs = {} )
|
8
|
+
default_attributes = {
|
9
|
+
:ear => 'both',
|
10
|
+
:direction => 'forward',
|
11
|
+
:angle => 0
|
12
|
+
}
|
13
|
+
attrs = default_attributes.merge( attrs )
|
14
|
+
|
15
|
+
self.ear = attrs[:ear]
|
16
|
+
self.angle = attrs[:angle]
|
17
|
+
self.direction = attrs[:direction]
|
18
|
+
end
|
19
|
+
|
20
|
+
def chor_type
|
21
|
+
'motor'
|
22
|
+
end
|
23
|
+
|
24
|
+
def chor_datas( message_ear = self.ear )
|
25
|
+
if message_ear.to_s == 'both'
|
26
|
+
return [ chor_datas('left').first, chor_datas('right').first ]
|
27
|
+
else
|
28
|
+
return [ [
|
29
|
+
self.chor_type,
|
30
|
+
message_ear.to_s == 'right' ? 0 : 1,
|
31
|
+
self.angle,
|
32
|
+
0,
|
33
|
+
self.direction.to_s == 'forward' ? 0 : 1
|
34
|
+
].map{ |p| p.to_s }.join( "," ) ]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Dinabaztag
|
2
|
+
module Action
|
3
|
+
class LedLight
|
4
|
+
|
5
|
+
attr_accessor :led, :color
|
6
|
+
|
7
|
+
COLORS = {
|
8
|
+
:black => [ 0, 0, 0 ],
|
9
|
+
:red => [ 255, 0, 0 ],
|
10
|
+
:green => [ 0, 255, 0 ],
|
11
|
+
:blue => [ 0, 0, 255 ],
|
12
|
+
:yellow => [ 255, 255, 0 ]
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize( attrs = {} )
|
16
|
+
default_attributes = {
|
17
|
+
:color => 'green',
|
18
|
+
:led => 'middle'
|
19
|
+
}
|
20
|
+
attrs = default_attributes.merge( attrs )
|
21
|
+
attrs[:color] = COLORS[attrs[:color].to_sym] unless attrs[:color].is_a?(Array)
|
22
|
+
raise "undefined color" unless attrs[:color].is_a?(Array) && attrs[:color].size == 3
|
23
|
+
|
24
|
+
self.color = attrs[:color]
|
25
|
+
self.led = attrs[:led]
|
26
|
+
end
|
27
|
+
|
28
|
+
def led_value
|
29
|
+
if led.is_a?( Fixnum )
|
30
|
+
return led
|
31
|
+
else
|
32
|
+
case self.led.to_s
|
33
|
+
when 'bottom'
|
34
|
+
0
|
35
|
+
when 'left'
|
36
|
+
1
|
37
|
+
when 'middle'
|
38
|
+
2
|
39
|
+
when 'right'
|
40
|
+
3
|
41
|
+
when 'top'
|
42
|
+
4
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def chor_type
|
48
|
+
'led'
|
49
|
+
end
|
50
|
+
|
51
|
+
def chor_datas
|
52
|
+
[ ( [ self.chor_type, self.led_value ] + self.color ).flatten.join(",") ]
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Dinabaztag
|
2
|
+
class Choreography
|
3
|
+
|
4
|
+
attr_accessor :actions, :tempo
|
5
|
+
|
6
|
+
def initialize( tempo = 10)
|
7
|
+
self.actions = Hash.new { |hash, key| hash[key] = [] }
|
8
|
+
self.tempo = tempo
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_action( action_time, action )
|
12
|
+
self.actions[action_time] << action
|
13
|
+
end
|
14
|
+
|
15
|
+
def data
|
16
|
+
action_data = self.actions.map do |action_time,actions_at_time|
|
17
|
+
actions_at_time.map do |action|
|
18
|
+
action.chor_datas.map{ |chor_data| "#{action_time},#{chor_data}" }
|
19
|
+
end.join(",")
|
20
|
+
end.join(",")
|
21
|
+
|
22
|
+
"#{tempo},#{action_data}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module Dinabaztag
|
6
|
+
|
7
|
+
class Message
|
8
|
+
|
9
|
+
attr_accessor :exec_commands, :api_key, :language
|
10
|
+
|
11
|
+
def initialize( api_key, config = {} )
|
12
|
+
self.api_key = api_key
|
13
|
+
self.language = config[:language] || "hu"
|
14
|
+
reset
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
self.exec_commands = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def exec_choreography( choreography )
|
22
|
+
chor_api_url = "http://www.nabaztag.com/api/chor?data=#{choreography.data}"
|
23
|
+
|
24
|
+
exec_commands << "CH #{chor_api_url}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def play_sound( url )
|
28
|
+
exec_commands << "MU #{URI.encode(url)}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def say_message( message )
|
32
|
+
url = "http://translate.google.com/translate_tts?ie=UTF-8&q=#{message}&tl=#{self.language}"
|
33
|
+
|
34
|
+
play_sound(url)
|
35
|
+
end
|
36
|
+
|
37
|
+
def wait_for_previous_commands
|
38
|
+
exec_commands << "MW"
|
39
|
+
end
|
40
|
+
|
41
|
+
def perform
|
42
|
+
begin
|
43
|
+
exec_string = CGI.escape( exec_commands.join("\n") )
|
44
|
+
|
45
|
+
url = "http://www.nabaztag.com/nabaztags/#{self.api_key}/exec?command=#{exec_string}"
|
46
|
+
|
47
|
+
puts url
|
48
|
+
|
49
|
+
Net::HTTP.get( URI(url) )
|
50
|
+
|
51
|
+
reset
|
52
|
+
rescue => e
|
53
|
+
puts "Exception happened while calling api url: #{e.message}"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/dinabaztag.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
require File.expand_path('../dinabaztag/version', __FILE__)
|
5
|
+
require File.expand_path('../dinabaztag/message', __FILE__)
|
6
|
+
require File.expand_path('../dinabaztag/choreography', __FILE__)
|
7
|
+
require File.expand_path('../dinabaztag/action/ear_movement', __FILE__)
|
8
|
+
require File.expand_path('../dinabaztag/action/led_light', __FILE__)
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dinabaztag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Miklós Beöthy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Dinabaztag is a Ruby Wrapper for Nabaztag API!
|
15
|
+
email: beothy.miklos@digitalnatives.hu
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- README.md
|
24
|
+
- dinabaztag.gemspec
|
25
|
+
- lib/dinabaztag.rb
|
26
|
+
- lib/dinabaztag/action/ear_movement.rb
|
27
|
+
- lib/dinabaztag/action/led_light.rb
|
28
|
+
- lib/dinabaztag/choreography.rb
|
29
|
+
- lib/dinabaztag/message.rb
|
30
|
+
- lib/dinabaztag/version.rb
|
31
|
+
homepage: https://github.com/digitalnatives/dinabaztag
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Dinabaztag is a Ruby Wrapper for Nabaztag API!
|
55
|
+
test_files: []
|