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.
Files changed (94) hide show
  1. data/.rspec +3 -0
  2. data/.rvmrc +2 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +120 -0
  5. data/LICENSE.txt +661 -0
  6. data/README.rdoc +398 -0
  7. data/Rakefile +38 -0
  8. data/bin/.DS_Store +0 -0
  9. data/bin/connfu-client +94 -0
  10. data/connfu-client.gemspec +41 -0
  11. data/examples/conference/application.rb +68 -0
  12. data/examples/conference/conference.rb +33 -0
  13. data/examples/conference/conference_app.rb +25 -0
  14. data/examples/conference/connfu.log +5 -0
  15. data/examples/conference/wall.rb +11 -0
  16. data/examples/provisioning/app/get.rb +29 -0
  17. data/examples/provisioning/channels/get.rb +34 -0
  18. data/examples/provisioning/rss/create.rb +28 -0
  19. data/examples/provisioning/rss/delete.rb +27 -0
  20. data/examples/provisioning/rss/get.rb +32 -0
  21. data/examples/provisioning/rss/put.rb +29 -0
  22. data/examples/provisioning/setup.rb +2 -0
  23. data/examples/provisioning/twitter/create.rb +31 -0
  24. data/examples/provisioning/twitter/delete.rb +27 -0
  25. data/examples/provisioning/twitter/get.rb +32 -0
  26. data/examples/provisioning/twitter/put.rb +29 -0
  27. data/examples/provisioning/voice/create.rb +26 -0
  28. data/examples/provisioning/voice/delete.rb +27 -0
  29. data/examples/provisioning/voice/get.rb +36 -0
  30. data/examples/provisioning/voice/phones/create.rb +26 -0
  31. data/examples/provisioning/voice/phones/delete.rb +28 -0
  32. data/examples/provisioning/voice/phones/get.rb +38 -0
  33. data/examples/provisioning/voice/put.rb +38 -0
  34. data/examples/provisioning/voice/whitelist/create.rb +26 -0
  35. data/examples/provisioning/voice/whitelist/delete.rb +27 -0
  36. data/examples/provisioning/voice/whitelist/get.rb +36 -0
  37. data/examples/provisioning/voice/whitelist/put.rb +27 -0
  38. data/lib/connfu.rb +134 -0
  39. data/lib/connfu/cli/generator.rb +71 -0
  40. data/lib/connfu/connfu_logger.rb +88 -0
  41. data/lib/connfu/connfu_message_formatter.rb +134 -0
  42. data/lib/connfu/connfu_stream.rb +182 -0
  43. data/lib/connfu/dispatcher.rb +164 -0
  44. data/lib/connfu/dsl.rb +84 -0
  45. data/lib/connfu/events.rb +32 -0
  46. data/lib/connfu/listener.rb +85 -0
  47. data/lib/connfu/listener_channel.rb +100 -0
  48. data/lib/connfu/message.rb +74 -0
  49. data/lib/connfu/provisioning.rb +12 -0
  50. data/lib/connfu/provisioning/application.rb +374 -0
  51. data/lib/connfu/provisioning/base.rb +95 -0
  52. data/lib/connfu/provisioning/channel.rb +79 -0
  53. data/lib/connfu/provisioning/phone.rb +55 -0
  54. data/lib/connfu/provisioning/rss.rb +21 -0
  55. data/lib/connfu/provisioning/twitter.rb +28 -0
  56. data/lib/connfu/provisioning/voice.rb +89 -0
  57. data/lib/connfu/provisioning/whitelist.rb +62 -0
  58. data/lib/connfu/version.rb +6 -0
  59. data/lib/rdoc/generator/template/connfu/_context.rhtml +209 -0
  60. data/lib/rdoc/generator/template/connfu/_head.rhtml +7 -0
  61. data/lib/rdoc/generator/template/connfu/class.rhtml +38 -0
  62. data/lib/rdoc/generator/template/connfu/file.rhtml +36 -0
  63. data/lib/rdoc/generator/template/connfu/index.rhtml +13 -0
  64. data/lib/rdoc/generator/template/connfu/resources/apple-touch-icon.png +0 -0
  65. data/lib/rdoc/generator/template/connfu/resources/css/github.css +129 -0
  66. data/lib/rdoc/generator/template/connfu/resources/css/main.css +339 -0
  67. data/lib/rdoc/generator/template/connfu/resources/css/panel.css +389 -0
  68. data/lib/rdoc/generator/template/connfu/resources/css/reset.css +53 -0
  69. data/lib/rdoc/generator/template/connfu/resources/favicon.ico +0 -0
  70. data/lib/rdoc/generator/template/connfu/resources/i/arrows.png +0 -0
  71. data/lib/rdoc/generator/template/connfu/resources/i/results_bg.png +0 -0
  72. data/lib/rdoc/generator/template/connfu/resources/i/tree_bg.png +0 -0
  73. data/lib/rdoc/generator/template/connfu/resources/js/highlight.pack.js +1 -0
  74. data/lib/rdoc/generator/template/connfu/resources/js/jquery-1.3.2.min.js +19 -0
  75. data/lib/rdoc/generator/template/connfu/resources/js/jquery-effect.js +593 -0
  76. data/lib/rdoc/generator/template/connfu/resources/js/main.js +20 -0
  77. data/lib/rdoc/generator/template/connfu/resources/js/searchdoc.js +628 -0
  78. data/lib/rdoc/generator/template/connfu/resources/panel/index.html +72 -0
  79. data/lib/rdoc/generator/template/connfu/se_index.rhtml +8 -0
  80. data/spec/connfu_message_formatter_spec.rb +88 -0
  81. data/spec/connfu_spec.rb +51 -0
  82. data/spec/connfu_stream_spec.rb +84 -0
  83. data/spec/dispatcher_spec.rb +227 -0
  84. data/spec/dsl_spec.rb +159 -0
  85. data/spec/listener_channel_spec.rb +130 -0
  86. data/spec/listener_spec.rb +67 -0
  87. data/spec/provisioning/application_spec.rb +47 -0
  88. data/spec/provisioning/channel_shared_examples.rb +52 -0
  89. data/spec/provisioning/channel_spec.rb +13 -0
  90. data/spec/provisioning/phone_spec.rb +88 -0
  91. data/spec/provisioning/voice_spec.rb +138 -0
  92. data/spec/provisioning_spec.rb +500 -0
  93. data/spec/spec_helper.rb +51 -0
  94. metadata +298 -0
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "connfu/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "connfu-client"
7
+ s.version = Connfu::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["connFu team", "Juan de Bravo"]
10
+ s.email = ["devs@connfu.com", "juandebravo@gmail.com"]
11
+ s.homepage = "http://www.github.com/O2Labs/connfu-client"
12
+ s.summary = %q{connFu DSL to get access to connFu platform}
13
+ s.description = %q{This gem provides a smooth access to connFu capabilities}
14
+
15
+ s.rubyforge_project = "connfu"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency("activesupport", "~>3.0.8")
23
+ s.add_dependency("rest-client")
24
+
25
+ #s.add_runtime_dependency("pry", ">= 0.8.3")
26
+ #s.add_development_dependency("pry-doc")
27
+
28
+ s.add_development_dependency("rspec")
29
+ s.add_development_dependency("flog", "~>2.5.1")
30
+ s.add_development_dependency("flay", "~>1.4.2")
31
+ s.add_development_dependency("roodi", "~>2.1.0")
32
+ s.add_development_dependency("reek", "~>1.2.8")
33
+ s.add_development_dependency('simplecov', '>= 0.4.0')
34
+ s.add_development_dependency("webmock")
35
+ s.add_development_dependency("sdoc")
36
+ s.add_development_dependency("metric_fu")
37
+ s.add_development_dependency("metrical")
38
+
39
+ s.add_dependency("gli")
40
+
41
+ end
@@ -0,0 +1,68 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+ $:.unshift File.join(File.dirname(__FILE__), '.')
3
+
4
+ # needed for 1.8.7, not needed in 1.9.2
5
+ RUBY_VERSION < "1.9.2" and require 'rubygems'
6
+ require 'connfu'
7
+
8
+ require 'conference'
9
+ require 'conference_app'
10
+ require 'wall'
11
+
12
+ #
13
+ # This application is an example of how to create a connFu application
14
+ # You should provide as parameter a valid TOKEN
15
+ #
16
+ # ruby application.rb VALID_TOKEN
17
+ # execute bundle install to download all the required gems
18
+ #
19
+
20
+ token = ARGV.shift
21
+
22
+ Connfu.logger = STDOUT
23
+
24
+ Connfu.log_level = Logger::DEBUG
25
+
26
+ @connfu = Connfu.application(token, "http://localhost:3000/v1") {
27
+
28
+ listen(:voice) do |conference|
29
+ conference.on(:join) do |call|
30
+ puts "New inbound call from #{call[:from]} on number #{call[:to]}"
31
+ conf = ConferenceApp::find_by_conference_number(call[:destination])
32
+ if conf.is_allowed?(call[:from])
33
+ puts "whitelist number received"
34
+ else
35
+ puts "not whitelist number"
36
+ end
37
+ end
38
+
39
+ conference.on(:leave) do |call|
40
+ puts "Attendee left"
41
+ puts "#{call[:from]} has left the conference #{call[:channel_name]}"
42
+ ConferenceApp::find(call[:to]).end(call[:from])
43
+ end
44
+
45
+ conference.on(:new_topic) do |topic|
46
+ puts "New topic in the conference #{topic[:channel_name]}: #{topic[:content]}"
47
+ end
48
+ end
49
+
50
+ listen(:twitter) do |twitter|
51
+
52
+ twitter.filter = "text has #conference"
53
+
54
+ twitter.on(:new) do |tweet|
55
+ puts "#{tweet[:from]} just posted a new tweet with content #{tweet.content} in the conference room: #{tweet[:channel_name]}"
56
+ conf = ConferenceApp::find_by_twitter_user(tweet[:to])
57
+ conf.wall.print("#{tweet[:from]} has tweeted => #{tweet[:content]}")
58
+ end
59
+ end
60
+
61
+ listen(:sms) do |sms|
62
+ sms.on(:new) do |message|
63
+ puts "New inbound sms"
64
+ puts "#{message}"
65
+ end
66
+ end
67
+
68
+ }
@@ -0,0 +1,33 @@
1
+ require 'wall'
2
+
3
+ # This class is a mockup of a conference in the conference rooms application.
4
+ # In real, this should be a Model
5
+ class Conference
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+
13
+ def is_allowed?(number)
14
+ true
15
+ end
16
+
17
+ def start
18
+
19
+ end
20
+
21
+ def end(number)
22
+
23
+ end
24
+
25
+ def to_s
26
+ @name
27
+ end
28
+
29
+ def wall
30
+ @wall ||= Wall.new
31
+ end
32
+
33
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '.')
2
+
3
+ require 'conference'
4
+
5
+ # This class is a mockup of a conference rooms application
6
+ # In real, it should access an external storage system (i.e. database) to retrieve
7
+ # information about Conference objects
8
+ class ConferenceApp
9
+
10
+ class << self
11
+
12
+ def find_by_conference_number(number)
13
+ Conference.new(number)
14
+ end
15
+
16
+ def find_by_twitter_user(username)
17
+ Conference.new(username)
18
+ end
19
+
20
+ def find(number)
21
+ Conference.new(number)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # Logfile created on 2011-08-15 12:32:54 +0300 by logger.rb/25413
2
+ I, [2011-08-15T12:32:54.897949 #90282] INFO -- : Starting application with token APP-TOKEN
3
+ I, [2011-08-15T12:32:54.899240 #90282] INFO -- : Starting application with token APP-TOKEN
4
+ I, [2011-08-15T12:32:54.900251 #90282] INFO -- : Starting application with token APP-TOKEN
5
+ I, [2011-08-15T12:32:54.901422 #90282] INFO -- : Starting application with token APP-TOKEN
@@ -0,0 +1,11 @@
1
+
2
+ # This class is a mockup for a conference wall.
3
+ # This allows conference attendees to tweet messages about the conference
4
+ # that can be shown in a nice UI
5
+ class Wall
6
+
7
+ def print(message)
8
+ puts message
9
+ end
10
+
11
+ end
@@ -0,0 +1,29 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 1 and
10
+ (
11
+ puts "Please include as argument the api_key"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+
17
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
18
+
19
+ begin
20
+
21
+ [:name, :description, :stream_name].each{|var|
22
+ puts "#{var} => #{application.send(var)}"
23
+ }
24
+
25
+ rescue Exception => ex
26
+ puts "There was an error:"
27
+ puts "Exception message: #{ex.message}"
28
+ end
29
+
@@ -0,0 +1,34 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 1 and
10
+ (
11
+ puts "Please include as argument the api_key"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+
17
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
18
+
19
+ begin
20
+ channels = application.get_channels
21
+
22
+ #channels.each{|channel|
23
+ # puts "##########"
24
+ # puts channel.class
25
+ # puts "channel #{channel.uid}"
26
+ # puts channel
27
+ #}
28
+
29
+ puts channels.map { |channel| channel.to_hash }
30
+ rescue Exception => ex
31
+ puts "There was an error:"
32
+ puts "Exception message: #{ex.message}"
33
+ end
34
+
@@ -0,0 +1,28 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 3 and
10
+ (
11
+ puts "Please include as argument the api_key, the channel name to be used and the RSS URL"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel_name = ARGV.shift
17
+ uri = ARGV.shift
18
+
19
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
20
+
21
+
22
+ begin
23
+ puts application.create_rss_channel(channel_name, uri)
24
+ rescue Exception => ex
25
+ puts "There was an error: #{ex.inspect} "
26
+ puts "Exception message: #{ex.message}"
27
+ end
28
+
@@ -0,0 +1,27 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 2 and
10
+ (
11
+ puts "Please include as argument the api_key and channel to be used"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel = ARGV.shift
17
+
18
+
19
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
20
+
21
+ begin
22
+ puts application.delete_rss_channel(channel)
23
+ rescue Exception => ex
24
+ puts "There was an error:"
25
+ puts "Exception message: #{ex.message}"
26
+ end
27
+
@@ -0,0 +1,32 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 1 and
10
+ (
11
+ puts "Please include as argument the api_key"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+
17
+ channel = if ARGV.length < 1
18
+ ""
19
+ else
20
+ ARGV.shift
21
+ end
22
+
23
+
24
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
25
+
26
+ begin
27
+ puts application.get_rss_channel(channel)
28
+ rescue Exception => ex
29
+ puts "There was an error:"
30
+ puts "Exception message: #{ex.message}"
31
+ end
32
+
@@ -0,0 +1,29 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 3 and
10
+ (
11
+ puts "Please include as argument the api_key, the channel and the new RSS URL to be used"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel = ARGV.shift
17
+ uri = ARGV.shift
18
+
19
+
20
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
21
+
22
+ begin
23
+ puts application.update_rss_channel(channel, uri)
24
+
25
+ rescue Exception => ex
26
+ puts "There was an error:"
27
+ puts "Exception message: #{ex.message}"
28
+ end
29
+
@@ -0,0 +1,2 @@
1
+
2
+ CONNFU_ENDPOINT = "http://localhost:3000/v1"
@@ -0,0 +1,31 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 4 and
10
+ (
11
+ puts "Please include as argument the api_key, the channel name to be used, the kind of channel (origin, mentions) and the accounts"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel_name = ARGV.shift
17
+ # should be either origin or mentions
18
+ type = ARGV.shift
19
+ users = ARGV
20
+
21
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
22
+
23
+ hashtags = ["football", "tennis"]
24
+
25
+ begin
26
+ puts application.create_twitter_channel(channel_name, {type.to_sym => users, :hashtags => hashtags})
27
+ rescue Exception => ex
28
+ puts "There was an error: #{ex.inspect} "
29
+ puts "Exception message: #{ex.backtrace}"
30
+ end
31
+
@@ -0,0 +1,27 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
4
+
5
+ require 'connfu'
6
+
7
+ require 'examples/provisioning/setup'
8
+
9
+ ARGV.length < 2 and
10
+ (
11
+ puts "Please include as argument the api_key and channel to be used"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel = ARGV.shift
17
+
18
+
19
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
20
+
21
+ begin
22
+ puts application.delete_twitter_channel(channel)
23
+ rescue Exception => ex
24
+ puts "There was an error:"
25
+ puts "Exception message: #{ex.message}"
26
+ end
27
+