karotz 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/karotz/client.rb +65 -15
- data/lib/karotz/version.rb +1 -1
- data/spec/cassettes/karotz/client_lifecycle_should_do_something_in_a_block.yml +52 -0
- data/spec/cassettes/karotz/client_lifecycle_should_start_and_stop_the_interactivemode.yml +35 -0
- data/spec/karotz_spec.rb +20 -4
- data/spec/spec_helper.rb +1 -3
- metadata +23 -19
data/lib/karotz/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'cgi'
|
2
2
|
require 'base64'
|
3
3
|
require 'httpi'
|
4
4
|
require 'httpclient'
|
@@ -7,21 +7,28 @@ require 'crack'
|
|
7
7
|
module Karotz
|
8
8
|
class Client
|
9
9
|
|
10
|
+
def initialize(interactive_id)
|
11
|
+
@interactive_id = interactive_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(meth, *args, &blk)
|
15
|
+
if self.class.respond_to? meth
|
16
|
+
args.unshift @interactive_id
|
17
|
+
self.class.send meth, *args, &blk
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def respond_to?(meth)
|
24
|
+
self.class.respond_to?(meth) || super
|
25
|
+
end
|
26
|
+
|
10
27
|
API = "http://api.karotz.com/api/karotz/"
|
11
28
|
DIGEST = OpenSSL::Digest::Digest.new('sha1')
|
12
29
|
|
13
|
-
|
14
|
-
|
15
|
-
'installid' => installid,
|
16
|
-
'apikey' => apikey,
|
17
|
-
'once' => once.to_s,
|
18
|
-
'timestamp' => timestamp.to_s,
|
19
|
-
}
|
20
|
-
query = create_query(params)
|
21
|
-
hmac = OpenSSL::HMAC.digest(DIGEST, secret, query)
|
22
|
-
signed = Base64.encode64(hmac).strip
|
23
|
-
"#{API}start?#{query}&signature=#{URI.encode(signed)}"
|
24
|
-
end
|
30
|
+
#==========EARS=================
|
31
|
+
|
25
32
|
|
26
33
|
def self.ears(interactive_id, params={:reset => true})
|
27
34
|
request :ears, interactive_id, params
|
@@ -43,10 +50,41 @@ module Karotz
|
|
43
50
|
|
44
51
|
#============LIFE_CYCLE=========
|
45
52
|
|
46
|
-
def self.
|
53
|
+
def self.start
|
54
|
+
url = start_url(Configuration.install_id, Configuration.api_key, Configuration.secret)
|
55
|
+
response = HTTPI.get(url)
|
56
|
+
answer = Crack::XML.parse(response.body)
|
57
|
+
raise "could not retrieve interactive_id" if answer["VoosMsg"].nil? || answer["VoosMsg"]["interactiveMode"].nil? || answer["VoosMsg"]["interactiveMode"]["interactiveId"].nil?
|
58
|
+
answer["VoosMsg"]["interactiveMode"]["interactiveId"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.stop(interactive_id, params={:action => :stop})
|
47
62
|
request :interactivemode, interactive_id, params
|
48
63
|
end
|
49
64
|
|
65
|
+
def self.session
|
66
|
+
interactive_id = start
|
67
|
+
yield(new(interactive_id))
|
68
|
+
ensure
|
69
|
+
stop(interactive_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
#===========HELPERS================
|
73
|
+
|
74
|
+
def self.start_url(install_id, api_key, secret, once=rand(99999999999999), timestamp=Time.now.to_i)
|
75
|
+
params = {
|
76
|
+
'installid' => install_id,
|
77
|
+
'apikey' => api_key,
|
78
|
+
'once' => once,
|
79
|
+
'timestamp' => timestamp,
|
80
|
+
}
|
81
|
+
query = create_query(params)
|
82
|
+
hmac = OpenSSL::HMAC.digest(DIGEST, secret, query)
|
83
|
+
encoded = Base64.encode64(hmac).chomp
|
84
|
+
signed = CGI.escape(encoded)
|
85
|
+
"#{API}start?#{query}&signature=#{signed}"
|
86
|
+
end
|
87
|
+
|
50
88
|
private()
|
51
89
|
|
52
90
|
def self.request(endpoint, interactive_id, params={})
|
@@ -59,8 +97,20 @@ module Karotz
|
|
59
97
|
end
|
60
98
|
|
61
99
|
def self.create_query(params)
|
62
|
-
params.map { |key, value| "#{key}=#{
|
100
|
+
params.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.sort.join('&')
|
63
101
|
end
|
64
102
|
|
65
103
|
end
|
66
104
|
end
|
105
|
+
|
106
|
+
if __FILE__ == $PROGRAM_NAME
|
107
|
+
require File.dirname(__FILE__) + "/configuration"
|
108
|
+
Karotz::Configuration.configure do |config|
|
109
|
+
config.install_id = ENV['KAROTZ_INSTALL_ID']
|
110
|
+
config.api_key = ENV['KAROTZ_API_KEY']
|
111
|
+
config.secret = ENV['KAROTZ_SECRET']
|
112
|
+
end
|
113
|
+
|
114
|
+
interactive_id = Karotz::Client.start
|
115
|
+
Karotz::Client.stop(interactive_id)
|
116
|
+
end
|
data/lib/karotz/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
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=68e0a42b-aca3-49aa-9dc2-85a8f141e8c5&once=45144111633037&signature=mYHKgqfC0X8t2mdHOudC9gO0hIU=×tamp=1324932376
|
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
|
+
- '388'
|
15
|
+
connection:
|
16
|
+
- keep-alive
|
17
|
+
body: <VoosMsg><id>35387ec7-8d4d-4f3e-80fe-21de698ed2dc</id><recipient>2addc8ff97e59fe4616021094db393d5</recipient><interactiveMode><action>START</action><interactiveId>0854e9e3-699f-4fa0-8c12-dee177dd50f7</interactiveId><configId>941894ed-d048-42f6-ab68-fbe95abaa157</configId><access>ears</access><access>led</access><access>multimedia</access><access>tts</access></interactiveMode></VoosMsg>
|
18
|
+
http_version: '1.1'
|
19
|
+
- !ruby/struct:VCR::HTTPInteraction
|
20
|
+
request: !ruby/struct:VCR::Request
|
21
|
+
method: :get
|
22
|
+
uri: http://api.karotz.com:80/api/karotz/ears?interactiveid=0854e9e3-699f-4fa0-8c12-dee177dd50f7&reset=true
|
23
|
+
body:
|
24
|
+
headers:
|
25
|
+
response: !ruby/struct:VCR::Response
|
26
|
+
status: !ruby/struct:VCR::ResponseStatus
|
27
|
+
code: 200
|
28
|
+
message: OK
|
29
|
+
headers:
|
30
|
+
content-length:
|
31
|
+
- '255'
|
32
|
+
connection:
|
33
|
+
- keep-alive
|
34
|
+
body: <VoosMsg><id>f9e9fbf4-55d5-424f-8a3b-4f11e5657bc3</id><correlationId>df6ab8da-b497-472c-b3b6-9a88a7351e1f</correlationId><interactiveId>0854e9e3-699f-4fa0-8c12-dee177dd50f7</interactiveId><callback></callback><response><code>OK</code></response></VoosMsg>
|
35
|
+
http_version: '1.1'
|
36
|
+
- !ruby/struct:VCR::HTTPInteraction
|
37
|
+
request: !ruby/struct:VCR::Request
|
38
|
+
method: :get
|
39
|
+
uri: http://api.karotz.com:80/api/karotz/interactivemode?action=stop&interactiveid=0854e9e3-699f-4fa0-8c12-dee177dd50f7
|
40
|
+
body:
|
41
|
+
headers:
|
42
|
+
response: !ruby/struct:VCR::Response
|
43
|
+
status: !ruby/struct:VCR::ResponseStatus
|
44
|
+
code: 200
|
45
|
+
message: OK
|
46
|
+
headers:
|
47
|
+
content-length:
|
48
|
+
- '255'
|
49
|
+
connection:
|
50
|
+
- keep-alive
|
51
|
+
body: <VoosMsg><id>9f54ba1c-f294-495f-aa17-de8d0eb9f919</id><correlationId>25a4a976-5578-4141-9f51-46acab6663ae</correlationId><interactiveId>0854e9e3-699f-4fa0-8c12-dee177dd50f7</interactiveId><callback></callback><response><code>OK</code></response></VoosMsg>
|
52
|
+
http_version: '1.1'
|
@@ -0,0 +1,35 @@
|
|
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=68e0a42b-aca3-49aa-9dc2-85a8f141e8c5&once=968427128138&signature=JoB4OPxlO68gimsw/P4Flrx9eDQ=×tamp=1324909989
|
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
|
+
- '388'
|
15
|
+
connection:
|
16
|
+
- keep-alive
|
17
|
+
body: <VoosMsg><id>620cdae1-0cfc-49ea-aae3-c516c0c434e5</id><recipient>2addc8ff97e59fe4616021094db393d5</recipient><interactiveMode><action>START</action><interactiveId>cfe16aac-425c-4efb-a1a1-caa857ff4a9e</interactiveId><configId>941894ed-d048-42f6-ab68-fbe95abaa157</configId><access>ears</access><access>led</access><access>multimedia</access><access>tts</access></interactiveMode></VoosMsg>
|
18
|
+
http_version: '1.1'
|
19
|
+
- !ruby/struct:VCR::HTTPInteraction
|
20
|
+
request: !ruby/struct:VCR::Request
|
21
|
+
method: :get
|
22
|
+
uri: http://api.karotz.com:80/api/karotz/interactivemode?action=stop&interactiveid=cfe16aac-425c-4efb-a1a1-caa857ff4a9e
|
23
|
+
body:
|
24
|
+
headers:
|
25
|
+
response: !ruby/struct:VCR::Response
|
26
|
+
status: !ruby/struct:VCR::ResponseStatus
|
27
|
+
code: 200
|
28
|
+
message: OK
|
29
|
+
headers:
|
30
|
+
content-length:
|
31
|
+
- '255'
|
32
|
+
connection:
|
33
|
+
- keep-alive
|
34
|
+
body: <VoosMsg><id>5d8e274c-d8de-4f37-9d1c-95f37ea1c7b9</id><correlationId>b612e547-a09c-4001-965e-fe5d12e8cb86</correlationId><interactiveId>cfe16aac-425c-4efb-a1a1-caa857ff4a9e</interactiveId><callback></callback><response><code>OK</code></response></VoosMsg>
|
35
|
+
http_version: '1.1'
|
data/spec/karotz_spec.rb
CHANGED
@@ -25,7 +25,7 @@ module Karotz
|
|
25
25
|
describe Client do
|
26
26
|
it "should create a signed url" do
|
27
27
|
args = ['INSTALL_ID', 'API_KEY', 'SECRET', '7112317', '1324833464']
|
28
|
-
url = "http://api.karotz.com/api/karotz/start?apikey=API_KEY&installid=INSTALL_ID&once=7112317×tamp=1324833464&signature=Vb
|
28
|
+
url = "http://api.karotz.com/api/karotz/start?apikey=API_KEY&installid=INSTALL_ID&once=7112317×tamp=1324833464&signature=Vb%2ByZK3eNlXGh%2B9DfnwIqQ%2BZIAE%3D"
|
29
29
|
Client.start_url(*args).should eql(url)
|
30
30
|
end
|
31
31
|
|
@@ -75,9 +75,25 @@ module Karotz
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
context "
|
79
|
-
|
80
|
-
|
78
|
+
context "lifecycle" do
|
79
|
+
before(:each) do
|
80
|
+
Configuration.configure do |config|
|
81
|
+
config.install_id = ENV['KAROTZ_INSTALL_ID']
|
82
|
+
config.api_key = ENV['KAROTZ_API_KEY']
|
83
|
+
config.secret = ENV['KAROTZ_SECRET']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should start and stop the interactiveMode", :vcr => true do
|
88
|
+
interactive_id = Client.start
|
89
|
+
interactive_id.should_not be_empty
|
90
|
+
Client.stop(interactive_id)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should do something in a block", :vcr => true do
|
94
|
+
Client.session do |karotz|
|
95
|
+
karotz.ears
|
96
|
+
end
|
81
97
|
end
|
82
98
|
end
|
83
99
|
|
data/spec/spec_helper.rb
CHANGED
@@ -27,9 +27,7 @@ RSpec.configure do |config|
|
|
27
27
|
@install_id = ENV['KAROTZ_INSTALL_ID']
|
28
28
|
@api_key = ENV['KAROTZ_API_KEY']
|
29
29
|
@secret = ENV['KAROTZ_SECRET']
|
30
|
-
#
|
31
|
-
# http://www.karotz.com/authentication/run/karotz/API_KEY
|
32
|
-
# cause login-process does throws 502 BAD_GATEWAY
|
30
|
+
# retrieved via http://www.karotz.com/authentication/run/karotz/API_KEY
|
33
31
|
@interactive_id = "117c09d2-02b9-4b38-b64b-9b821ac7c91c"
|
34
32
|
|
35
33
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156300600 !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: *
|
24
|
+
version_requirements: *2156300600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156300180 !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: *
|
35
|
+
version_requirements: *2156300180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: pry
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156299760 !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: *
|
46
|
+
version_requirements: *2156299760
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: guard-rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156299340 !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: *
|
57
|
+
version_requirements: *2156299340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: webmock
|
60
|
-
requirement: &
|
60
|
+
requirement: &2156298920 !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: *
|
68
|
+
version_requirements: *2156298920
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: vcr
|
71
|
-
requirement: &
|
71
|
+
requirement: &2156298500 !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: *
|
79
|
+
version_requirements: *2156298500
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: httpclient
|
82
|
-
requirement: &
|
82
|
+
requirement: &2156314460 !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: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2156314460
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: httpi
|
93
|
-
requirement: &
|
93
|
+
requirement: &2156314040 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2156314040
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: crack
|
104
|
-
requirement: &
|
104
|
+
requirement: &2156313620 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2156313620
|
113
113
|
description: ruby bindings for karotz rest api
|
114
114
|
email:
|
115
115
|
- phoetmail@googlemail.com
|
@@ -140,6 +140,8 @@ files:
|
|
140
140
|
- spec/cassettes/karotz/client_led_should_fade.yml
|
141
141
|
- spec/cassettes/karotz/client_led_should_light.yml
|
142
142
|
- spec/cassettes/karotz/client_led_should_pulse.yml
|
143
|
+
- spec/cassettes/karotz/client_lifecycle_should_do_something_in_a_block.yml
|
144
|
+
- spec/cassettes/karotz/client_lifecycle_should_start_and_stop_the_interactivemode.yml
|
143
145
|
- spec/karotz_spec.rb
|
144
146
|
- spec/spec_helper.rb
|
145
147
|
homepage: http://github.com/phoet/karotz
|
@@ -175,5 +177,7 @@ test_files:
|
|
175
177
|
- spec/cassettes/karotz/client_led_should_fade.yml
|
176
178
|
- spec/cassettes/karotz/client_led_should_light.yml
|
177
179
|
- spec/cassettes/karotz/client_led_should_pulse.yml
|
180
|
+
- spec/cassettes/karotz/client_lifecycle_should_do_something_in_a_block.yml
|
181
|
+
- spec/cassettes/karotz/client_lifecycle_should_start_and_stop_the_interactivemode.yml
|
178
182
|
- spec/karotz_spec.rb
|
179
183
|
- spec/spec_helper.rb
|