karotz 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -40,6 +40,7 @@ via Bundler:
40
40
  config.install_id = ENV['KAROTZ_INSTALL_ID']
41
41
  config.api_key = ENV['KAROTZ_API_KEY']
42
42
  config.secret = ENV['KAROTZ_SECRET']
43
+ config.proxy = ENV['KAROTZ_PROXY']
43
44
  end
44
45
 
45
46
  # bare
@@ -59,3 +60,19 @@ via Bundler:
59
60
  karotz.ears
60
61
  [...]
61
62
  karotz.stop
63
+
64
+ == Railtie
65
+
66
+ The gem comes with two example Rake tasks, that are automatically included into your Rails application:
67
+
68
+ rake karotz:build:failed
69
+ rake karotz:build:normal
70
+
71
+ Both Tasks are examples of how you could use your Karotz in a CI system like Jenkins.
72
+
73
+ == License
74
+
75
+ "THE BEER-WARE LICENSE" (Revision 42):
76
+ ps@nofail.de[mailto:ps@nofail.de] wrote this file. As long as you retain this notice you
77
+ can do whatever you want with this stuff. If we meet some day, and you think
78
+ this stuff is worth it, you can buy me a beer in return Peter Schröder
data/lib/karotz/client.rb CHANGED
@@ -25,9 +25,6 @@ module Karotz
25
25
  self.class.respond_to?(meth) || super
26
26
  end
27
27
 
28
- API = "http://api.karotz.com/api/karotz/"
29
- DIGEST = OpenSSL::Digest::Digest.new('sha1')
30
-
31
28
  class << self
32
29
 
33
30
  #==========EARS=================
@@ -101,7 +98,7 @@ module Karotz
101
98
  Configuration.validate_credentials!
102
99
  url = start_url(Configuration.install_id, Configuration.api_key, Configuration.secret)
103
100
  Configuration.logger.debug "calling karotz api with url '#{url}'"
104
- response = HTTPI.get(url)
101
+ response = get(url)
105
102
  answer = Crack::XML.parse(response.body)
106
103
  Configuration.logger.debug "answer was '#{answer}'"
107
104
  raise "could not retrieve interactive_id" if answer["VoosMsg"].nil? || answer["VoosMsg"]["interactiveMode"].nil? || answer["VoosMsg"]["interactiveMode"]["interactiveId"].nil?
@@ -137,10 +134,10 @@ module Karotz
137
134
  'timestamp' => timestamp,
138
135
  }
139
136
  query = create_query(params)
140
- hmac = OpenSSL::HMAC.digest(DIGEST, secret, query)
137
+ hmac = OpenSSL::HMAC.digest(Configuration.digest, secret, query)
141
138
  encoded = Base64.encode64(hmac).chomp
142
139
  signed = CGI.escape(encoded)
143
- "#{API}start?#{query}&signature=#{signed}"
140
+ "#{Configuration.endpoint}start?#{query}&signature=#{signed}"
144
141
  end
145
142
 
146
143
  private()
@@ -150,12 +147,18 @@ module Karotz
150
147
  raise "bad response from server" if answer["VoosMsg"].nil? || answer["VoosMsg"]["response"].nil? || answer["VoosMsg"]["response"]["code"] != "OK"
151
148
  end
152
149
 
153
- def perform_request(endpoint, interactive_id, params={})
150
+ def get(url)
151
+ request = HTTPI::Request.new(url)
152
+ request.proxy = Configuration.proxy if Configuration.proxy
153
+ HTTPI.get request
154
+ end
155
+
156
+ def perform_request(action, interactive_id, params={})
154
157
  raise "interactive_id is needed!" unless interactive_id
155
- raise "endpoint is needed!" unless endpoint
156
- url = "#{API}#{endpoint}?#{create_query({ :interactiveid => interactive_id }.merge(params))}"
158
+ raise "action is needed!" unless action
159
+ url = "#{Configuration.endpoint}#{action}?#{create_query({ :interactiveid => interactive_id }.merge(params))}"
157
160
  Configuration.logger.debug "calling karotz api with url '#{url}'"
158
- response = HTTPI.get(url)
161
+ response = get(url)
159
162
  answer = Crack::XML.parse(response.body)
160
163
  Configuration.logger.debug "answer was '#{answer}'"
161
164
  answer
@@ -5,7 +5,8 @@ module Karotz
5
5
  class << self
6
6
 
7
7
  attr_accessor :install_id, :api_key, :secret
8
- attr_accessor :logger
8
+ attr_accessor :endpoint, :proxy
9
+ attr_accessor :logger, :digest
9
10
 
10
11
  def configure(options={})
11
12
  init_config
@@ -36,11 +37,14 @@ module Karotz
36
37
 
37
38
  def init_config(force=false)
38
39
  return if @init && !force
39
- @init = true
40
- @secret = ''
41
- @api_key = ''
42
- @install_id = ''
43
- @logger = Logger.new(STDERR)
40
+ @init = true
41
+ @secret = ''
42
+ @api_key = ''
43
+ @install_id = ''
44
+ @proxy = nil
45
+ @logger = Logger.new(STDERR)
46
+ @endpoint = "http://api.karotz.com/api/karotz/"
47
+ @digest = OpenSSL::Digest::Digest.new('sha1')
44
48
  end
45
49
  end
46
50
  end
@@ -23,6 +23,7 @@ namespace :karotz do
23
23
  config.install_id = ENV['KAROTZ_INSTALL_ID']
24
24
  config.api_key = ENV['KAROTZ_API_KEY']
25
25
  config.secret = ENV['KAROTZ_SECRET']
26
+ config.proxy = ENV['KAROTZ_PROXY']
26
27
  end
27
28
  end
28
29
  end
@@ -1,3 +1,3 @@
1
1
  module Karotz
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,26 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.karotz.com:80/api/karotz/start?apikey=7afdd4b7-3bc8-4469-bda2-1d8bc1e218a0&installid=37b67bee-b480-44e9-84fe-8c711b09fe78&once=1502266272712&signature=DYh/pt3G//CENw9A5nyp3lsjaMY=&timestamp=1326123132
6
+ body:
7
+ headers:
8
+ date:
9
+ - Mon, 09 Jan 2012 15:32:12 GMT
10
+ host:
11
+ - api.karotz.com
12
+ via:
13
+ - 1.1 ernst.local:9000
14
+ accept-encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ response: !ruby/struct:VCR::Response
17
+ status: !ruby/struct:VCR::ResponseStatus
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ content-length:
22
+ - '540'
23
+ connection:
24
+ - keep-alive
25
+ body: <VoosMsg><id>eb9cacc6-8ad4-4ea9-8f72-8be3d2995a37</id><recipient>2addc8ff97e59fe4616021094db393d5</recipient><interactiveMode><action>START</action><interactiveId>f72ad94a-6424-4f8e-9b19-e3aad56f0b65</interactiveId><configId>b800bdca-482c-455c-8b9c-581ac7f2b1ec</configId><access>asr</access><access>button</access><access>ears</access><access>file</access><access>http</access><access>led</access><access>multimedia</access><access>rfid</access><access>serial</access><access>tts</access><access>webcam</access></interactiveMode></VoosMsg>
26
+ http_version: '1.1'
@@ -0,0 +1,24 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.karotz.com:80/api/karotz/start?apikey=7afdd4b7-3bc8-4469-bda2-1d8bc1e218a0&installid=37b67bee-b480-44e9-84fe-8c711b09fe78&once=1502266272712&signature=DYh/pt3G//CENw9A5nyp3lsjaMY=&timestamp=1326123132
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
+ proxy-connection:
14
+ - close
15
+ content-length:
16
+ - '540'
17
+ via:
18
+ - 1.1 ernst.local:9000
19
+ server:
20
+ - WEBrick/1.3.1 (Ruby/1.9.3/2011-10-30)
21
+ date:
22
+ - Mon, 09 Jan 2012 15:32:25 GMT
23
+ body: <VoosMsg><id>eb9cacc6-8ad4-4ea9-8f72-8be3d2995a37</id><recipient>2addc8ff97e59fe4616021094db393d5</recipient><interactiveMode><action>START</action><interactiveId>f72ad94a-6424-4f8e-9b19-e3aad56f0b65</interactiveId><configId>b800bdca-482c-455c-8b9c-581ac7f2b1ec</configId><access>asr</access><access>button</access><access>ears</access><access>file</access><access>http</access><access>led</access><access>multimedia</access><access>rfid</access><access>serial</access><access>tts</access><access>webcam</access></interactiveMode></VoosMsg>
24
+ http_version: '1.1'
@@ -1,27 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  module Karotz
4
- describe Configuration do
5
- it "should be initialized with defaults" do
6
- Configuration.install_id.should be_empty
7
- Configuration.api_key.should be_empty
8
- Configuration.secret.should be_empty
9
- Configuration.logger.should_not be_nil
10
- end
11
-
12
- it "should configure with a hash" do
13
- Configuration.configure :api_key => 'some-key'
14
- Configuration.api_key.should eql('some-key')
15
- end
16
-
17
- it "should be initializable with a block" do
18
- Configuration.configure do |conf|
19
- conf.install_id = 'some-id'
20
- end
21
- Configuration.install_id.should eql('some-id')
22
- end
23
- end
24
-
25
4
  describe Client do
26
5
  it "should create a signed url" do
27
6
  args = ['INSTALL_ID', 'API_KEY', 'SECRET', '7112317', '1324833464']
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Karotz
4
+ describe Configuration do
5
+ it "should be initialized with defaults" do
6
+ Configuration.install_id.should be_empty
7
+ Configuration.api_key.should be_empty
8
+ Configuration.secret.should be_empty
9
+ Configuration.logger.should_not be_nil
10
+ end
11
+
12
+ it "should configure with a hash" do
13
+ Configuration.configure :api_key => 'some-key'
14
+ Configuration.api_key.should eql('some-key')
15
+ end
16
+
17
+ it "should be initializable with a block" do
18
+ Configuration.configure do |conf|
19
+ conf.install_id = 'some-id'
20
+ end
21
+ Configuration.install_id.should eql('some-id')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'webrick'
4
+ require 'webrick/httpproxy'
5
+ require 'thread' # for ::Mutex used in VCR middleware
6
+
7
+ module WEBrick
8
+ class VCRProxyServer < HTTPProxyServer
9
+ def initialize(*)
10
+ super
11
+ @mutex = Mutex.new
12
+ trap('INT') { shutdown }
13
+ end
14
+
15
+ def service(*args)
16
+ @mutex.synchronize do
17
+ VCR.use_cassette('proxied') do
18
+ super(*args) # XXX: for some reason super (with no args) does not work
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ unless RUBY_PLATFORM == 'java'
26
+ module Karotz
27
+ describe "proxy" do
28
+ before :all do
29
+ @pid = fork do
30
+ STDERR.reopen('/dev/null', 'a')
31
+ WEBrick::VCRProxyServer.new(:Port => 9000).start
32
+ end
33
+
34
+ begin
35
+ TCPSocket.open('localhost', 9000).close
36
+ rescue Errno::ECONNREFUSED
37
+ retry
38
+ end
39
+ end
40
+
41
+ before(:each) do
42
+ Configuration.configure do |config|
43
+ config.install_id = ENV['KAROTZ_INSTALL_ID']
44
+ config.api_key = ENV['KAROTZ_API_KEY']
45
+ config.secret = ENV['KAROTZ_SECRET']
46
+ config.proxy = 'http://localhost:9000'
47
+ end
48
+ end
49
+
50
+ it "should work with a proxy", :vcr => true do
51
+ Client.create.tap do |it|
52
+ it.interactive_id.should_not be_nil
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
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 = "aa36d0a0-fcbd-4095-955b-9a6d53c2e3fc"
29
+ @interactive_id = "f3065573-913f-417f-8171-4524f7863cff"
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.3.0
4
+ version: 0.4.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-30 00:00:00.000000000 Z
12
+ date: 2012-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2151815860 !ruby/object:Gem::Requirement
16
+ requirement: &2151815380 !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: *2151815860
24
+ version_requirements: *2151815380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2151814740 !ruby/object:Gem::Requirement
27
+ requirement: &2151814460 !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: *2151814740
35
+ version_requirements: *2151814460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2151814020 !ruby/object:Gem::Requirement
38
+ requirement: &2151813700 !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: *2151814020
46
+ version_requirements: *2151813700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &2151829460 !ruby/object:Gem::Requirement
49
+ requirement: &2151828300 !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: *2151829460
57
+ version_requirements: *2151828300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-rspec
60
- requirement: &2151827220 !ruby/object:Gem::Requirement
60
+ requirement: &2151826840 !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: *2151827220
68
+ version_requirements: *2151826840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
- requirement: &2151826380 !ruby/object:Gem::Requirement
71
+ requirement: &2151826000 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2151826380
79
+ version_requirements: *2151826000
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: vcr
82
- requirement: &2151825580 !ruby/object:Gem::Requirement
82
+ requirement: &2151825200 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2151825580
90
+ version_requirements: *2151825200
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: httpclient
93
- requirement: &2151824520 !ruby/object:Gem::Requirement
93
+ requirement: &2151824360 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '2.2'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2151824520
101
+ version_requirements: *2151824360
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: httpi
104
- requirement: &2151823960 !ruby/object:Gem::Requirement
104
+ requirement: &2151823800 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0.9'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2151823960
112
+ version_requirements: *2151823800
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: crack
115
- requirement: &2151823440 !ruby/object:Gem::Requirement
115
+ requirement: &2151822880 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0.3'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2151823440
123
+ version_requirements: *2151822880
124
124
  description: ruby bindings for karotz rest api
125
125
  email:
126
126
  - phoetmail@googlemail.com
@@ -166,7 +166,11 @@ files:
166
166
  - spec/cassettes/karotz/client_multimedia_should_play_mp3.yml
167
167
  - spec/cassettes/karotz/client_text_to_speach_tts_should_say_something.yml
168
168
  - spec/cassettes/karotz/client_webcam_should_take_a_picture_and_upload_it.yml
169
- - spec/karotz_spec.rb
169
+ - spec/cassettes/proxied.yml
170
+ - spec/cassettes/proxy/should_work_with_a_proxy.yml
171
+ - spec/client_spec.rb
172
+ - spec/configuration_spec.rb
173
+ - spec/proxy_spec.rb
170
174
  - spec/spec_helper.rb
171
175
  homepage: http://github.com/phoet/karotz
172
176
  licenses: []
@@ -210,5 +214,9 @@ test_files:
210
214
  - spec/cassettes/karotz/client_multimedia_should_play_mp3.yml
211
215
  - spec/cassettes/karotz/client_text_to_speach_tts_should_say_something.yml
212
216
  - spec/cassettes/karotz/client_webcam_should_take_a_picture_and_upload_it.yml
213
- - spec/karotz_spec.rb
217
+ - spec/cassettes/proxied.yml
218
+ - spec/cassettes/proxy/should_work_with_a_proxy.yml
219
+ - spec/client_spec.rb
220
+ - spec/configuration_spec.rb
221
+ - spec/proxy_spec.rb
214
222
  - spec/spec_helper.rb