connfu-client 0.1
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/.rspec +3 -0
- data/.rvmrc +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +120 -0
- data/LICENSE.txt +661 -0
- data/README.rdoc +398 -0
- data/Rakefile +38 -0
- data/bin/.DS_Store +0 -0
- data/bin/connfu-client +94 -0
- data/connfu-client.gemspec +41 -0
- data/examples/conference/application.rb +68 -0
- data/examples/conference/conference.rb +33 -0
- data/examples/conference/conference_app.rb +25 -0
- data/examples/conference/connfu.log +5 -0
- data/examples/conference/wall.rb +11 -0
- data/examples/provisioning/app/get.rb +29 -0
- data/examples/provisioning/channels/get.rb +34 -0
- data/examples/provisioning/rss/create.rb +28 -0
- data/examples/provisioning/rss/delete.rb +27 -0
- data/examples/provisioning/rss/get.rb +32 -0
- data/examples/provisioning/rss/put.rb +29 -0
- data/examples/provisioning/setup.rb +2 -0
- data/examples/provisioning/twitter/create.rb +31 -0
- data/examples/provisioning/twitter/delete.rb +27 -0
- data/examples/provisioning/twitter/get.rb +32 -0
- data/examples/provisioning/twitter/put.rb +29 -0
- data/examples/provisioning/voice/create.rb +26 -0
- data/examples/provisioning/voice/delete.rb +27 -0
- data/examples/provisioning/voice/get.rb +36 -0
- data/examples/provisioning/voice/phones/create.rb +26 -0
- data/examples/provisioning/voice/phones/delete.rb +28 -0
- data/examples/provisioning/voice/phones/get.rb +38 -0
- data/examples/provisioning/voice/put.rb +38 -0
- data/examples/provisioning/voice/whitelist/create.rb +26 -0
- data/examples/provisioning/voice/whitelist/delete.rb +27 -0
- data/examples/provisioning/voice/whitelist/get.rb +36 -0
- data/examples/provisioning/voice/whitelist/put.rb +27 -0
- data/lib/connfu.rb +134 -0
- data/lib/connfu/cli/generator.rb +71 -0
- data/lib/connfu/connfu_logger.rb +88 -0
- data/lib/connfu/connfu_message_formatter.rb +134 -0
- data/lib/connfu/connfu_stream.rb +182 -0
- data/lib/connfu/dispatcher.rb +164 -0
- data/lib/connfu/dsl.rb +84 -0
- data/lib/connfu/events.rb +32 -0
- data/lib/connfu/listener.rb +85 -0
- data/lib/connfu/listener_channel.rb +100 -0
- data/lib/connfu/message.rb +74 -0
- data/lib/connfu/provisioning.rb +12 -0
- data/lib/connfu/provisioning/application.rb +374 -0
- data/lib/connfu/provisioning/base.rb +95 -0
- data/lib/connfu/provisioning/channel.rb +79 -0
- data/lib/connfu/provisioning/phone.rb +55 -0
- data/lib/connfu/provisioning/rss.rb +21 -0
- data/lib/connfu/provisioning/twitter.rb +28 -0
- data/lib/connfu/provisioning/voice.rb +89 -0
- data/lib/connfu/provisioning/whitelist.rb +62 -0
- data/lib/connfu/version.rb +6 -0
- data/lib/rdoc/generator/template/connfu/_context.rhtml +209 -0
- data/lib/rdoc/generator/template/connfu/_head.rhtml +7 -0
- data/lib/rdoc/generator/template/connfu/class.rhtml +38 -0
- data/lib/rdoc/generator/template/connfu/file.rhtml +36 -0
- data/lib/rdoc/generator/template/connfu/index.rhtml +13 -0
- data/lib/rdoc/generator/template/connfu/resources/apple-touch-icon.png +0 -0
- data/lib/rdoc/generator/template/connfu/resources/css/github.css +129 -0
- data/lib/rdoc/generator/template/connfu/resources/css/main.css +339 -0
- data/lib/rdoc/generator/template/connfu/resources/css/panel.css +389 -0
- data/lib/rdoc/generator/template/connfu/resources/css/reset.css +53 -0
- data/lib/rdoc/generator/template/connfu/resources/favicon.ico +0 -0
- data/lib/rdoc/generator/template/connfu/resources/i/arrows.png +0 -0
- data/lib/rdoc/generator/template/connfu/resources/i/results_bg.png +0 -0
- data/lib/rdoc/generator/template/connfu/resources/i/tree_bg.png +0 -0
- data/lib/rdoc/generator/template/connfu/resources/js/highlight.pack.js +1 -0
- data/lib/rdoc/generator/template/connfu/resources/js/jquery-1.3.2.min.js +19 -0
- data/lib/rdoc/generator/template/connfu/resources/js/jquery-effect.js +593 -0
- data/lib/rdoc/generator/template/connfu/resources/js/main.js +20 -0
- data/lib/rdoc/generator/template/connfu/resources/js/searchdoc.js +628 -0
- data/lib/rdoc/generator/template/connfu/resources/panel/index.html +72 -0
- data/lib/rdoc/generator/template/connfu/se_index.rhtml +8 -0
- data/spec/connfu_message_formatter_spec.rb +88 -0
- data/spec/connfu_spec.rb +51 -0
- data/spec/connfu_stream_spec.rb +84 -0
- data/spec/dispatcher_spec.rb +227 -0
- data/spec/dsl_spec.rb +159 -0
- data/spec/listener_channel_spec.rb +130 -0
- data/spec/listener_spec.rb +67 -0
- data/spec/provisioning/application_spec.rb +47 -0
- data/spec/provisioning/channel_shared_examples.rb +52 -0
- data/spec/provisioning/channel_spec.rb +13 -0
- data/spec/provisioning/phone_spec.rb +88 -0
- data/spec/provisioning/voice_spec.rb +138 -0
- data/spec/provisioning_spec.rb +500 -0
- data/spec/spec_helper.rb +51 -0
- metadata +298 -0
data/spec/dsl_spec.rb
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#
|
|
2
|
+
# connFu is a platform of Telefonica delivered by Bluevia Labs
|
|
3
|
+
# Please, check out www.connfu.com and if you need more information
|
|
4
|
+
# contact us at mailto:support@connfu.com
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'examples')
|
|
8
|
+
|
|
9
|
+
require 'spec_helper'
|
|
10
|
+
|
|
11
|
+
# Conference application
|
|
12
|
+
require 'conference/conference_app'
|
|
13
|
+
|
|
14
|
+
describe Connfu::DSL do
|
|
15
|
+
|
|
16
|
+
let(:prov_client) {
|
|
17
|
+
application = Connfu::Provisioning::Application.new(API_KEY, ENDPOINT)
|
|
18
|
+
application.stub(:name) {APP_NAME}
|
|
19
|
+
application.stub(:description) {APP_DESCRIPTION}
|
|
20
|
+
application.stub(:stream_name) {APP_STREAM_NAME}
|
|
21
|
+
|
|
22
|
+
obj = double 'prov_client'
|
|
23
|
+
obj.stub(:get_info) { application }
|
|
24
|
+
obj.stub(:get_channels) {[]}
|
|
25
|
+
obj
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
before(:each) do
|
|
29
|
+
|
|
30
|
+
Connfu.stub(:prov_client).and_return(prov_client)
|
|
31
|
+
Connfu.should_receive(:prov_client).twice
|
|
32
|
+
|
|
33
|
+
Connfu::Listener.any_instance.stub(:start) { true }
|
|
34
|
+
Connfu::Listener.any_instance.stub(:join) { true }
|
|
35
|
+
Connfu::Dispatcher.any_instance.stub(:join) { true }
|
|
36
|
+
Connfu::ConnfuStream.any_instance.stub(:start_listening) { nil }
|
|
37
|
+
Connfu::Provisioning::Application.any_instance.stub(:get_channels).and_return {[]}
|
|
38
|
+
|
|
39
|
+
@connfu = Connfu.application(API_KEY) {
|
|
40
|
+
|
|
41
|
+
listen(:voice) do |channel|
|
|
42
|
+
channel.on(:new) do |call|
|
|
43
|
+
puts "#{NEW_CALL_MESSAGE} on number #{call[:destination]}"
|
|
44
|
+
conf = ConferenceApp::find_by_conference_number(call[:destination])
|
|
45
|
+
if conf.is_allowed?(call[:origin])
|
|
46
|
+
puts "whitelist number received"
|
|
47
|
+
else
|
|
48
|
+
puts "not whitelist number"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
channel.on(:leave) do |call|
|
|
53
|
+
puts "#{call[:origin]} #{HANG_MESSAGE} #{call[:destination]}"
|
|
54
|
+
ConferenceApp::find(call[:destination]).end(call[:origin])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
channel.on(:foo) do
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
listen(:twitter) do |channel|
|
|
62
|
+
|
|
63
|
+
channel.filter = "text has #conference"
|
|
64
|
+
|
|
65
|
+
channel.on(:new) do |tweet|
|
|
66
|
+
puts "A new tweet arrived"
|
|
67
|
+
conf = ConferenceApp::find_by_twitter_user(tweet[:origin])
|
|
68
|
+
conf.wall.print("#{tweet[:origin]}: has tweeted #{tweet[:destination]}")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
listen(:foo) do |channel|
|
|
74
|
+
channel.on(:new) do |message|
|
|
75
|
+
puts "This is an unsupported channel"
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "channels" do
|
|
84
|
+
|
|
85
|
+
it "should have two channels defined" do
|
|
86
|
+
@connfu.listener_channels.length.should eql(2)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "should have the channels :voice and :twitter" do
|
|
90
|
+
[:voice, :twitter].each { |channel|
|
|
91
|
+
@connfu.listener_channels.keys.should include(channel)
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "channel voice blocks length should be 4 (one per event :new, :join, :leave, :new_topic)" do
|
|
96
|
+
@connfu.listener_channels[:voice].blocks.length.should eql(4)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "channel voice should have one block defined in :new event" do
|
|
100
|
+
@connfu.listener_channels[:voice].blocks[:new].length.should eql(1)
|
|
101
|
+
@connfu.listener_channels[:voice].blocks[:leave].length.should eql(1)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "channel voice should have one block defined in :hang event" do
|
|
105
|
+
@connfu.listener_channels[:voice].blocks[:leave].length.should eql(1)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "channel twitter should have one block defined in :new event" do
|
|
109
|
+
@connfu.listener_channels[:twitter].blocks[:new].length.should eql(1)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context "filters" do
|
|
115
|
+
it "should defined propertly the channel filter" do
|
|
116
|
+
@connfu.listener_channels[:twitter].filter.should eql("text has #conference")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "messages" do
|
|
122
|
+
|
|
123
|
+
context "voice" do
|
|
124
|
+
|
|
125
|
+
it "should execute the defined block when a :new event is raised" do
|
|
126
|
+
@connfu.listener_channels[:voice].should_receive(:puts).with("#{NEW_CALL_MESSAGE} on number 222").once
|
|
127
|
+
@connfu.listener_channels[:voice].should_receive(:puts).with("whitelist number received").once
|
|
128
|
+
|
|
129
|
+
# throw event
|
|
130
|
+
@connfu.listener_channels[:voice].message(:new, {:origin => "111", :destination => "222"})
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "should execute the defined block when a :hang event is raised" do
|
|
134
|
+
@connfu.listener_channels[:voice].should_receive(:puts).with("111 #{HANG_MESSAGE} 222").once
|
|
135
|
+
@connfu.listener_channels[:voice].message(:leave, {:origin => "111", :destination => "222"})
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
context "twitter" do
|
|
140
|
+
it "should execute the defined block when a :new event is raised" do
|
|
141
|
+
# mock wall
|
|
142
|
+
wall = Wall.new
|
|
143
|
+
wall.should_receive(:puts).with("juandebravo: has tweeted My new tweet").once
|
|
144
|
+
conference = Conference.new("twitter")
|
|
145
|
+
conference.should_receive(:wall).and_return(wall)
|
|
146
|
+
|
|
147
|
+
# mock conference
|
|
148
|
+
ConferenceApp.should_receive(:find_by_twitter_user).with("juandebravo").and_return(conference)
|
|
149
|
+
|
|
150
|
+
@connfu.listener_channels[:twitter].should_receive(:puts).with("A new tweet arrived").once
|
|
151
|
+
|
|
152
|
+
# throw event
|
|
153
|
+
@connfu.listener_channels[:twitter].message(:new, {:origin => "juandebravo", :destination => "My new tweet"})
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#
|
|
2
|
+
# connFu is a platform of Telefonica delivered by Bluevia Labs
|
|
3
|
+
# Please, check out www.connfu.com and if you need more information
|
|
4
|
+
# contact us at mailto:support@connfu.com
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
require 'spec_helper'
|
|
8
|
+
require 'connfu'
|
|
9
|
+
|
|
10
|
+
describe Connfu::ListenerChannel do
|
|
11
|
+
|
|
12
|
+
let(:prov_client) {
|
|
13
|
+
application = Connfu::Provisioning::Application.new(API_KEY, ENDPOINT)
|
|
14
|
+
application.stub(:name) {APP_NAME}
|
|
15
|
+
application.stub(:description) {APP_DESCRIPTION}
|
|
16
|
+
application.stub(:stream_name) {APP_STREAM_NAME}
|
|
17
|
+
|
|
18
|
+
obj = double 'prov_client'
|
|
19
|
+
obj.stub(:get_info) { application }
|
|
20
|
+
obj.stub(:get_channels) {[]}
|
|
21
|
+
obj
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
context "channel types" do
|
|
25
|
+
it "defines four supported channel types" do
|
|
26
|
+
Connfu::ListenerChannel::CHANNEL_TYPES.length.should eql(4)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "listener channels" do
|
|
31
|
+
before(:each) do
|
|
32
|
+
Connfu.stub(:prov_client).and_return(prov_client)
|
|
33
|
+
Connfu.should_receive(:prov_client).twice
|
|
34
|
+
|
|
35
|
+
Connfu::Listener.any_instance.stub(:start) { true }
|
|
36
|
+
Connfu::Listener.any_instance.stub(:join) { true }
|
|
37
|
+
Connfu::Dispatcher.any_instance.stub(:join) { true }
|
|
38
|
+
Connfu::Provisioning::Application.any_instance.stub(:get_channels).and_return { [] }
|
|
39
|
+
Connfu::ConnfuStream.any_instance.stub(:start_listening) { nil }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
it "unsupported channel is unconsidered" do
|
|
44
|
+
|
|
45
|
+
connfu = Connfu.application(API_KEY) {
|
|
46
|
+
listen(:foo) do
|
|
47
|
+
on(:new) do |call|
|
|
48
|
+
puts "foo bar"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
listen(:twitter) do
|
|
52
|
+
on(:new) do |call|
|
|
53
|
+
puts "foo bar"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
connfu.listener_channels.length.should eql(1)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "supports RSS channel" do
|
|
62
|
+
connfu = Connfu.application(API_KEY) {
|
|
63
|
+
listen(:rss) do
|
|
64
|
+
on(:new) do |rss|
|
|
65
|
+
puts "foo bar"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
}
|
|
69
|
+
connfu.listener_channels.length.should eql(1)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "supports sms channel" do
|
|
73
|
+
connfu = Connfu.application(API_KEY) {
|
|
74
|
+
listen(:sms) do
|
|
75
|
+
on(:new) do |sms|
|
|
76
|
+
puts "foo bar"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
}
|
|
80
|
+
connfu.listener_channels.length.should eql(1)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "supports twitter channel" do
|
|
84
|
+
connfu = Connfu.application(API_KEY) {
|
|
85
|
+
listen(:twitter) do
|
|
86
|
+
on(:new) do |tweet|
|
|
87
|
+
puts "foo bar"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
}
|
|
91
|
+
connfu.listener_channels.length.should eql(1)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "supports voice channel" do
|
|
95
|
+
connfu = Connfu.application(API_KEY) {
|
|
96
|
+
listen(:voice) do
|
|
97
|
+
on(:new) do |call|
|
|
98
|
+
puts "foo bar"
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
}
|
|
102
|
+
connfu.listener_channels.length.should eql(1)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
it "supports more than one channel" do
|
|
107
|
+
connfu = Connfu.application(API_KEY) {
|
|
108
|
+
listen(:voice) do
|
|
109
|
+
on(:new) do |call|
|
|
110
|
+
puts "foo bar"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
listen(:rss) do
|
|
115
|
+
on(:new) do |rss|
|
|
116
|
+
puts "foo bar"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
}
|
|
120
|
+
connfu.listener_channels.length.should eql(2)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "raise an exception if no channel defined" do
|
|
124
|
+
lambda { @connfu = Connfu.application(API_KEY) {
|
|
125
|
+
} }.should raise_error(Exception)
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#
|
|
2
|
+
# connFu is a platform of Telefonica delivered by Bluevia Labs
|
|
3
|
+
# Please, check out www.connfu.com and if you need more information
|
|
4
|
+
# contact us at mailto:support@connfu.com
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
require 'spec_helper'
|
|
9
|
+
|
|
10
|
+
describe Connfu::Listener do
|
|
11
|
+
|
|
12
|
+
let(:prov_client) {
|
|
13
|
+
application = Connfu::Provisioning::Application.new(API_KEY, ENDPOINT)
|
|
14
|
+
application.stub(:name) {APP_NAME}
|
|
15
|
+
application.stub(:description) {APP_DESCRIPTION}
|
|
16
|
+
application.stub(:stream_name) {APP_STREAM_NAME}
|
|
17
|
+
|
|
18
|
+
obj = double 'prov_client'
|
|
19
|
+
obj.stub(:get_info) { application }
|
|
20
|
+
obj.stub(:get_channels) {[]}
|
|
21
|
+
obj
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
before(:each) do
|
|
25
|
+
Connfu.stub(:prov_client).and_return(prov_client)
|
|
26
|
+
Connfu.should_receive(:prov_client).twice
|
|
27
|
+
|
|
28
|
+
Connfu::Dispatcher.any_instance.stub(:max_messages).and_return(10)
|
|
29
|
+
Connfu::Listener.any_instance.stub(:max_messages).and_return(10)
|
|
30
|
+
|
|
31
|
+
Connfu::ConnfuStream.any_instance.stub(:start_listening) { nil }
|
|
32
|
+
|
|
33
|
+
@id = 0
|
|
34
|
+
|
|
35
|
+
Connfu::Provisioning::Application.any_instance.stub(:get_channels).and_return {[]}
|
|
36
|
+
|
|
37
|
+
Connfu::ConnfuStream.any_instance.stub(:get) {
|
|
38
|
+
@id+=1
|
|
39
|
+
message = "{\"id\":\"#{@id}\",\"remoteId\":\"87872349432582144\",\"summary\":\"\",\"content\":\":foo => \\\"bar\\\"\",\"sender\":\"twitter://connfudev/\",\"recipients\":[],\"tags\":[],\"links\":[],\"attachments\":[],\"timeStamp\":\"2011-07-04T13:16:15.000Z\",\"isDeleted\":false,\"isPublic\":true,\"isArticle\":false}"
|
|
40
|
+
Connfu::ConnfuMessageFormatter.send(:format_message, message) # private method
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@connfu = Connfu.application(API_KEY) {
|
|
44
|
+
listen(:twitter) do |channel|
|
|
45
|
+
channel.filter = "text has #conference"
|
|
46
|
+
|
|
47
|
+
channel.on(:new) do |tweet|
|
|
48
|
+
# puts "A new tweet arrived"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context "twitter stream" do
|
|
57
|
+
describe "listener" do
|
|
58
|
+
it "should be an instance of Connfu::Listener when initialized" do
|
|
59
|
+
@connfu.listener.should be_an_instance_of(Connfu::Listener)
|
|
60
|
+
end
|
|
61
|
+
it "should receive ten messages" do
|
|
62
|
+
@connfu.listener.counter.should eql(10)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#
|
|
2
|
+
# connFu is a platform of Telefonica delivered by Bluevia Labs
|
|
3
|
+
# Please, check out www.connfu.com and if you need more information
|
|
4
|
+
# contact us at mailto:support@connfu.com
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
require 'connfu'
|
|
8
|
+
|
|
9
|
+
require 'spec_helper'
|
|
10
|
+
|
|
11
|
+
describe Connfu::Provisioning::Application do
|
|
12
|
+
|
|
13
|
+
before(:each) do
|
|
14
|
+
@application = Connfu::Provisioning::Application.new(API_KEY, ENDPOINT)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Matcher that helps to test if an Application instance is well defined after retrieving data using prov API
|
|
18
|
+
RSpec::Matchers.define :be_well_defined_as_app do |name, description, stream_name|
|
|
19
|
+
match do |app| # app should be the Connfu::Provisioning::Application instance
|
|
20
|
+
app.should be_instance_of(Connfu::Provisioning::Application)
|
|
21
|
+
app.name.should eql(APP_NAME)
|
|
22
|
+
app.description.should eql(APP_DESCRIPTION)
|
|
23
|
+
app.stream_name.should eql(APP_STREAM_NAME)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "Application" do
|
|
28
|
+
context "get_info" do
|
|
29
|
+
it "should retrieve name, description and stream_name" do
|
|
30
|
+
@application.base.should_receive(:get).once.and_return("{'description':'#{APP_DESCRIPTION}', 'name':'#{APP_NAME}', 'stream_name':'#{APP_STREAM_NAME}'}")
|
|
31
|
+
app = @application.get_info
|
|
32
|
+
app.should be_well_defined_as_app(APP_NAME, APP_DESCRIPTION, APP_STREAM_NAME)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "instance attributes" do
|
|
37
|
+
# Constructing RSpec examples programmatically
|
|
38
|
+
{"name" => APP_NAME, "description" => APP_DESCRIPTION, "stream_name" => APP_STREAM_NAME}.each do |attribute, value|
|
|
39
|
+
it "should make a HTTP request to retrieve app #{attribute}" do
|
|
40
|
+
@application.base.should_receive(:get).once.and_return("{'description':'#{APP_DESCRIPTION}', 'name':'#{APP_NAME}', 'stream_name':'#{APP_STREAM_NAME}'}")
|
|
41
|
+
@application.send(attribute.to_sym).should eql(value)
|
|
42
|
+
@application.should be_well_defined_as_app(APP_NAME, APP_DESCRIPTION, APP_STREAM_NAME)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
def current_time
|
|
5
|
+
@current_time ||= Time.now
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def channel_attrs
|
|
9
|
+
@channel_attrs ||= {:created_at => "2011-08-26 11:55:10 +0300",
|
|
10
|
+
:updated_at => "2011-08-26 11:55:10 +0300"
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
shared_examples_for "Channel" do |channel, type|
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
RSpec::Matchers.define :have_defined_channel_attributes do |expected|
|
|
19
|
+
match do |channel|
|
|
20
|
+
channel_attrs.keys.each { |attribute|
|
|
21
|
+
channel.send(attribute).should eql(expected[attribute])
|
|
22
|
+
}
|
|
23
|
+
channel.type.should be_instance_of(String)
|
|
24
|
+
channel.uid.should be_instance_of(String)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
describe "while creating a Channel instance" do
|
|
30
|
+
it "should initialize properly the meaning attributes" do
|
|
31
|
+
channel.should be_kind_of(Connfu::Provisioning::Channel)
|
|
32
|
+
channel.should have_defined_channel_attributes channel_attrs
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "to_hash method" do
|
|
38
|
+
RSpec::Matchers.define :have_channel_details do |uid|
|
|
39
|
+
match do |actual|
|
|
40
|
+
actual.should be_instance_of(Hash)
|
|
41
|
+
actual.should have_key("uid")
|
|
42
|
+
actual["uid"].should be_instance_of(String)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should retrieve uid" do
|
|
47
|
+
#channel = Connfu::Provisioning::Channel.new(channel_attrs)
|
|
48
|
+
channel.to_hash.should have_channel_details(CHANNEL_KEY)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|