connfu-client 0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,72 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
6
|
+
<head>
|
7
|
+
<title>search index</title>
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" charset="utf-8" />
|
9
|
+
<link rel="stylesheet" href="../css/panel.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
<script src="search_index.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="tree.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../js/searchdoc.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script type="text/javascript" charset="utf-8">
|
15
|
+
function placeholder() {
|
16
|
+
if ($('<input type="text">')[0].placeholder !== undefined) return;
|
17
|
+
|
18
|
+
$('#search-label').click(function() {
|
19
|
+
$('#search').focus();
|
20
|
+
$('#search-label').hide();
|
21
|
+
});
|
22
|
+
|
23
|
+
$('#search').focus(function() {
|
24
|
+
$('#search-label').hide();
|
25
|
+
});
|
26
|
+
$('#search').blur(function() {
|
27
|
+
this.value == '' && $('#search-label').show()
|
28
|
+
});
|
29
|
+
|
30
|
+
$('#search')[0].value == '' && $('#search-label').show();
|
31
|
+
}
|
32
|
+
$(function() {
|
33
|
+
placeholder();
|
34
|
+
$('#links').hide();
|
35
|
+
var panel = new Searchdoc.Panel($('#panel'), search_data, tree, top.frames[1]);
|
36
|
+
$('#search').focus();
|
37
|
+
|
38
|
+
var s = window.parent.location.search.match(/\?q=([^&]+)/);
|
39
|
+
if (s) {
|
40
|
+
s = decodeURIComponent(s[1]).replace(/\+/g, ' ');
|
41
|
+
if (s.length > 0)
|
42
|
+
{
|
43
|
+
$('#search').val(s);
|
44
|
+
panel.search(s, true);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
})
|
48
|
+
</script>
|
49
|
+
</head>
|
50
|
+
<body>
|
51
|
+
<div class="panel panel_tree" id="panel">
|
52
|
+
<div class="header">
|
53
|
+
<div>
|
54
|
+
<label for="search" id="search-label" style="display: none">Search</label>
|
55
|
+
<table>
|
56
|
+
<tr><td>
|
57
|
+
<input type="Search" placeholder="Search" autosave="searchdoc" results="10" id="search" autocomplete="off"/>
|
58
|
+
</td></tr>
|
59
|
+
</table></div>
|
60
|
+
</div>
|
61
|
+
<div class="tree">
|
62
|
+
<ul>
|
63
|
+
</ul>
|
64
|
+
</div>
|
65
|
+
<div class="result">
|
66
|
+
<ul>
|
67
|
+
</ul>
|
68
|
+
</div>
|
69
|
+
</div>
|
70
|
+
<a href="links.html" id="links">index</a>
|
71
|
+
</body>
|
72
|
+
</html>
|
@@ -0,0 +1,88 @@
|
|
1
|
+
##
|
2
|
+
# connFu is a platform of Telefonica delivered by Bluevia Labs.
|
3
|
+
#
|
4
|
+
# Please, check out www.connfu.com and if you need further information
|
5
|
+
# contact us at mailto:support@connfu.com
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
require 'connfu'
|
9
|
+
|
10
|
+
describe Connfu::ConnfuMessageFormatter do
|
11
|
+
|
12
|
+
context "initialize" do
|
13
|
+
|
14
|
+
it "should format properly a SMS event" do
|
15
|
+
message = Connfu::ConnfuMessageFormatter.format_voice_sms(["sms", { "appId" => "123456", "from" => "+34677001122", "to" => "+4475234444", "message" => "Hello connFu application!" }])
|
16
|
+
message.should be_instance_of(Array)
|
17
|
+
message.length.should be(1)
|
18
|
+
message = message.pop
|
19
|
+
message.message_type.should eql("new")
|
20
|
+
message.channel_type.should eql("sms")
|
21
|
+
message.channel_name.should eql("123456")
|
22
|
+
message.to.should eql("+4475234444")
|
23
|
+
message.from.should eql("+34677001122")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should format properly a join event" do
|
27
|
+
message = Connfu::ConnfuMessageFormatter.format_voice_sms(["join", {"appId" => "123456","conferenceId" => "connfu://channel-99999#", "from" => "+34677001122", "to" => "+4475234444"}])
|
28
|
+
message.should be_instance_of(Array)
|
29
|
+
message.length.should be(1)
|
30
|
+
message = message.pop
|
31
|
+
|
32
|
+
message.message_type.should eql("join")
|
33
|
+
message.channel_type.should eql("voice")
|
34
|
+
message.channel_name.should eql("channel-99999")
|
35
|
+
message.to.should eql("+4475234444")
|
36
|
+
message.from.should eql("+34677001122")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should discard an invalid voice event type" do
|
40
|
+
message = Connfu::ConnfuMessageFormatter.format_voice_sms(["join2", {"appId" => "123456","conferenceId" => "connfu://99999#", "from" => "+34677001122", "to" => "+4475234444"}])
|
41
|
+
message.should be_instance_of(Array)
|
42
|
+
puts message[0]
|
43
|
+
message.length.should be(0)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should discard an invalid voice event message" do
|
47
|
+
message = Connfu::ConnfuMessageFormatter.format_voice_sms(["join2"])
|
48
|
+
message.should be_instance_of(Array)
|
49
|
+
puts message[0]
|
50
|
+
message.length.should be(0)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should format properly a twitter event" do
|
54
|
+
raw = {"id" => "source:twitter/94cc51b0-e5e3-11e0-a5f3-12313b050905","occurred_at" => "2011-09-23T12:57:23.000Z","actor" => {"object_type" => "person","id" => "connfudev","display_name" => "connfudev","published" => "2011-07-03T11:02:39.000Z","image" => {"url" => "http://a3.twimg.com/profile_images/1424588002/ninja_normal.jpg"},"statuses_count" => 128,"profile_text_color" => "333333","geo_enabled" => true,"show_all_inline_media" => false,"protected" => false,"friends_count" => 1,"favourites_count" => 0,"description" => "","profile_image_url_https" => "https://si0.twimg.com/profile_images/1424588002/ninja_normal.jpg","profile_use_background_image" => true,"following" => nil,"follow_request_sent" => nil,"listed_count" => 0,"default_profile_image" => false,"profile_link_color" => "0084B4","profile_sidebar_border_color" => "C0DEED","profile_sidebar_fill_color" => "DDEEF6","profile_background_image_url_https" => "https://si0.twimg.com/images/themes/theme1/bg.png","default_profile" => true,"profile_background_tile" => false,"utc_offset" => 0,"lang" => "en","is_translator" => false,"notifications" => nil,"verified" => false,"profile_background_image_url" => "http://a0.twimg.com/images/themes/theme1/bg.png","contributors_enabled" => false,"time_zone" => "London","followers_count" => 0,"profile_background_color" => "C0DEED"},"verb" => "post","object" => {"object_type" => "note","id" => "117221019508424704","url" => "http://twitter.com/connfudev/status/117221019508424704","published" => "2011-07-03T11:02:39.000Z","content" => "yoooooosss","in_reply_to_status_id" => nil,"retweeted" => false,"entities" => {"urls" => [],"user_mentions" => []},"truncated" => false,"place" => nil,"retweet_count" => 0,"favorited" => false,"contributors" => nil},"target" => {"object_type" => "list","display_name" => "connfudev's Twitter Timeline","summary" => "connfudev's Twitter Timeline","image" => {"url" => "http://a3.twimg.com/profile_images/1424588002/ninja_normal.jpg"}},"title" => "yoooooosss","provider" => {"object_type" => "service","id" => "http://twitter.com","display_name" => "Twitter","url" => "http://twitter.com"},"backchat" => {"source" => "TWITTER","bare_uri" => "twitter://connfudev/","user_path" => ["twitter-listener"],"journal" => ["backchat.tracker.TwitterJValueProcessor"],"uuid" => "94cd1500-e5e3-11e0-a5f3-12313b050905","channels" => ["twitter://connfudev/"]}}
|
55
|
+
message = Connfu::ConnfuMessageFormatter.format_message(raw)
|
56
|
+
message.should be_instance_of(Array)
|
57
|
+
message.length.should be(1)
|
58
|
+
message = message.pop
|
59
|
+
message.message_type.should eql("new")
|
60
|
+
message.channel_type.should eql("twitter")
|
61
|
+
message.channel_name.should eql("connfudev")
|
62
|
+
message.to.should be_nil
|
63
|
+
message.from.should eql("connfudev")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should discard a invalid twitter event because sender is invalid" do
|
67
|
+
raw = "{\"id\":\"1111111\",\"remoteId\":\"87872349432582144\",\"summary\":\"\",\"content\":\":foo => \\\"bar\\\"\",\"sender\":\"\",\"recipients\":[],\"tags\":[],\"links\":[],\"attachments\":[],\"timeStamp\":\"2011-07-04T13:16:15.000Z\",\"isDeleted\":false,\"isPublic\":true,\"isArticle\":false}"
|
68
|
+
message = Connfu::ConnfuMessageFormatter.format_message(raw)
|
69
|
+
message.should be_instance_of(Array)
|
70
|
+
message.length.should be(0)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should discard a invalid twitter event because message is not a Hash" do
|
74
|
+
raw = ["foo", "bar"]
|
75
|
+
message = Connfu::ConnfuMessageFormatter.format_message(raw)
|
76
|
+
message.should be_instance_of(Array)
|
77
|
+
message.length.should be(0)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should discard a invalid twitter event because recipient is invalid" do
|
81
|
+
raw = "{\"id\":\"1111111\",\"remoteId\":\"87872349432582144\",\"summary\":\"\",\"content\":\":foo => \\\"bar\\\"\",\"sender\":\"twitter://connfudev/\",\"recipients\":[\"foo\"],\"tags\":[],\"links\":[],\"attachments\":[],\"timeStamp\":\"2011-07-04T13:16:15.000Z\",\"isDeleted\":false,\"isPublic\":true,\"isArticle\":false}"
|
82
|
+
message = Connfu::ConnfuMessageFormatter.format_message(raw)
|
83
|
+
message.should be_instance_of(Array)
|
84
|
+
message.length.should be(0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/spec/connfu_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
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
|
+
|
9
|
+
describe Connfu do
|
10
|
+
|
11
|
+
let(:prov_client) {
|
12
|
+
application = Connfu::Provisioning::Application.new(API_KEY, "endpoint")
|
13
|
+
application.stub(:name) {APP_NAME}
|
14
|
+
application.stub(:description) {APP_DESCRIPTION}
|
15
|
+
application.stub(:stream_name) {APP_STREAM_NAME}
|
16
|
+
|
17
|
+
obj = double 'prov_client'
|
18
|
+
obj.stub(:get_info) { application }
|
19
|
+
obj.stub(:get_channels) {[]}
|
20
|
+
obj
|
21
|
+
}
|
22
|
+
|
23
|
+
context "initialize" do
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
|
27
|
+
Connfu.stub(:prov_client).and_return(prov_client)
|
28
|
+
Connfu.should_receive(:prov_client).twice
|
29
|
+
|
30
|
+
@connfu = Connfu.application(API_KEY)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be an instance of Module when initialized" do
|
34
|
+
@connfu.should be_an_instance_of(Module)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should initialize properly the token attribute" do
|
38
|
+
@connfu.token.should eql(API_KEY)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to read the token attribute" do
|
42
|
+
@connfu.should respond_to(:token)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not be able to write the token attribute" do
|
46
|
+
lambda { @connfu.token="we5rwer" }.should raise_error (NoMethodError)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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::ConnfuStream do
|
11
|
+
|
12
|
+
let(:connfu_stream) do
|
13
|
+
Connfu::ConnfuStream.new(APP_STREAM_NAME, API_KEY, ENDPOINT)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "initialize" do
|
17
|
+
it "should be an instance of Connfu::ConnfuStream when initialized" do
|
18
|
+
connfu_stream.should be_an_instance_of(Connfu::ConnfuStream)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Constructing RSpec examples programmatically
|
22
|
+
{"app_stream" => APP_STREAM_NAME, "api_key" => API_KEY}.each do |attribute, value|
|
23
|
+
it "should initialize properly the parameter #{attribute}" do
|
24
|
+
connfu_stream.instance_variable_get("@#{attribute}").should eql(value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should define a custom message formatter" do
|
29
|
+
connfu_stream.instance_variable_get("@formatter").should eql(Connfu::ConnfuMessageFormatter)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "queue" do
|
34
|
+
let(:message) do
|
35
|
+
Connfu::Message.new({})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be an instance of Queue" do
|
39
|
+
connfu_stream.send(:queue).should be_instance_of(Queue)
|
40
|
+
end
|
41
|
+
it "should be empty when intialized" do
|
42
|
+
connfu_stream.send(:queue).empty?.should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be populate when an incoming message arrives" do
|
46
|
+
connfu_stream.send(:message, [message])
|
47
|
+
connfu_stream.send(:queue).empty?.should be_false
|
48
|
+
connfu_stream.send(:queue).length.should be(1)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be populate when several incoming message arrives" do
|
52
|
+
connfu_stream.send(:message, [message, message, message])
|
53
|
+
connfu_stream.send(:queue).empty?.should be_false
|
54
|
+
connfu_stream.send(:queue).length.should be(3)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should retrieve the first message in the queue" do
|
58
|
+
messages = [message, message, message]
|
59
|
+
connfu_stream.send(:message, messages)
|
60
|
+
connfu_stream.send(:queue).empty?.should be_false
|
61
|
+
messages.each{|msg|
|
62
|
+
connfu_stream.get.should eql(msg)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not add a message if it is not the valid type" do
|
67
|
+
connfu_stream.send(:message, [1111])
|
68
|
+
connfu_stream.send(:queue).empty?.should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context "authentication headers" do
|
74
|
+
let(:headers) do
|
75
|
+
{"accept" => "application/json",
|
76
|
+
"authorization" => "Backchat #{API_KEY}",
|
77
|
+
"Connection" => "Keep-Alive"}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should include the required headers" do
|
81
|
+
connfu_stream.send(:headers).should eql(headers)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,227 @@
|
|
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
|
+
|
9
|
+
describe Connfu::Dispatcher do
|
10
|
+
|
11
|
+
let(:prov_client) {
|
12
|
+
application = Connfu::Provisioning::Application.new(API_KEY, ENDPOINT)
|
13
|
+
application.stub(:name) {APP_NAME}
|
14
|
+
application.stub(:description) {APP_DESCRIPTION}
|
15
|
+
application.stub(:stream_name) {APP_STREAM_NAME}
|
16
|
+
|
17
|
+
obj = double 'prov_client'
|
18
|
+
obj.stub(:get_info) { application }
|
19
|
+
obj.stub(:get_channels) { [] }
|
20
|
+
obj
|
21
|
+
}
|
22
|
+
|
23
|
+
context "initialize" do
|
24
|
+
it "should be a Dispatch class instance" do
|
25
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"})
|
26
|
+
obj.should be_instance_of(Connfu::Dispatcher)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise an exception if no listener channels are provided" do
|
30
|
+
lambda { Connfu::Dispatcher.new(nil, nil) }.should raise_error(Exception, "Unable to dispatch events if no channel is defined")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "set_channels" do
|
35
|
+
let(:app_channels) do
|
36
|
+
[{"uid"=>"twitter", "type"=>"twitter", "accounts"=>[{"name"=>"juandebravo"}, {"name"=>"connfudev"}], "filter"=>""},
|
37
|
+
{"uid"=>"juan-voice", "type"=>"sms", "phones" => [{"country"=>"UK", "phone_number"=>"9876"}]},
|
38
|
+
{"uid"=>"juan-voice", "type"=>"voice", "phones" => [{"country"=>"UK", "phone_number"=>"9876"}]},
|
39
|
+
{"uid"=>"channel-1312722260", "type"=>"twitter", "accounts"=>[{"name"=>"juandebravo"}, {"name"=>"finnstr"}], "filter"=>""}]
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:message_details) do
|
43
|
+
{"id" => "external_id", "content" => "foo, bar", "from" => "connfudev", "to" => "osuka", "message_type" => "new"}
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:voice_message_details) do
|
47
|
+
details = message_details
|
48
|
+
details["channel_type"] = "voice"
|
49
|
+
details["to"] = "1234"
|
50
|
+
details["channel_name"] = "juan-voice"
|
51
|
+
details
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:sms_message_details) do
|
55
|
+
details = message_details
|
56
|
+
details["channel_type"] = "sms"
|
57
|
+
details["to"] = "9876"
|
58
|
+
details["channel_name"] = "juan-voice"
|
59
|
+
details
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:twitter_message_details) do
|
63
|
+
details = message_details
|
64
|
+
details["channel_type"] = "twitter"
|
65
|
+
details
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should retrieve only the twitter channels when a twitter message from is retrieved" do
|
69
|
+
details = twitter_message_details
|
70
|
+
details["to"] = "unknown"
|
71
|
+
details["from"] = "connfudev"
|
72
|
+
message = Connfu::Message.new(details)
|
73
|
+
message.channel_name.should be_nil
|
74
|
+
|
75
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
76
|
+
obj.send(:set_channels!, message)
|
77
|
+
message.channel_name.should be_kind_of(Array)
|
78
|
+
message.channel_name.length.should eql(1)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should retrieve only the twitter channels when a twitter message from is retrieved. return two channels" do
|
82
|
+
details = twitter_message_details
|
83
|
+
details["to"] = "unknown"
|
84
|
+
details["from"] = "juandebravo"
|
85
|
+
message = Connfu::Message.new(details)
|
86
|
+
message.channel_name.should be_nil
|
87
|
+
|
88
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
89
|
+
obj.send(:set_channels!, message)
|
90
|
+
message.channel_name.should be_kind_of(Array)
|
91
|
+
message.channel_name.length.should eql(2)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should retrieve only the twitter channels when a twitter message to is retrieved" do
|
95
|
+
details = twitter_message_details
|
96
|
+
details["to"] = "connfudev"
|
97
|
+
details["from"] = "unknown"
|
98
|
+
message = Connfu::Message.new(details)
|
99
|
+
message.channel_name.should be_nil
|
100
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
101
|
+
obj.send(:set_channels!, message)
|
102
|
+
message.channel_name.should be_kind_of(Array)
|
103
|
+
message.channel_name.length.should eql(1)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should retrieve only the twitter channels when a twitter message to is retrieved. return two channels" do
|
107
|
+
details = twitter_message_details
|
108
|
+
details["to"] = "juandebravo"
|
109
|
+
details["from"] = "unknown"
|
110
|
+
message = Connfu::Message.new(details)
|
111
|
+
message.channel_name.should be_nil
|
112
|
+
|
113
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
114
|
+
obj.send(:set_channels!, message)
|
115
|
+
message.channel_name.should be_kind_of(Array)
|
116
|
+
message.channel_name.length.should eql(2)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should retrieve only the voice channels when a voice message is retrieved" do
|
120
|
+
message = Connfu::Message.new(voice_message_details)
|
121
|
+
message.channel_name.should_not be_nil
|
122
|
+
message.channel_name.should eql("juan-voice")
|
123
|
+
|
124
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
125
|
+
obj.send(:set_channels!, message)
|
126
|
+
message.channel_name.should be_kind_of(Array)
|
127
|
+
message.channel_name.length.should eql(1)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should retrieve no voice channel when DID is not expected" do
|
131
|
+
voice = voice_message_details
|
132
|
+
voice["channel_name"] = "foo"
|
133
|
+
message = Connfu::Message.new(voice)
|
134
|
+
message.channel_name.should_not be_nil
|
135
|
+
message.channel_name.should eql("foo")
|
136
|
+
|
137
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
138
|
+
obj.send(:set_channels!, message)
|
139
|
+
puts message.channel_name
|
140
|
+
message.channel_name.should be_kind_of(Array)
|
141
|
+
message.channel_name.length.should eql(0)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should retrieve no sms channel when DID is not expected" do
|
145
|
+
sms = sms_message_details
|
146
|
+
sms["to"] = "1234"
|
147
|
+
message = Connfu::Message.new(sms)
|
148
|
+
|
149
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
150
|
+
obj.send(:set_channels!, message)
|
151
|
+
puts message.channel_name
|
152
|
+
message.channel_name.should be_kind_of(Array)
|
153
|
+
message.channel_name.length.should eql(0)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should retrieve only the sms channels when a sms message is retrieved" do
|
157
|
+
message = Connfu::Message.new(sms_message_details)
|
158
|
+
message.channel_name.should_not be_nil
|
159
|
+
message.channel_name.should eql("juan-voice")
|
160
|
+
|
161
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
162
|
+
|
163
|
+
obj.send(:set_channels!, message)
|
164
|
+
message.channel_name.should be_kind_of(Array)
|
165
|
+
message.channel_name.length.should eql(1)
|
166
|
+
message.channel_name[0].should eql("juan-voice")
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should retrieve no channel when unknown channel_type is retrieved" do
|
170
|
+
message = Connfu::Message.new(message_details)
|
171
|
+
obj = Connfu::Dispatcher.new(nil, {:foo => "bar"}, app_channels)
|
172
|
+
obj.send(:set_channels!, message)
|
173
|
+
message.channel_name.should be_kind_of(Array)
|
174
|
+
message.channel_name.length.should eql(0)
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
context "twitter stream" do
|
181
|
+
|
182
|
+
before(:each) do
|
183
|
+
|
184
|
+
Connfu.stub(:prov_client).and_return(prov_client)
|
185
|
+
Connfu.should_receive(:prov_client).twice
|
186
|
+
|
187
|
+
Connfu::Dispatcher.any_instance.stub(:max_messages).and_return(10)
|
188
|
+
Connfu::Listener.any_instance.stub(:max_messages).and_return(10)
|
189
|
+
Connfu::Provisioning::Application.any_instance.stub(:get_channels).and_return { [] }
|
190
|
+
|
191
|
+
Connfu::ConnfuStream.any_instance.stub(:start_listening) { nil }
|
192
|
+
|
193
|
+
@id = 0
|
194
|
+
Connfu::ConnfuStream.any_instance.stub(:get) {
|
195
|
+
@id+=1
|
196
|
+
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}"
|
197
|
+
Connfu::ConnfuMessageFormatter.send(:format_message, message) # private method
|
198
|
+
}
|
199
|
+
|
200
|
+
#Connfu.logger = STDOUT
|
201
|
+
|
202
|
+
@connfu = Connfu.application(API_KEY) {
|
203
|
+
listen(:twitter) do |channel|
|
204
|
+
|
205
|
+
channel.filter = "text has #conference"
|
206
|
+
|
207
|
+
channel.on(:new) do |tweet|
|
208
|
+
# puts "A new tweet arrived"
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "dispatcher" do
|
218
|
+
it "should be an instance of Connfu::Dispatcher when initialized" do
|
219
|
+
@connfu.dispatcher.should be_an_instance_of(Connfu::Dispatcher)
|
220
|
+
end
|
221
|
+
it "should receive ten messages" do
|
222
|
+
@connfu.dispatcher.counter.should eql(10)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|