karotz 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ *.zip
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
data/.irbrc CHANGED
@@ -7,4 +7,4 @@ Karotz::Configuration.configure do |config|
7
7
  config.secret = ENV['KAROTZ_SECRET']
8
8
  end
9
9
 
10
- @client = Karotz::Client.new(Karotz::Client.start)
10
+ @client = Karotz::Client.create
data/README.rdoc CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Status: http://stillmaintained.com/phoet/karotz.png
4
4
  Build: http://travis-ci.org/phoet/karotz.png
5
+ Dependencies: http://gemnasium.com/phoet/karotz.png
5
6
 
6
7
  This gem is still in early development.
7
8
 
@@ -13,8 +14,24 @@ Supported methods:
13
14
  * led
14
15
  * tts (text to speach)
15
16
  * multimedia
17
+ * asr (automated speach recognition)
18
+ * webcam
19
+ * config
16
20
 
17
- Have a look at the whole api: http://dev.karotz.com/api/
21
+ Have a look at the whole api: http://dev.karotz.com/api
22
+
23
+ Read the HOW-TO: http://www.dzone.com/links/karotz_ruby_love.html
24
+
25
+ == Installation
26
+
27
+ gem install karotz
28
+
29
+ via Bundler:
30
+
31
+ # Gemfile
32
+ gem "karotz"
33
+
34
+ bundle install
18
35
 
19
36
  == Examples
20
37
 
data/descriptor.xml ADDED
@@ -0,0 +1,21 @@
1
+ <descriptor>
2
+ <version>0.0.3</version>
3
+ <accesses>
4
+ <access>tts</access>
5
+ <access>ears</access>
6
+ <access>led</access>
7
+ <access>multimedia</access>
8
+ <access>button</access>
9
+ <access>asr</access>
10
+ <access>webcam</access>
11
+ <access>rfid</access>
12
+ <access>http</access>
13
+ <access>file</access>
14
+ <access>serial</access>
15
+ </accesses>
16
+ <deployment>external</deployment>
17
+ <callback>http://ohrsome.heroku.com/karotz</callback>
18
+ <parameters>
19
+ <parameter key="showInstallUuid" value="true"/>
20
+ </parameters>
21
+ </descriptor>
data/karotz.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Peter Schröder"]
9
9
  s.email = ["phoetmail@googlemail.com"]
10
10
  s.homepage = "http://github.com/phoet/karotz"
11
- s.description = s.summary = %q{ruby bindings for karotz rest api}
11
+ s.description = s.summary = %q{ruby bindings for karotz rest api}
12
12
 
13
13
  s.rubyforge_project = "karotz"
14
14
 
@@ -24,9 +24,9 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "webmock"
25
25
  s.add_development_dependency "vcr"
26
26
 
27
- s.add_runtime_dependency "httpclient"
28
- s.add_runtime_dependency "httpi"
29
- s.add_runtime_dependency "crack"
27
+ s.add_runtime_dependency "httpclient", "~> 2.2"
28
+ s.add_runtime_dependency "httpi", "~> 0.9"
29
+ s.add_runtime_dependency "crack", "~> 0.3"
30
30
 
31
31
  s.add_runtime_dependency('jruby-openssl') if RUBY_PLATFORM == 'java'
32
32
  end
data/lib/karotz/client.rb CHANGED
@@ -58,13 +58,35 @@ module Karotz
58
58
  end
59
59
  alias :speak :tts
60
60
 
61
+ #============ASR================
62
+
63
+ def asr(interactive_id, params={})
64
+ request :asr, interactive_id, {:grammar => 'ruby', :lang => Language::ENGLISH}.merge(params)
65
+ end
66
+ alias :listen :asr
67
+
61
68
  #============MULTIMEDIA=========
62
69
 
63
70
  def multimedia(interactive_id, params={})
64
- request :multimedia, interactive_id, {:action => :play, :url => "http://www.jimwalls.net/mp3/ATeam.mp3"}.merge(params)
71
+ request :multimedia, interactive_id, {:action => Karotz::Multimedia::PLAY, :url => "http://www.jimwalls.net/mp3/ATeam.mp3"}.merge(params)
65
72
  end
66
73
  alias :play :multimedia
67
74
 
75
+ #============WEBCAM=========
76
+
77
+ def webcam(interactive_id, params={})
78
+ request :webcam, interactive_id, {:action => :photo, :url => "https://picasaweb.google.com/data/feed/api/phoet6/default/albumid/default"}.merge(params)
79
+ end
80
+ alias :snap :webcam
81
+ alias :cam :webcam
82
+
83
+ #============CONFIG=========
84
+
85
+ def config(interactive_id)
86
+ answer = perform_request(:config, interactive_id)
87
+ answer["ConfigResponse"]
88
+ end
89
+
68
90
  #============LIFE_CYCLE=========
69
91
 
70
92
  def start
@@ -79,7 +101,7 @@ module Karotz
79
101
  end
80
102
 
81
103
  def stop(interactive_id, params={})
82
- request :interactivemode, interactive_id, {:action => :stop}.merge(params)
104
+ request(:interactivemode, interactive_id, {:action => :stop}.merge(params))
83
105
  end
84
106
 
85
107
  def session # TODO multimedia-api is not blocking, so we need some whay to find out when we can kill the session properly
@@ -113,6 +135,11 @@ module Karotz
113
135
  private()
114
136
 
115
137
  def request(endpoint, interactive_id, params={})
138
+ answer = perform_request(endpoint, interactive_id, params)
139
+ raise "bad response from server" if answer["VoosMsg"].nil? || answer["VoosMsg"]["response"].nil? || answer["VoosMsg"]["response"]["code"] != "OK"
140
+ end
141
+
142
+ def perform_request(endpoint, interactive_id, params={})
116
143
  raise "interactive_id is needed!" unless interactive_id
117
144
  raise "endpoint is needed!" unless endpoint
118
145
  url = "#{API}#{endpoint}?#{create_query({ :interactiveid => interactive_id }.merge(params))}"
@@ -120,7 +147,7 @@ module Karotz
120
147
  response = HTTPI.get(url)
121
148
  answer = Crack::XML.parse(response.body)
122
149
  Configuration.logger.debug "answer was '#{answer}'"
123
- raise "bad response from server" if answer["VoosMsg"].nil? || answer["VoosMsg"]["response"].nil? || answer["VoosMsg"]["response"]["code"] != "OK"
150
+ answer
124
151
  end
125
152
 
126
153
  def create_query(params)
@@ -3,5 +3,6 @@ module Karotz
3
3
  ENGLISH = :EN
4
4
  GERMAN = :DE
5
5
  FRENCH = :FR
6
+ SPANISH = :ES
6
7
  end
7
8
  end
@@ -0,0 +1,15 @@
1
+ module Karotz
2
+ class Multimedia
3
+ PLAY = :play
4
+ PAUSE = :pause
5
+ RESUME = :resume
6
+ STOP = :stop
7
+ PREVIOUS = :previous
8
+ NEXT = :next
9
+ RECORD = :record
10
+ ALL_SONG = :allsong
11
+ FOLDER = :folder
12
+ ARTIST = :artist
13
+ GENRE = :genre
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Karotz
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/karotz.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "karotz/version"
2
2
  require "karotz/configuration"
3
+ require "karotz/multimedia"
3
4
  require "karotz/color"
4
5
  require "karotz/language"
5
6
  require "karotz/client"
@@ -0,0 +1,18 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.karotz.com:80/api/karotz/asr?grammar=ruby&interactiveid=61f280fd-88fc-469f-bded-fc2ead4152c4&lang=EN
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ content-length:
14
+ - '283'
15
+ connection:
16
+ - keep-alive
17
+ body: <VoosMsg><id>d7c49346-dc3a-4c32-ab18-95e1406967c7</id><correlationId>fa7690be-672e-4847-a7eb-4265be06e9a1</correlationId><interactiveId>61f280fd-88fc-469f-bded-fc2ead4152c4</interactiveId><callback>http://localhost:3000/karotz</callback><response><code>OK</code></response></VoosMsg>
18
+ http_version: '1.1'
@@ -0,0 +1,18 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.karotz.com:80/api/karotz/config?interactiveid=2f72fe9f-9c0a-4949-b1e6-5a402f125536
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ content-length:
14
+ - '511'
15
+ connection:
16
+ - keep-alive
17
+ body: <ConfigResponse><config><interruptible>false</interruptible><awake>false</awake><name>config</name><uuid>SOME_UUID</uuid><params><key>awake</key><value>false</value></params><params><key>interruptible</key><value>false</value></params><params><key>permanentTriggerActivator</key><value>false</value></params><params><key>scheduledDateTriggerActivator</key><value>false</value></params><params><key>scheduledTriggerActivator</key><value>false</value></params></config></ConfigResponse>
18
+ http_version: '1.1'
@@ -0,0 +1,18 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.karotz.com:80/api/karotz/webcam?action=photo&interactiveid=aa36d0a0-fcbd-4095-955b-9a6d53c2e3fc&url=https://picasaweb.google.com/data/feed/api/phoet6/default/albumid/default
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ content-length:
14
+ - '286'
15
+ connection:
16
+ - keep-alive
17
+ body: <VoosMsg><id>bec92e1c-e412-4bce-93f6-d89336c4f7f1</id><correlationId>84e5b955-4676-4511-9c1d-5de8b86f4755</correlationId><interactiveId>aa36d0a0-fcbd-4095-955b-9a6d53c2e3fc</interactiveId><callback>http://localhost:3000/karotz</callback><response><code>OK</code></response></VoosMsg>
18
+ http_version: '1.1'
data/spec/karotz_spec.rb CHANGED
@@ -45,8 +45,8 @@ module Karotz
45
45
 
46
46
  it "should look sad", :vcr => true do
47
47
  params = {
48
- :left => 90,
49
- :right => 90,
48
+ :left => 9,
49
+ :right => 9,
50
50
  :relative => false
51
51
  }
52
52
  Client.ears(@interactive_id, params)
@@ -76,7 +76,13 @@ module Karotz
76
76
 
77
77
  context "text to speach (tts)" do
78
78
  it "should say something", :vcr => true do
79
- Client.tts(@interactive_id)
79
+ Client.speak(@interactive_id)
80
+ end
81
+ end
82
+
83
+ context "automatic speach recognition (asr)" do
84
+ it "should listen to voice", :vcr => true do
85
+ Client.listen(@interactive_id)
80
86
  end
81
87
  end
82
88
 
@@ -86,6 +92,34 @@ module Karotz
86
92
  end
87
93
  end
88
94
 
95
+ context "webcam" do
96
+ it "should take a picture and upload it", :vcr => true do
97
+ Client.snap(@interactive_id)
98
+ end
99
+ end
100
+
101
+ context "config" do
102
+ it "should retrieve the config", :vcr => true do
103
+ Client.config(@interactive_id).should eql(
104
+ {
105
+ "config" => {
106
+ "interruptible"=>"false",
107
+ "awake"=>"false",
108
+ "name"=>"config",
109
+ "uuid"=>"SOME_UUID",
110
+ "params"=>[
111
+ {"key"=>"awake", "value"=>"false"},
112
+ {"key"=>"interruptible", "value"=>"false"},
113
+ {"key"=>"permanentTriggerActivator", "value"=>"false"},
114
+ {"key"=>"scheduledDateTriggerActivator", "value"=>"false"},
115
+ {"key"=>"scheduledTriggerActivator", "value"=>"false"}
116
+ ]
117
+ }
118
+ }
119
+ )
120
+ end
121
+ end
122
+
89
123
  context "lifecycle" do
90
124
  before(:each) do
91
125
  Configuration.configure do |config|
data/spec/spec_helper.rb CHANGED
@@ -26,7 +26,7 @@ RSpec.configure do |config|
26
26
  @api_key = ENV['KAROTZ_API_KEY']
27
27
  @secret = ENV['KAROTZ_SECRET']
28
28
  # retrieved via http://www.karotz.com/authentication/run/karotz/API_KEY
29
- @interactive_id = "209301e8-05a6-47b4-b257-600eb62f7d25"
29
+ @interactive_id = "aa36d0a0-fcbd-4095-955b-9a6d53c2e3fc"
30
30
 
31
31
  HTTPI.log = false
32
32
  Karotz::Configuration.reset
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karotz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-27 00:00:00.000000000 Z
12
+ date: 2011-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2160175000 !ruby/object:Gem::Requirement
16
+ requirement: &2160174660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2160175000
24
+ version_requirements: *2160174660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2160174580 !ruby/object:Gem::Requirement
27
+ requirement: &2160174240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2160174580
35
+ version_requirements: *2160174240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &2160174160 !ruby/object:Gem::Requirement
38
+ requirement: &2160173820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160174160
46
+ version_requirements: *2160173820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
- requirement: &2160173740 !ruby/object:Gem::Requirement
49
+ requirement: &2160173400 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160173740
57
+ version_requirements: *2160173400
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &2160173320 !ruby/object:Gem::Requirement
60
+ requirement: &2160189360 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2160173320
68
+ version_requirements: *2160189360
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
- requirement: &2160189280 !ruby/object:Gem::Requirement
71
+ requirement: &2160188940 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,40 +76,40 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2160189280
79
+ version_requirements: *2160188940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: httpclient
82
- requirement: &2160188860 !ruby/object:Gem::Requirement
82
+ requirement: &2160188440 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
- - - ! '>='
85
+ - - ~>
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: '2.2'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *2160188860
90
+ version_requirements: *2160188440
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: httpi
93
- requirement: &2160188440 !ruby/object:Gem::Requirement
93
+ requirement: &2160187940 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
- - - ! '>='
96
+ - - ~>
97
97
  - !ruby/object:Gem::Version
98
- version: '0'
98
+ version: '0.9'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2160188440
101
+ version_requirements: *2160187940
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: crack
104
- requirement: &2160188020 !ruby/object:Gem::Requirement
104
+ requirement: &2160187480 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: '0.3'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2160188020
112
+ version_requirements: *2160187480
113
113
  description: ruby bindings for karotz rest api
114
114
  email:
115
115
  - phoetmail@googlemail.com
@@ -127,14 +127,18 @@ files:
127
127
  - Guardfile
128
128
  - README.rdoc
129
129
  - Rakefile
130
+ - descriptor.xml
130
131
  - karotz.gemspec
131
132
  - lib/karotz.rb
132
133
  - lib/karotz/client.rb
133
134
  - lib/karotz/color.rb
134
135
  - lib/karotz/configuration.rb
135
136
  - lib/karotz/language.rb
137
+ - lib/karotz/multimedia.rb
136
138
  - lib/karotz/version.rb
139
+ - spec/cassettes/karotz/client_automatic_speach_recognition_asr_should_listen_to_voice.yml
137
140
  - spec/cassettes/karotz/client_automatic_speach_recognition_asr_should_say_something.yml
141
+ - spec/cassettes/karotz/client_config_should_retrieve_the_config.yml
138
142
  - spec/cassettes/karotz/client_ears_should_look_sad.yml
139
143
  - spec/cassettes/karotz/client_ears_should_make_the_bull.yml
140
144
  - spec/cassettes/karotz/client_ears_should_reset_the_ears.yml
@@ -148,6 +152,7 @@ files:
148
152
  - spec/cassettes/karotz/client_lifecycle_should_start_and_stop_the_interactivemode.yml
149
153
  - spec/cassettes/karotz/client_multimedia_should_play_mp3.yml
150
154
  - spec/cassettes/karotz/client_text_to_speach_tts_should_say_something.yml
155
+ - spec/cassettes/karotz/client_webcam_should_take_a_picture_and_upload_it.yml
151
156
  - spec/karotz_spec.rb
152
157
  - spec/spec_helper.rb
153
158
  homepage: http://github.com/phoet/karotz
@@ -175,7 +180,9 @@ signing_key:
175
180
  specification_version: 3
176
181
  summary: ruby bindings for karotz rest api
177
182
  test_files:
183
+ - spec/cassettes/karotz/client_automatic_speach_recognition_asr_should_listen_to_voice.yml
178
184
  - spec/cassettes/karotz/client_automatic_speach_recognition_asr_should_say_something.yml
185
+ - spec/cassettes/karotz/client_config_should_retrieve_the_config.yml
179
186
  - spec/cassettes/karotz/client_ears_should_look_sad.yml
180
187
  - spec/cassettes/karotz/client_ears_should_make_the_bull.yml
181
188
  - spec/cassettes/karotz/client_ears_should_reset_the_ears.yml
@@ -189,5 +196,6 @@ test_files:
189
196
  - spec/cassettes/karotz/client_lifecycle_should_start_and_stop_the_interactivemode.yml
190
197
  - spec/cassettes/karotz/client_multimedia_should_play_mp3.yml
191
198
  - spec/cassettes/karotz/client_text_to_speach_tts_should_say_something.yml
199
+ - spec/cassettes/karotz/client_webcam_should_take_a_picture_and_upload_it.yml
192
200
  - spec/karotz_spec.rb
193
201
  - spec/spec_helper.rb