connfu-client 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,9 +1,9 @@
1
-
2
1
  == Welcome to connFu
3
2
 
4
3
  connFu gem provides an easy way to get access to connFu platform using the defined DSL and the provisioning API.
5
4
 
6
5
  connFu is a platform of Telefonica delivered by Bluevia Labs.
6
+
7
7
  Please, check out http://www.connfu.com and if you need further information do not hesitate to contact us at *support* *at* *connfu* *dot* *com*
8
8
 
9
9
  === Why connFu?
@@ -57,11 +57,11 @@ connFu DSL allows you to create really powerful applications in just a few lines
57
57
 
58
58
  4. Update the code generated in hello-world/application.rb with your valid application token:
59
59
 
60
- token = "YOUR-VALID-CONNFU-TOKEN"
60
+ token = "YOUR-VALID-CONNFU-TOKEN"
61
61
 
62
62
  4. Run the code:
63
63
 
64
- ruby application.rb
64
+ ruby application.rb
65
65
 
66
66
  5. You'll get as output something like:
67
67
 
@@ -96,33 +96,27 @@ A voice channel has four related events:
96
96
  * *voice*:*new**\_**topic*: the conference topic was changed
97
97
  * *sms*:*new*: a sms sent by an user was received in the number
98
98
 
99
- require 'connfu'
100
-
101
- TOKEN = "<app-token>"
102
-
103
- Connfu.application(TOKEN) {
104
-
105
- listen(:voice) do |conference|
106
- conference.on(:join) do |call|
107
- puts "New inbound call from #{call[:from]} on number #{call[:to]}"
108
- end
109
-
110
- conference.on(:leave) do |call|
111
- puts "#{call[:from]} has left the conference #{call[:channel_name]}"
112
- end
113
-
114
- conference.on(:new_topic) do |topic|
115
- puts "New topic in the conference #{topic[:channel_name]}: #{topic[:content]}"
116
- end
117
- end
118
-
119
- listen(:sms) do |sms|
120
- sms.on(:new) do |message|
121
- puts "New inbound sms"
122
- puts "#{message}"
123
- end
124
- end
125
- }
99
+ require 'connfu'
100
+ TOKEN = "<app-token>"
101
+ Connfu.application(TOKEN) {
102
+ listen(:voice) do |conference|
103
+ conference.on(:join) do |call|
104
+ puts "New inbound call from #{call[:from]} on number #{call[:to]}"
105
+ end
106
+ conference.on(:leave) do |call|
107
+ puts "#{call[:from]} has left the conference #{call[:channel_name]}"
108
+ end
109
+ conference.on(:new_topic) do |topic|
110
+ puts "New topic in the conference #{topic[:channel_name]}: #{topic[:content]}"
111
+ end
112
+ end
113
+ listen(:sms) do |sms|
114
+ sms.on(:new) do |message|
115
+ puts "New inbound sms"
116
+ puts "#{message}"
117
+ end
118
+ end
119
+ }
126
120
 
127
121
 
128
122
  === Handling twitter channels
@@ -131,21 +125,15 @@ A twitter channel has one related event:
131
125
 
132
126
  * *twitter*:*new*: a new tweet sent by an associated twitter account reached the application
133
127
 
134
- require 'connfu'
135
-
136
- TOKEN = "<app-token>"
137
-
138
- Connfu.application(TOKEN) {
139
-
140
- listen(:twitter) do |twitter|
141
-
142
- twitter.on(:new) do |tweet|
143
- puts "#{tweet[:channel_name]} just posted a new tweet in the application: #{tweet.content}"
144
- end
145
-
146
- end
147
-
148
- }
128
+ require 'connfu'
129
+ TOKEN = "<app-token>"
130
+ Connfu.application(TOKEN) {
131
+ listen(:twitter) do |twitter|
132
+ twitter.on(:new) do |tweet|
133
+ puts "#{tweet[:channel_name]} just posted a new tweet in the application: #{tweet.content}"
134
+ end
135
+ end
136
+ }
149
137
 
150
138
 
151
139
  === Examples
@@ -157,8 +145,7 @@ This application defines two channels, voice and twitter, and handles conference
157
145
  Conference attendees can also tweet information regarding the chat room using the hashtag #conference.
158
146
 
159
147
  require 'connfu'
160
-
161
- TOKEN = "<valid-app-token>"
148
+ TOKEN = "<valid-app-token>"
162
149
  NEW_CALL_MESSAGE = "new call received"
163
150
 
164
151
  HANG_MESSAGE = "has left the call"
@@ -230,15 +217,14 @@ The next sections show information about how to manage voice channels in an appl
230
217
 
231
218
  This snippet of code creates a voice channel and associates a phone number to the application.
232
219
 
233
- require 'connfu'
234
-
220
+ require 'connfu'
235
221
  application = Connfu::Provisioning::Application.new(api_key)
236
222
  application.create_voice_channel("my-voice-channel", "UK")
237
223
 
238
224
  Optionally a third parameter can be used defining the channel privacy settings:
239
225
 
240
- * Connfu::Provisioning::Voice::Channel::WHITELIST : only a specific set of phone numbers can join the conference
241
- * Connfu::Provisioning::Voice::Channel::PUBLIC : any user can join the conference
226
+ * Connfu::Provisioning::Voice::Channel::WHITELIST : only a specific set of phone numbers can join the conference
227
+ * Connfu::Provisioning::Voice::Channel::PUBLIC : any user can join the conference
242
228
 
243
229
  Valid country codes are _UK_ and _US_
244
230
 
@@ -246,41 +232,37 @@ Valid country codes are _UK_ and _US_
246
232
 
247
233
  This snippet of code retrieves information about the voice channels associated to the application.
248
234
 
249
- require 'connfu'
250
-
251
- application = Connfu::Provisioning::Application.new(api_key)
252
- voice_channels = application.get_voice_channel
235
+ require 'connfu'
236
+ application = Connfu::Provisioning::Application.new(api_key)
237
+ voice_channels = application.get_voice_channel
253
238
 
254
239
  ==== Retrieve a Voice channel
255
240
 
256
241
  This snippet of code retrieves information about a specific voice channel associated to the application.
257
242
 
258
- require 'connfu'
259
-
260
- application = Connfu::Provisioning::Application.new(api_key)
261
- voice_channel = application.get_voice_channel("my-voice-channel")
243
+ require 'connfu'
244
+ application = Connfu::Provisioning::Application.new(api_key)
245
+ voice_channel = application.get_voice_channel("my-voice-channel")
262
246
 
263
247
  ==== Update Voice channel
264
248
 
265
249
  This snippet of code updates the topic, privacy setting, welcome\_message and rejected\_message associated to the voice channel.
266
250
 
267
- require 'connfu'
268
-
269
- application = Connfu::Provisioning::Application.new(api_key)
270
- application.update_voice_channel("my-voice-channel",
271
- {:topic =>"new topic",
272
- :welcome_message => "Hello!",
273
- :rejected_message => "You're not allowed to join the conference.",
274
- :privacy => Connfu::Provisioning::Voice::Privacy::PUBLIC})
251
+ require 'connfu'
252
+ application = Connfu::Provisioning::Application.new(api_key)
253
+ application.update_voice_channel("my-voice-channel",
254
+ {:topic =>"new topic",
255
+ :welcome_message => "Hello!",
256
+ :rejected_message => "You're not allowed to join the conference.",
257
+ :privacy => Connfu::Provisioning::Voice::Privacy::PUBLIC})
275
258
 
276
259
  ==== Delete a Voice channel
277
260
 
278
261
  This snippet of code deletes a voice channel previously created.
279
262
 
280
- require 'connfu'
281
-
282
- application = Connfu::Provisioning::Application.new(api_key)
283
- application.delete_voice_channel("my-voice-channel")
263
+ require 'connfu'
264
+ application = Connfu::Provisioning::Application.new(api_key)
265
+ application.delete_voice_channel("my-voice-channel")
284
266
 
285
267
  ==== Voice Channel Whitelist
286
268
 
@@ -290,37 +272,33 @@ Only a predefined set of numbers can join a conference created using a voice cha
290
272
 
291
273
  This snippet of code adds a new user to the conference whitelist.
292
274
 
293
- require 'connfu'
294
-
295
- application = Connfu::Provisioning::Application.new(api_key)
296
- application.add_whitelist("my-voice-channel", "paul", "0044654332")
275
+ require 'connfu'
276
+ application = Connfu::Provisioning::Application.new(api_key)
277
+ application.add_whitelist("my-voice-channel", "paul", "0044654332")
297
278
 
298
279
  ===== Retrieve a channel whitelist
299
280
 
300
281
  This snippet of code retrieves a conference whitelist.
301
282
 
302
- require 'connfu'
303
-
304
- application = Connfu::Provisioning::Application.new(api_key)
305
- whitelist = application.get_whitelist("my-voice-channel")
283
+ require 'connfu'
284
+ application = Connfu::Provisioning::Application.new(api_key)
285
+ whitelist = application.get_whitelist("my-voice-channel")
306
286
 
307
287
  ===== Delete the Voice channel whitelist
308
288
 
309
289
  This snippet of code deletes the whole conference whitelist.
310
290
 
311
- require 'connfu'
312
-
313
- application = Connfu::Provisioning::Application.new(api_key)
314
- application.delete_whitelist("my-voice-channel")
291
+ require 'connfu'
292
+ application = Connfu::Provisioning::Application.new(api_key)
293
+ application.delete_whitelist("my-voice-channel")
315
294
 
316
295
  ===== Delete a whitelist entry
317
296
 
318
297
  This snippet of code deletes a specific whitelist item.
319
298
 
320
- require 'connfu'
321
-
322
- application = Connfu::Provisioning::Application.new(api_key)
323
- application.delete_whitelist("my-voice-channel", "0044654332")
299
+ require 'connfu'
300
+ application = Connfu::Provisioning::Application.new(api_key)
301
+ application.delete_whitelist("my-voice-channel", "0044654332")
324
302
 
325
303
  ==== Voice channel numbers
326
304
 
@@ -330,28 +308,25 @@ A voice channel can have more than one mapped phone number. This will enable use
330
308
 
331
309
  This snippet of code adds a new phone number to the voice channel. The desired country must be supported.
332
310
 
333
- require 'connfu'
334
-
335
- application = Connfu::Provisioning::Application.new(api_key)
336
- application.add_phone("my-voice-channel", "UK")
311
+ require 'connfu'
312
+ application = Connfu::Provisioning::Application.new(api_key)
313
+ application.add_phone("my-voice-channel", "UK")
337
314
 
338
315
  ===== Remove a number from a voice channel
339
316
 
340
317
  This snippet of code removes a phone number from the voice channel and release the resource.
341
318
 
342
- require 'connfu'
343
-
344
- application = Connfu::Provisioning::Application.new(api_key)
345
- application.delete_phone("my-voice-channel", "0044654332")
319
+ require 'connfu'
320
+ application = Connfu::Provisioning::Application.new(api_key)
321
+ application.delete_phone("my-voice-channel", "0044654332")
346
322
 
347
323
  ===== Retrieve all the voice channel numbers
348
324
 
349
325
  This snippet of code retrieves a voice channel phone lists.
350
326
 
351
- require 'connfu'
352
-
353
- application = Connfu::Provisioning::Application.new(api_key)
354
- phones = application.get_phones("my-voice-channel")
327
+ require 'connfu'
328
+ application = Connfu::Provisioning::Application.new(api_key)
329
+ phones = application.get_phones("my-voice-channel")
355
330
 
356
331
  === Twitter channels
357
332
 
@@ -359,39 +334,34 @@ This snippet of code retrieves a voice channel phone lists.
359
334
 
360
335
  This snippet of code creates a twitter channel with two twitter accounts and two hashtags to filter only those messages with a specific hashtag.
361
336
 
362
- require 'connfu'
363
-
364
- application = Connfu::Provisioning::Application.new(api_key)
365
- application.create_twitter_channel("my-twitter-channel",
366
- {:origin => "juandebravo", :hashtags => ["ruby", "rails]})
337
+ require 'connfu'
338
+ application = Connfu::Provisioning::Application.new(api_key)
339
+ application.create_twitter_channel("my-twitter-channel",
340
+ {:origin => "juandebravo", :hashtags => ["ruby", "rails]})
367
341
 
368
342
  ==== Retrieve all Twitter channels
369
343
 
370
344
  This snippet of code retrieves information about all the twitter channels previously created.
371
345
 
372
- require 'connfu'
373
-
374
- application = Connfu::Provisioning::Application.new(api_key)
375
- twitter_channels = application.get_twitter_channel
346
+ require 'connfu'
347
+ application = Connfu::Provisioning::Application.new(api_key)
348
+ twitter_channels = application.get_twitter_channel
376
349
 
377
350
  ==== Retrieve a Twitter channel
378
351
 
379
352
  This snippet of code retrieves information about a specific twitter channel previously created.
380
353
 
381
- require 'connfu'
382
-
383
- application = Connfu::Provisioning::Application.new(api_key)
384
- twitter_channel = application.get_twitter_channel("my-twitter_channel")
354
+ require 'connfu'
355
+ application = Connfu::Provisioning::Application.new(api_key)
356
+ twitter_channel = application.get_twitter_channel("my-twitter_channel")
385
357
 
386
358
  ==== Delete a Twitter channel
387
359
 
388
360
  This snippet of code deletes a specific twitter channel previously created.
389
361
 
390
-
391
- require 'connfu'
392
-
393
- application = Connfu::Provisioning::Application.new(api_key)
394
- application.delete_twitter_channel("my-twitter_channel")
362
+ require 'connfu'
363
+ application = Connfu::Provisioning::Application.new(api_key)
364
+ application.delete_twitter_channel("my-twitter_channel")
395
365
 
396
366
  == License
397
367
 
data/bin/connfu-client CHANGED
@@ -22,14 +22,14 @@ long_desc <<EOS
22
22
  Use scaffold to create a basic application that listens to all the available connFu channels.
23
23
  A connFu application can listen to one or more channels.
24
24
  Each channel will launch the application logic based on the event fetched using the streaming endpoint that belongs to the application.
25
- You need a valid application token that can be retrieved in connFu web portal, http://www.connfu.com
25
+ You need a valid application token that can be retrieved in connFu web portal, https://www.connfu.com
26
26
  \n
27
27
  EOS
28
28
 
29
29
  arg_name "project_name"
30
30
  command :scaffold do |c|
31
31
  c.desc 'Channels the application should listen to'
32
- c.default_value ":all"
32
+ c.default_value nil
33
33
  c.flag :c
34
34
 
35
35
  c.desc 'Main file that will contain the application logic'
@@ -57,7 +57,7 @@ command :scaffold do |c|
57
57
  end
58
58
  puts " #{green("create")} #{args[0]}"
59
59
 
60
- Connfu::Cli::Generator.run(args[0], nil, options[:f])
60
+ Connfu::Cli::Generator.run(args[0], options[:c], options[:f])
61
61
 
62
62
  puts " #{green("create")} #{options[:f]}"
63
63
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["connFu team", "Juan de Bravo"]
10
10
  s.email = ["devs@connfu.com", "juandebravo@gmail.com"]
11
- s.homepage = "http://www.github.com/O2Labs/connfu-client"
11
+ s.homepage = "http://www.github.com/bluevialabs/connfu-client"
12
12
  s.summary = %q{connFu DSL to get access to connFu platform}
13
13
  s.description = %q{This gem provides a smooth access to connFu capabilities}
14
14
 
@@ -23,7 +23,7 @@ Connfu.logger = STDOUT
23
23
 
24
24
  Connfu.log_level = Logger::DEBUG
25
25
 
26
- @connfu = Connfu.application(token, "http://localhost:3000/v1") {
26
+ @connfu = Connfu.application(token) {
27
27
 
28
28
  listen(:voice) do |conference|
29
29
  conference.on(:join) do |call|
@@ -58,6 +58,12 @@ Connfu.log_level = Logger::DEBUG
58
58
  end
59
59
  end
60
60
 
61
+ listen(:rss) do |rss|
62
+ rss.on(:new) do |post|
63
+ puts "New post with title #{post[:content]} in the channel #{post[:channel_name]}"
64
+ end
65
+ end
66
+
61
67
  listen(:sms) do |sms|
62
68
  sms.on(:new) do |message|
63
69
  puts "New inbound sms"
@@ -1,2 +1,2 @@
1
1
 
2
- CONNFU_ENDPOINT = "http://localhost:3000/v1"
2
+ CONNFU_ENDPOINT = "https://api.connfu.com/v1"
@@ -1,50 +1,72 @@
1
+ require 'connfu/listener_channel'
2
+
1
3
  module Connfu
2
4
  ##
3
5
  # This module helps a client to manage connFu applications
4
6
  module Cli
5
7
  module Generator
6
8
 
7
- APPLICATION_TEMPLATE=<<END
8
-
9
- require 'connfu'
10
-
11
- ##
12
- # This application is an example of how to create a connFu application
13
-
14
- token = "YOUR-VALID-CONNFU-TOKEN"
9
+ VOICE_CHANNEL=<<END
15
10
 
16
- Connfu.logger = STDOUT
17
- Connfu.log_level = Logger::DEBUG
18
-
19
- Connfu.application(token) {
20
-
21
- listen(:voice) do |conference|
11
+ listen(:voice) do |conference|
22
12
  conference.on(:join) do |call|
23
- puts "New inbound call from \#{call[:from]} on number \#{call[:to]}"
24
- end
13
+ puts "\e[32mNew inbound call from \#{call[:from]} on number \#{call[:to]}\e[0m"
14
+ end
25
15
 
26
- conference.on(:leave) do |call|
27
- puts "\#{call[:from]} has left the conference \#{call[:channel_name]}"
28
- end
16
+ conference.on(:leave) do |call|
17
+ puts "\e[32m\#{call[:from]} has left the conference \#{call[:channel_name]}\e[0m"
18
+ end
29
19
 
30
- conference.on(:new_topic) do |topic|
31
- puts "New topic in the conference \#{topic[:channel_name]}: \#{topic[:content]}"
32
- end
20
+ conference.on(:new_topic) do |topic|
21
+ puts "\e[32mNew topic in the conference \#{topic[:channel_name]}: \#{topic[:content]}\e[0m"
22
+ end
33
23
  end
34
24
 
25
+ END
26
+ TWITTER_CHANNEL=<<END
27
+
35
28
  listen(:twitter) do |twitter|
36
29
  twitter.on(:new) do |tweet|
37
- puts "\#{tweet[:channel_name]} just posted a new tweet in the conference room: \#{tweet.content}"
30
+ puts "\e[32m\#{tweet[:channel_name]} just posted a new tweet in the conference room: \#{tweet.content}\e[0m"
38
31
  end
39
32
  end
33
+
34
+ END
35
+ SMS_CHANNEL=<<END
40
36
 
41
37
  listen(:sms) do |sms|
42
38
  sms.on(:new) do |message|
43
- puts "New inbound sms from \#{message[:from]}: \#{message[:content]}"
39
+ puts "\e[32mNew inbound sms from \#{message[:from]}: \#{message[:content]}\e[0m"
44
40
  end
45
41
  end
46
42
 
47
- }
43
+ END
44
+
45
+ RSS_CHANNEL=<<END
46
+
47
+ listen(:rss) do |rss|
48
+ rss.on(:new) do |post|
49
+ puts "\e[32mNew post with title \#{post[:channel_name]} in the blog \#{post[:channel_name]}\e[0m"
50
+ end
51
+ end
52
+
53
+ END
54
+
55
+ APPLICATION_TEMPLATE=<<END
56
+
57
+ require 'connfu'
58
+
59
+ ##
60
+ # This application is an example of how to create a connFu application
61
+
62
+ token = "YOUR-VALID-CONNFU-TOKEN"
63
+
64
+ Connfu.logger = STDOUT
65
+ Connfu.log_level = Logger::INFO
66
+
67
+ Connfu.application(token) {
68
+ %{channels}
69
+ }
48
70
 
49
71
  END
50
72
 
@@ -58,10 +80,30 @@ END
58
80
  #
59
81
  # ==== Return
60
82
  def run(name, channels = nil, file_name = "application.rb")
83
+
84
+ channels.is_a?(String) and channels = channels.split.map{|channel| channel.to_sym}
85
+
86
+ channels_templates = {:voice => VOICE_CHANNEL, :sms => SMS_CHANNEL, :twitter => TWITTER_CHANNEL, :rss => RSS_CHANNEL}
87
+
88
+ code = APPLICATION_TEMPLATE.dup
89
+
90
+ if channels.nil?
91
+ channels = channels_templates.values.join
92
+ else
93
+ channels.delete_if{|channel| !Connfu::ListenerChannel::CHANNEL_TYPES.include?(channel)}
94
+ channels = channels.map{|item| channels_templates[item]}.join
95
+ end
96
+ values = {:channels => channels}
97
+
98
+ code.gsub!(/%\{(\w+)\}/) do |match|
99
+ key = $1
100
+ values[key.to_sym]
101
+ end
102
+
61
103
  Dir.mkdir(name)
62
104
  Dir.chdir(name) do
63
105
  File.open(file_name, 'w') do |f|
64
- f.write(APPLICATION_TEMPLATE)
106
+ f.write(code)
65
107
  end
66
108
  end
67
109
  end # end:run
@@ -68,14 +68,32 @@ module Connfu
68
68
 
69
69
  if message.is_a?(Array)
70
70
  message.each { |msg|
71
- params = fetch_values.call(msg)
72
- # include the message if valid params
73
- params.nil? or values << Connfu::Message.new(params)
71
+ if msg.respond_to?("has_key?") && msg.has_key?("backchat") && msg["backchat"].has_key?("source")
72
+ case msg["backchat"]["source"].downcase
73
+ when "twitter"
74
+ params = fetch_values.call(msg)
75
+ when "webfeed"
76
+ params = format_rss_message(msg)
77
+ else
78
+ params = nil
79
+ end
80
+ # include the message if valid params
81
+ params.nil? or values << Connfu::Message.new(params)
82
+ end
74
83
  }
75
84
  else
76
- params = fetch_values.call(message)
77
- # include the message if valid params
78
- params.nil? or values << Connfu::Message.new(params)
85
+ if message.respond_to?("has_key?") && message.has_key?("backchat") && message["backchat"].has_key?("source")
86
+ case message["backchat"]["source"].downcase
87
+ when "twitter"
88
+ params = fetch_values.call(message)
89
+ when "webfeed"
90
+ params = format_rss_message(message)
91
+ else
92
+ params = nil
93
+ end
94
+ # include the message if valid params
95
+ params.nil? or values << Connfu::Message.new(params)
96
+ end
79
97
  end
80
98
  values
81
99
  end
@@ -128,7 +146,29 @@ module Connfu
128
146
  []
129
147
  end
130
148
  end
131
- end
132
149
 
150
+ def format_rss_message(msg)
151
+ begin
152
+ if msg.is_a?(Hash)
153
+ params = {
154
+ :id => msg["object"]["id"],
155
+ :content => msg["title"],
156
+ :message_type => "new",
157
+ :channel_type => "rss",
158
+ :channel_name => msg["backchat"]["bare_uri"],
159
+ :from => msg["actor"]["id"],
160
+ :to => []
161
+ }
162
+ params
163
+ else
164
+ logger.error("Invalid message format: #{msg}")
165
+ nil
166
+ end
167
+ rescue => ex
168
+ logger.error("Unable to fetch values from message #{msg}. Caught exception #{ex}")
169
+ nil
170
+ end
171
+ end
172
+ end
133
173
  end
134
174
  end
@@ -126,11 +126,16 @@ module Connfu
126
126
  events = []
127
127
  temp_events = []
128
128
  chunk.each { |value|
129
- json = ActiveSupport::JSON.decode(value)
129
+ begin
130
+ json = ActiveSupport::JSON.decode(value.force_encoding("UTF-8"))
131
+ rescue Exception => ex
132
+ json = nil
133
+ logger.error("Unable to decode JSON")
134
+ end
130
135
  if json
131
136
  unless json.is_a?(Array) # Twitter - RSS message
132
137
  unless json.nil?
133
- logger.debug("#{self.class} Got a twitter message")
138
+ logger.debug("#{self.class} Got a stream message")
134
139
  temp_events << @formatter.format_message(json)
135
140
  temp_events.nil? or events << temp_events.flatten
136
141
  else
@@ -139,6 +139,10 @@ module Connfu
139
139
  item["phone_number"].eql?(message.to)
140
140
  }.length > 0
141
141
  }
142
+ when "rss"
143
+ channels = channels.select { |channel|
144
+ channel["uri"].eql?(message.channel_name)
145
+ }
142
146
  else
143
147
  logger.warn("This code should not be executed because the first select should avoid this")
144
148
  logger.info("Unexpected message: #{message.channel_type}")
@@ -134,7 +134,7 @@ module Connfu
134
134
  filter = []
135
135
 
136
136
  # filter = "tags:(tag1 AND tag2...)
137
- if params.has_key?(:hashtags) and params[:hashtags].length > 0
137
+ if params.has_key?(:hashtags) && params[:hashtags].respond_to?(:length) && params[:hashtags].length > 0
138
138
  filter << "tags:(#{params[:hashtags].map { |hashtag| "#{hashtag}" }.join(" AND ")})"
139
139
  end
140
140
 
@@ -2,5 +2,5 @@
2
2
  module Connfu
3
3
  ##
4
4
  # Current connFu DSL version
5
- VERSION = "0.1"
5
+ VERSION = "0.1.1"
6
6
  end
@@ -63,6 +63,19 @@ describe Connfu::ConnfuMessageFormatter do
63
63
  message.from.should eql("connfudev")
64
64
  end
65
65
 
66
+ it "should format properly a RSS event" do
67
+ raw = {"id"=>"http://identi.ca/bookmark/2eaba5c4-6377-4b59-8281-df8963c5ae25", "occurred_at"=> "2011-09-27 18:37:01 UTC", "actor"=>{"object_type"=>"person", "id"=>"http://identi.ca/user/530127", "display_name"=>"popl", "url"=>"http://identi.ca/user/530127"}, "verb"=>"post", "object"=>{"object_type"=>"article", "id"=>"http://identi.ca/bookmark/2eaba5c4-6377-4b59-8281-df8963c5ae25", "display_name"=>"Dobre ofert kredytu na firme pewne kredyty na firme", "summary"=>"Masz firme ?", "published" => "2011-09-27 18:37:01 UTC", "updated"=> "2011-09-27 18:37:01 UTC"}, "title"=>"Dobre ofert kredytu na firme pewne kredyty na firme", "provider"=>{"object_type"=>"service", "id"=>"http://identi.ca/", "display_name"=>"Identi.ca public timeline", "summary"=>"Identi.ca updates from everyone!", "url"=>"tag:identi.ca,2011-09-27:PublicTimeline", "published"=>"2011-09-27 18:39:52 UTC"}, "backchat"=>{"source"=>"WEBFEED", "bare_uri"=>"http://identi.ca/api/statuses/public_timeline.atom", "user_path"=>["http://identi.ca/api/statuses/public_timeline.atom"], "journal"=>["feed-distributor"], "uuid"=>"16acab10-e938-11e0-8d2b-12313b050905", "channels"=>["http://identi.ca/api/statuses/public_timeline.atom"]}}
68
+ message = Connfu::ConnfuMessageFormatter.format_message(raw)
69
+ message.should be_instance_of(Array)
70
+ message.length.should be(1)
71
+ message = message.pop
72
+ message.message_type.should eql("new")
73
+ message.channel_type.should eql("rss")
74
+ message.channel_name.should eql("http://identi.ca/api/statuses/public_timeline.atom")
75
+ message.to.should eql([])
76
+ message.from.should eql("http://identi.ca/user/530127")
77
+ end
78
+
66
79
  it "should discard a invalid twitter event because sender is invalid" do
67
80
  raw = "{\"id\":\"1111111\",\"remoteId\":\"87872349432582144\",\"summary\":\"\",\"content\":\":foo =&gt; \\\"bar\\\"\",\"sender\":\"\",\"recipients\":[],\"tags\":[],\"links\":[],\"attachments\":[],\"timeStamp\":\"2011-07-04T13:16:15.000Z\",\"isDeleted\":false,\"isPublic\":true,\"isArticle\":false}"
68
81
  message = Connfu::ConnfuMessageFormatter.format_message(raw)
@@ -83,6 +96,16 @@ describe Connfu::ConnfuMessageFormatter do
83
96
  message.should be_instance_of(Array)
84
97
  message.length.should be(0)
85
98
  end
99
+
100
+ it "should discard an event because the source is unknown" do
101
+ raw = {"id"=>"http://identi.ca/bookmark/2eaba5c4-6377-4b59-8281-df8963c5ae25", "occurred_at"=> "2011-09-27 18:37:01 UTC", "actor"=>{"object_type"=>"person", "id"=>"http://identi.ca/user/530127", "display_name"=>"popl", "url"=>"http://identi.ca/user/530127"}, "verb"=>"post", "object"=>{"object_type"=>"article", "id"=>"http://identi.ca/bookmark/2eaba5c4-6377-4b59-8281-df8963c5ae25", "display_name"=>"Dobre ofert kredytu na firme pewne kredyty na firme", "summary"=>"Masz firme ?", "published" => "2011-09-27 18:37:01 UTC", "updated"=> "2011-09-27 18:37:01 UTC"}, "title"=>"Dobre ofert kredytu na firme pewne kredyty na firme", "provider"=>{"object_type"=>"service", "id"=>"http://identi.ca/", "display_name"=>"Identi.ca public timeline", "summary"=>"Identi.ca updates from everyone!", "url"=>"tag:identi.ca,2011-09-27:PublicTimeline", "published"=>"2011-09-27 18:39:52 UTC"}, "backchat"=>{"source"=>"unknown", "bare_uri"=>"http://identi.ca/api/statuses/public_timeline.atom", "user_path"=>["http://identi.ca/api/statuses/public_timeline.atom"], "journal"=>["feed-distributor"], "uuid"=>"16acab10-e938-11e0-8d2b-12313b050905", "channels"=>["http://identi.ca/api/statuses/public_timeline.atom"]}}
102
+ message = Connfu::ConnfuMessageFormatter.format_message(raw)
103
+ message.should be_instance_of(Array)
104
+ puts message[0]
105
+ message.length.should be(0)
106
+ end
107
+
108
+
86
109
  end
87
110
 
88
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connfu-client
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-26 00:00:00.000000000Z
13
+ date: 2011-09-29 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2152356700 !ruby/object:Gem::Requirement
17
+ requirement: &2152365500 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.8
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152356700
25
+ version_requirements: *2152365500
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rest-client
28
- requirement: &2152355740 !ruby/object:Gem::Requirement
28
+ requirement: &2152364680 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2152355740
36
+ version_requirements: *2152364680
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2152354460 !ruby/object:Gem::Requirement
39
+ requirement: &2152329680 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2152354460
47
+ version_requirements: *2152329680
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: flog
50
- requirement: &2152352900 !ruby/object:Gem::Requirement
50
+ requirement: &2152328240 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.5.1
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2152352900
58
+ version_requirements: *2152328240
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: flay
61
- requirement: &2152351900 !ruby/object:Gem::Requirement
61
+ requirement: &2152326800 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.4.2
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2152351900
69
+ version_requirements: *2152326800
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: roodi
72
- requirement: &2152351140 !ruby/object:Gem::Requirement
72
+ requirement: &2152325780 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 2.1.0
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2152351140
80
+ version_requirements: *2152325780
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: reek
83
- requirement: &2152350220 !ruby/object:Gem::Requirement
83
+ requirement: &2152324980 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 1.2.8
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2152350220
91
+ version_requirements: *2152324980
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: simplecov
94
- requirement: &2152346700 !ruby/object:Gem::Requirement
94
+ requirement: &2152324080 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 0.4.0
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *2152346700
102
+ version_requirements: *2152324080
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: webmock
105
- requirement: &2152345100 !ruby/object:Gem::Requirement
105
+ requirement: &2152323140 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *2152345100
113
+ version_requirements: *2152323140
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: sdoc
116
- requirement: &2152343320 !ruby/object:Gem::Requirement
116
+ requirement: &2152319380 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *2152343320
124
+ version_requirements: *2152319380
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: metric_fu
127
- requirement: &2152341900 !ruby/object:Gem::Requirement
127
+ requirement: &2152317700 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *2152341900
135
+ version_requirements: *2152317700
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: metrical
138
- requirement: &2152340460 !ruby/object:Gem::Requirement
138
+ requirement: &2152316240 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *2152340460
146
+ version_requirements: *2152316240
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: gli
149
- requirement: &2152338800 !ruby/object:Gem::Requirement
149
+ requirement: &2152314840 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,7 +154,7 @@ dependencies:
154
154
  version: '0'
155
155
  type: :runtime
156
156
  prerelease: false
157
- version_requirements: *2152338800
157
+ version_requirements: *2152314840
158
158
  description: This gem provides a smooth access to connFu capabilities
159
159
  email:
160
160
  - devs@connfu.com
@@ -257,7 +257,7 @@ files:
257
257
  - spec/provisioning/voice_spec.rb
258
258
  - spec/provisioning_spec.rb
259
259
  - spec/spec_helper.rb
260
- homepage: http://www.github.com/O2Labs/connfu-client
260
+ homepage: http://www.github.com/bluevialabs/connfu-client
261
261
  licenses: []
262
262
  post_install_message:
263
263
  rdoc_options: []