connfu-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- == Welcome to connfu-client {<img src="http://travis-ci.org/bluevialabs/connfu-client.png" />}[http://travis-ci.org/bluevialabs/connfu-client]
1
+ == Welcome to connfu-client {<img src="https://secure.travis-ci.org/bluevialabs/connfu-client.png" />}[http://travis-ci.org/bluevialabs/connfu-client]
2
2
 
3
3
  connFu gem provides an easy way to get access to connFu platform using the defined DSL and the provisioning API.
4
4
 
@@ -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 < 4 and
10
+ (
11
+ puts "Please include as argument the api_key, the channel name, the tone and the message to be used"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel_name = ARGV.shift
17
+ tone = ARGV.shift
18
+ message = ARGV.shift
19
+
20
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
21
+
22
+ begin
23
+ puts application.add_dtmf(channel_name, tone, message)
24
+ rescue Exception => ex
25
+ puts "There was an error: #{ex.inspect}"
26
+ puts "Exception message: #{ex.message}"
27
+ end
28
+
@@ -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 < 2 and
10
+ (
11
+ puts "Please include as argument the api_key, the channel and the dtmf (optional) to be deleted"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+ channel = ARGV.shift
17
+ dtmf = 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.delete_dtmf(channel, dtmf)
28
+ rescue Exception => ex
29
+ puts "There was an error:"
30
+ puts "Exception message: #{ex.message}"
31
+ end
32
+
@@ -0,0 +1,38 @@
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, the channel and optionally the dtmf tone"
12
+ exit
13
+ )
14
+
15
+ api_key = ARGV.shift
16
+
17
+ channel = ARGV.shift
18
+
19
+ dtmf = if ARGV.length < 1
20
+ ""
21
+ else
22
+ ARGV.shift
23
+ end
24
+
25
+
26
+ Connfu.log_level = Logger::DEBUG
27
+
28
+ application = Connfu::Provisioning::Application.new(api_key, CONNFU_ENDPOINT)
29
+
30
+
31
+ begin
32
+ phones = application.get_dtmf(channel, dtmf)
33
+ p phones
34
+ rescue Exception => ex
35
+ puts "There was an error:"
36
+ puts "Exception message: #{ex.message}"
37
+ end
38
+
@@ -151,11 +151,12 @@ module Connfu
151
151
  users = params[:origin]
152
152
  end
153
153
 
154
- @base.post("channels/twitter",
154
+ data = @base.post("channels/twitter",
155
155
  {:uid => key,
156
156
  :accounts => users.collect { |item| {:name => item} },
157
157
  :filter => filter
158
158
  })
159
+ Twitter.unmarshal(ActiveSupport::JSON.decode(data))
159
160
  else
160
161
  # retrieve users mentions
161
162
  users = params[:mentions]
@@ -165,11 +166,12 @@ module Connfu
165
166
  user_filter = filter.dup
166
167
  user_filter << "recipients:#{user}"
167
168
 
168
- locations << @base.post("channels/twitter",
169
+ data = @base.post("channels/twitter",
169
170
  {:uid => key,
170
171
  :accounts => [{:name => user}],
171
172
  :filter => "(#{user_filter.join(' AND ')})"
172
173
  })
174
+ locations << Twitter.unmarshal(ActiveSupport::JSON.decode(data))
173
175
  }
174
176
  locations
175
177
  end
@@ -231,7 +233,7 @@ module Connfu
231
233
  # * +country+ country to allocate a DID
232
234
  #
233
235
  def create_voice_channel(name, country, privacy = Voice::Privacy::WHITELIST)
234
- @base.post("channels/voice", {:uid => name, :country => country, :privacy => privacy})
236
+ Voice.unmarshal(ActiveSupport::JSON.decode(@base.post("channels/voice", {:uid => name, :country => country, :privacy => privacy})))
235
237
  end
236
238
 
237
239
  ##
@@ -272,6 +274,32 @@ module Connfu
272
274
  @base.post("channels/voice/#{voice}/phones", {:country => country})
273
275
  end
274
276
 
277
+ ##
278
+ # Retrieve a voice channel dtmf tones, that's the list of actions associated to a IVR voice channel
279
+ # ==== Parameters
280
+ # * +voice+ Voice channel identifier
281
+ # * +dtmf+ (optional) specific Dtmf tone to retrieve. If it is not specified, all the list is fetched
282
+ def get_dtmf(voice, dtmf = "")
283
+ Dtmf.unmarshal(voice, ActiveSupport::JSON.decode(@base.get("channels/voice/#{voice}/dtmf/#{dtmf}")))
284
+ end
285
+
286
+ ##
287
+ # Delete one dtmf action or the whole dtmf actions
288
+ # ==== Parameters
289
+ # * +voice+: Voice channel identifier
290
+ # * +dtmf+: specific dtmf tone to delete.
291
+ def delete_dtmf(voice, dtmf)
292
+ @base.delete("channels/voice/#{voice}/dtmf/#{dtmf}")
293
+ end
294
+
295
+ ##
296
+ # Add a new dtmf action to the Voice channel
297
+ # ==== Parameters
298
+ # * +voice+: Voice channel identifier
299
+ # * +dtmf+: for the phone number to be allocated
300
+ def add_dtmf(voice, tone, message)
301
+ @base.post("channels/voice/#{voice}/dtmf", {:tone => tone, :message => message})
302
+ end
275
303
 
276
304
  ##
277
305
  # Voice channel Whitelist management
@@ -296,22 +324,25 @@ module Connfu
296
324
  @base.delete("channels/voice/#{voice}/whitelisted/#{number}")
297
325
  end
298
326
 
299
- #
327
+ ##
300
328
  # Create a new item in the whitelist
301
- # @param *args:
329
+ # ===== Parameters
330
+ # * *args:
302
331
  # - First parameter: voice channel identifier
303
332
  # - Second parameter can be either:
304
333
  # - WhitelistUser object with the name and phone information
305
334
  # - two arguments name, phone
306
335
  #
336
+ # ==== Return
337
+ # * Whitelist object
307
338
  def add_whitelist(*args)
308
-
339
+ voice_id = args[0]
309
340
  if args.length.eql?(2)
310
- @base.post("channels/voice/#{args[0]}/whitelisted", {:name => args[1].name, :phone => args[1].phone})
341
+ whitelist = @base.post("channels/voice/#{voice_id}/whitelisted", {:name => args[1].name, :phone => args[1].phone})
311
342
  else
312
- @base.post("channels/voice/#{args[0]}/whitelisted", {:name => args[1], :phone => args[2]})
343
+ whitelist = @base.post("channels/voice/#{voice_id}/whitelisted", {:name => args[1], :phone => args[2]})
313
344
  end
314
-
345
+ WhitelistUser.unmarshal(ActiveSupport::JSON.decode(whitelist))
315
346
  end
316
347
 
317
348
  #
@@ -348,7 +379,9 @@ module Connfu
348
379
  # @param uri RSS endpoint
349
380
  #
350
381
  def create_rss_channel(name, uri)
351
- @base.post("channels/rss", {:uid => name, :uri => uri})
382
+ data = @base.post("channels/rss", {:uid => name, :uri => uri})
383
+ data = ActiveSupport::JSON.decode(data)
384
+ Rss.unmarshal(data)
352
385
  end
353
386
 
354
387
  #
@@ -41,10 +41,6 @@ module Connfu
41
41
  RestClient.post("#{@endpoint}/#{path}", ActiveSupport::JSON.encode(body), headers) { |response, request, result|
42
42
  case response.code
43
43
  when 200..201
44
- # If there is a :location header, return it
45
- if response.headers.has_key?(:location)
46
- return response.headers[:location]
47
- end
48
44
  # else, do the normal stuff
49
45
  if block_given?
50
46
  response.return!(request, result, &Proc.new)
@@ -17,12 +17,12 @@ module Connfu
17
17
  attr_accessor :uid
18
18
 
19
19
  # channel type
20
- attr_accessor :type
20
+ attr_accessor :channel_type
21
21
 
22
22
  # Creates a Channel instance using a Hash values
23
23
  # It creates an instance variable per each hash key
24
24
  def initialize(params)
25
- self.type = self.class.to_s.downcase
25
+ self.channel_type = self.class.to_s.downcase
26
26
  params.each_pair { |key, value|
27
27
  self.instance_variable_set("@#{key}", value)
28
28
  }
@@ -52,14 +52,13 @@ module Connfu
52
52
  #
53
53
  # * +data+ - hash containing channel information retrieved using the connFu API
54
54
  def unmarshal(data)
55
-
56
- # Helper to get the channel class using the type attribute (we are
55
+ # Helper to get the channel class using the channel_type attribute (we are
57
56
  # retrieving all the channels) or the client class (we are retrieving
58
57
  # specific a channel type)
59
58
  create_channel = lambda { |channel|
60
- if channel.has_key?("type") # get the class from type attribute (get all channels)
61
- type = channel["type"].capitalize
62
- Connfu::Provisioning.const_get(type).new(channel)
59
+ if channel.has_key?("type") && ListenerChannel::CHANNEL_TYPES.include?(channel["type"].to_sym) # get the class from type attribute (get all channels)
60
+ channel_type = channel["type"].capitalize
61
+ Connfu::Provisioning.const_get(channel_type).new(channel)
63
62
  else # get the class from class
64
63
  self.new(channel)
65
64
  end
@@ -0,0 +1,55 @@
1
+ module Connfu
2
+
3
+ module Provisioning
4
+
5
+ #
6
+ # connFu Dtmf press key (belongs to a Voice channel)
7
+ #
8
+ class Dtmf
9
+
10
+ # tone
11
+ attr_accessor :tone
12
+
13
+ # message
14
+ attr_accessor :message
15
+
16
+ # voice channel unique identifier
17
+ attr_reader :voice
18
+
19
+ # @param voice voice channel identifier
20
+ # @param tone
21
+ # @param message
22
+ def initialize(voice, tone, message = "")
23
+ @voice = voice
24
+ @tone = tone
25
+ @message = message
26
+ end
27
+
28
+ # Hash way to retrieve attributes
29
+ def [](value)
30
+ self.respond_to?(value.to_sym) ? self.send(value.to_sym) : nil
31
+ end
32
+
33
+ def to_hash
34
+ {"tone" => tone, "message" => message}
35
+ end
36
+
37
+ def to_s
38
+ "#{self.class.to_s}: #{to_hash}"
39
+ end
40
+
41
+ #
42
+ # Creates a Dtmf object using the raw data from the provisioning API
43
+ # @param voice channel unique identifier
44
+ # @param data Hash containing the raw data
45
+ def self.unmarshal(voice, data)
46
+ if data.is_a?(Array)
47
+ data.map{|item| Dtmf.new(voice, item["tone"], item["message"])}
48
+ else
49
+ Dtmf.new(voice, data["tone"], data["message"])
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -9,11 +9,11 @@ module Connfu
9
9
 
10
10
  def initialize(params)
11
11
  super(params)
12
- self.type = "rss"
12
+ self.channel_type = "rss"
13
13
  end
14
14
 
15
15
  def to_hash
16
- {"uid" => uid, "type" => type, "uri" => uri}
16
+ {"uid" => uid, "channel_type" => channel_type, "uri" => uri}
17
17
  end
18
18
 
19
19
  end
@@ -15,12 +15,12 @@ module Connfu
15
15
 
16
16
  def initialize(params)
17
17
  super(params)
18
- self.type = "twitter"
18
+ self.channel_type = "twitter"
19
19
  end
20
20
 
21
21
  # Creates a hash with the Twitter instance info
22
22
  def to_hash
23
- {"uid" => uid, "type" => type, "accounts" => accounts, "filter" => filter}
23
+ {"uid" => uid, "channel_type" => channel_type, "accounts" => accounts, "filter" => filter}
24
24
  end
25
25
 
26
26
  end
@@ -1,4 +1,3 @@
1
- require 'connfu/provisioning/whitelist'
2
1
 
3
2
  module Connfu
4
3
 
@@ -15,7 +14,7 @@ module Connfu
15
14
  end
16
15
 
17
16
  # Voice channel attributes that could be updated
18
- UPDATE_ATTRIBUTES = ["topic", "welcome_message", "rejected_message", "privacy"]
17
+ UPDATE_ATTRIBUTES = ["topic", "welcome_message", "rejected_message", "privacy", "type"]
19
18
 
20
19
  _values = UPDATE_ATTRIBUTES.dup
21
20
  _values.each { |value|
@@ -39,11 +38,11 @@ module Connfu
39
38
 
40
39
  def initialize(params)
41
40
  super(params)
42
- self.type = "voice"
41
+ self.channel_type = "voice"
43
42
  end
44
43
 
45
44
  def to_hash
46
- {"uid" => uid, "type" => type, "phones" => phones.map(&:to_hash)}
45
+ {"uid" => uid, "channel_type" => channel_type, "phones" => phones.map(&:to_hash)}
47
46
  end
48
47
 
49
48
  # access the Voice channel Whitelist
@@ -2,10 +2,6 @@ module Connfu
2
2
 
3
3
  module Provisioning
4
4
 
5
- ##
6
- # This class defines a whitelist user (whitelist item)
7
- WhitelistUser = Struct.new(:name, :phone)
8
-
9
5
  ##
10
6
  # This class models a conference whitelist
11
7
  class Whitelist
@@ -0,0 +1,18 @@
1
+ module Connfu
2
+ module Provisioning
3
+ ##
4
+ # This class defines a whitelist user (whitelist item)
5
+ class WhitelistUser < Struct.new(:name, :phone)
6
+
7
+ ##
8
+ # Creates a WhitelistUser object using the raw data from the provisioning API
9
+ # ==== Parameters
10
+ # * +data+ raw data retrieved using the connFu API
11
+ def self.unmarshal(data)
12
+ WhitelistUser.new(*data.values)
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -1,10 +1,13 @@
1
1
  require 'connfu/provisioning/application'
2
2
  require 'connfu/provisioning/base'
3
3
  require 'connfu/provisioning/channel'
4
+ require 'connfu/provisioning/dtmf'
4
5
  require 'connfu/provisioning/phone'
5
6
  require 'connfu/provisioning/rss'
6
7
  require 'connfu/provisioning/twitter'
7
8
  require 'connfu/provisioning/voice'
9
+ require 'connfu/provisioning/whitelist'
10
+ require 'connfu/provisioning/whitelist_user'
8
11
 
9
12
  module Connfu
10
13
  module Provisioning
@@ -2,5 +2,5 @@
2
2
  module Connfu
3
3
  ##
4
4
  # Current connFu DSL version
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
@@ -12,7 +12,7 @@ def channel_attrs
12
12
  end
13
13
 
14
14
 
15
- shared_examples_for "Channel" do |channel, type|
15
+ shared_examples_for "Channel" do |channel, channel_type|
16
16
 
17
17
 
18
18
  RSpec::Matchers.define :have_defined_channel_attributes do |expected|
@@ -20,7 +20,7 @@ shared_examples_for "Channel" do |channel, type|
20
20
  channel_attrs.keys.each { |attribute|
21
21
  channel.send(attribute).should eql(expected[attribute])
22
22
  }
23
- channel.type.should be_instance_of(String)
23
+ channel.channel_type.should be_instance_of(String)
24
24
  channel.uid.should be_instance_of(String)
25
25
  end
26
26
  end
@@ -26,7 +26,7 @@ describe Connfu::Provisioning::Voice do
26
26
  [:uid, :topic, :welcome_message, :rejected_message].each { |attribute|
27
27
  voice.send(attribute).should eql(expected[attribute])
28
28
  }
29
- voice.type.should eql("voice")
29
+ voice.channel_type.should eql("voice")
30
30
  end
31
31
  end
32
32
 
@@ -82,12 +82,12 @@ describe Connfu::Provisioning::Voice do
82
82
  match do |actual| # actual should be the Connfu::Provisioning::Voice instance
83
83
  actual.should be_instance_of(Hash)
84
84
 
85
- ["uid", "type", "phones"].each{|key|
85
+ ["uid", "channel_type", "phones"].each{|key|
86
86
  actual.should have_key(key)
87
87
  }
88
88
 
89
89
  actual["uid"].should eql(uid)
90
- actual["type"].should eql("voice")
90
+ actual["channel_type"].should eql("voice")
91
91
 
92
92
  actual["phones"].should be_instance_of(Array)
93
93
  actual["phones"].length.should eql(phones.length)
@@ -103,25 +103,25 @@ describe Connfu::Provisioning::Voice do
103
103
  end
104
104
  end
105
105
 
106
- it "should retrieved uid, type and phones attributes (empty phones)" do
106
+ it "should retrieved uid, channel_type and phones attributes (empty phones)" do
107
107
  voice = Connfu::Provisioning::Voice.new(voice_attrs)
108
108
  voice.to_hash.should have_voice_details(VOICE_KEY, [])
109
109
  end
110
110
 
111
- it "should retrieved uid, type and phones attributes (phones with elements)" do
111
+ it "should retrieved uid, channel_type and phones attributes (phones with elements)" do
112
112
  voice = Connfu::Provisioning::Voice.new(voice_attrs)
113
113
  voice << phone
114
114
  voice.to_hash.should have_voice_details(VOICE_KEY, [phone])
115
115
  end
116
116
 
117
- it "should retrieved uid, type and phones attributes (phones two elements)" do
117
+ it "should retrieved uid, channel_type and phones attributes (phones two elements)" do
118
118
  voice = Connfu::Provisioning::Voice.new(voice_attrs)
119
119
  voice << phone
120
120
  voice << phone
121
121
  voice.to_hash.should have_voice_details(VOICE_KEY, [phone, phone])
122
122
  end
123
123
 
124
- it "should retrieved uid, type and phones attributes (phones hundred elements)" do
124
+ it "should retrieved uid, channel_type and phones attributes (phones hundred elements)" do
125
125
  voice = Connfu::Provisioning::Voice.new(voice_attrs)
126
126
  data = []
127
127
  100.times do
@@ -18,11 +18,11 @@ describe Connfu::Provisioning do
18
18
  RSpec::Matchers.define :be_well_defined_as_voice do |uid, phones|
19
19
  match do |actual| # actual should be the Connfu::Provisioning::Voice instance
20
20
  actual.should be_instance_of(Connfu::Provisioning::Voice)
21
- ["uid", "type", "phones"].each { |key|
21
+ ["uid", "channel_type", "phones"].each { |key|
22
22
  actual.to_hash.should have_key(key)
23
23
  }
24
24
  actual.uid.should eql(uid)
25
- actual.type.should eql("voice")
25
+ actual.channel_type.should eql("voice")
26
26
 
27
27
  actual.should respond_to("topic")
28
28
  actual.should respond_to("welcome_message")
@@ -46,12 +46,12 @@ describe Connfu::Provisioning do
46
46
  RSpec::Matchers.define :be_well_defined_as_twitter do |uid, twitter_accounts|
47
47
  match do |actual| # actual should be the Connfu::Provisioning::Twitter instance
48
48
  actual.should be_instance_of(Connfu::Provisioning::Twitter)
49
- ["uid", "type", "accounts"].each { |key|
49
+ ["uid", "channel_type", "accounts"].each { |key|
50
50
  actual.to_hash.should have_key(key)
51
51
  }
52
52
 
53
53
  actual.uid.should eql(uid)
54
- actual.type.should eql("twitter")
54
+ actual.channel_type.should eql("twitter")
55
55
 
56
56
  actual.accounts.should be_instance_of(Array)
57
57
  actual.accounts.length.should eql(twitter_accounts.length)
@@ -85,56 +85,57 @@ describe Connfu::Provisioning do
85
85
  it "should create a Twitter channel application with one origin speficied as array" do
86
86
  stub_request(:post, "#{ENDPOINT}/channels/twitter").
87
87
  with(:body => create_twitter_channel_request(["juan"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
88
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
88
+ to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
89
89
 
90
90
  response = @application.create_twitter_channel(TWITTER_KEY, ["juan"])
91
- response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}")
91
+ response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan'])
92
92
  end
93
93
 
94
94
  it "should create a Twitter channel application with one origins speficied as hash (string)" do
95
95
  stub_request(:post, "#{ENDPOINT}/channels/twitter").
96
96
  with(:body => create_twitter_channel_request(["juan"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
97
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
97
+ to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
98
98
 
99
99
  response = @application.create_twitter_channel(TWITTER_KEY, {:origin => "juan"})
100
- response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}")
100
+ response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan'])
101
101
  end
102
102
 
103
103
  it "should create a Twitter channel application with one origins speficied as hash (array)" do
104
104
  stub_request(:post, "#{ENDPOINT}/channels/twitter").
105
105
  with(:body => create_twitter_channel_request(["juan"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
106
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
106
+ to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
107
107
 
108
108
  response = @application.create_twitter_channel(TWITTER_KEY, {:origin => ["juan"]})
109
- response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}")
109
+ response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan'])
110
110
  end
111
111
 
112
112
  it "should create a Twitter channel application with two origins speficied as Hash" do
113
113
  stub_request(:post, "#{ENDPOINT}/channels/twitter").
114
114
  with(:body => create_twitter_channel_request(["juan", "connfu"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
115
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
115
+ to_return(:status => 201, :body => "{'accounts':[{'name':'juan'},{'name':'connfu'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
116
116
 
117
117
  response = @application.create_twitter_channel(TWITTER_KEY, {:origin => ["juan", "connfu"]})
118
- response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}")
118
+ response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan', 'connfu'])
119
119
  end
120
120
 
121
121
  it "should create a Twitter channel application with two origins speficied as Array" do
122
122
  stub_request(:post, "#{ENDPOINT}/channels/twitter").
123
123
  with(:body => create_twitter_channel_request(["juan", "connfu"]), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
124
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
124
+ to_return(:status => 201, :body => "{'accounts':[{'name':'juan'},{'name':'connfu'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
125
125
 
126
126
  response = @application.create_twitter_channel(TWITTER_KEY, ["juan", "connfu"])
127
- response.should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}")
127
+ response.should be_well_defined_as_twitter(TWITTER_KEY, ['juan', 'connfu'])
128
128
  end
129
129
 
130
130
  it "should create a Twitter channel application with one mention" do
131
131
  stub_request(:post, "#{ENDPOINT}/channels/twitter").
132
132
  with(:body => create_twitter_channel_request(["juan"], TWITTER_KEY, "(recipients:juan)"), :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
133
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
133
+ to_return(:status => 201, :body => "{'accounts':[{'name':'juan'}],'created_at':'2011-09-06T05:33:39+00:00','filter':'','uid':'#{TWITTER_KEY}','updated_at':'2011-09-06T05:33:39+00:00'}", :headers => {:location => "#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}"})
134
134
 
135
135
  response = @application.create_twitter_channel(TWITTER_KEY, {:mentions => ["juan"]})
136
- response.should be_kind_of(Array)
137
- response[0].should eql("#{ENDPOINT}/channels/twitter/#{TWITTER_KEY}")
136
+ response.should be_instance_of(Array)
137
+ response.length.should be(1)
138
+ response[0].should be_well_defined_as_twitter(TWITTER_KEY, ["juan"])
138
139
  end
139
140
 
140
141
  it "should retrieve a channel information when the channel exists" do
@@ -180,29 +181,32 @@ describe Connfu::Provisioning do
180
181
 
181
182
  it "should create a Voice channel application with the default privacy attribute" do
182
183
  stub_request(:post, "#{ENDPOINT}/channels/voice").
183
- with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"de\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
184
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"})
184
+ with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"#{COUNTRY}\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
185
+ to_return(:status => 201, :body => "{'created_at':'2011-08-25T14:16:44+03:00','rejected_message':'You are not allowed to join this conference','privacy':'whitelisted','topic':'hello_man','uid':'#{VOICE_KEY}','updated_at':'2011-08-25T15:10:12+03:00','welcome_message':'Welcome to connFu, you are going to join the conference','phones':[{'country':'#{COUNTRY}','phone_number':'#{PHONE_NUMBER}'}]}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"})
185
186
 
186
- response = @application.create_voice_channel(VOICE_KEY, "de")
187
- response.should eql("#{ENDPOINT}/channels/voice/#{VOICE_KEY}")
187
+ response = @application.create_voice_channel(VOICE_KEY, COUNTRY)
188
+ response.should be_well_defined_as_voice(VOICE_KEY, [{:phone_number => PHONE_NUMBER, :country => COUNTRY}])
189
+ response.privacy.should eql("whitelisted")
188
190
  end
189
191
 
190
192
  it "should create a Voice channel application with a privacy attribute (public)" do
191
193
  stub_request(:post, "#{ENDPOINT}/channels/voice").
192
- with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"de\",\"privacy\":\"public\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
193
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"})
194
+ with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"#{COUNTRY}\",\"privacy\":\"public\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
195
+ to_return(:status => 201, :body => "{'created_at':'2011-08-25T14:16:44+03:00','rejected_message':'You are not allowed to join this conference','privacy':'public','topic':'hello_man','uid':'#{VOICE_KEY}','updated_at':'2011-08-25T15:10:12+03:00','welcome_message':'Welcome to connFu, you are going to join the conference','phones':[{'country':'#{COUNTRY}','phone_number':'#{PHONE_NUMBER}'}]}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"})
194
196
 
195
- response = @application.create_voice_channel(VOICE_KEY, "de", Connfu::Provisioning::Voice::Privacy::PUBLIC)
196
- response.should eql("#{ENDPOINT}/channels/voice/#{VOICE_KEY}")
197
+ response = @application.create_voice_channel(VOICE_KEY, COUNTRY, Connfu::Provisioning::Voice::Privacy::PUBLIC)
198
+ response.should be_well_defined_as_voice(VOICE_KEY, [{:phone_number => PHONE_NUMBER, :country => COUNTRY}])
199
+ response.privacy.should eql("public")
197
200
  end
198
201
 
199
202
  it "should create a Voice channel application with a privacy attribute (whitelisted)" do
200
203
  stub_request(:post, "#{ENDPOINT}/channels/voice").
201
- with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"de\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
202
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"})
204
+ with(:body => "{\"uid\":\"#{VOICE_KEY}\",\"country\":\"#{COUNTRY}\",\"privacy\":\"whitelisted\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
205
+ to_return(:status => 201, :body => "{'created_at':'2011-08-25T14:16:44+03:00','rejected_message':'You are not allowed to join this conference','privacy':'whitelisted','topic':'hello_man','uid':'#{VOICE_KEY}','updated_at':'2011-08-25T15:10:12+03:00','welcome_message':'Welcome to connFu, you are going to join the conference','phones':[{'country':'#{COUNTRY}','phone_number':'#{PHONE_NUMBER}'}]}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}"})
203
206
 
204
- response = @application.create_voice_channel(VOICE_KEY, "de", Connfu::Provisioning::Voice::Privacy::WHITELIST)
205
- response.should eql("#{ENDPOINT}/channels/voice/#{VOICE_KEY}")
207
+ response = @application.create_voice_channel(VOICE_KEY, COUNTRY, Connfu::Provisioning::Voice::Privacy::WHITELIST)
208
+ response.should be_well_defined_as_voice(VOICE_KEY, [{:phone_number => PHONE_NUMBER, :country => COUNTRY}])
209
+ response.privacy.should eql("whitelisted")
206
210
  end
207
211
 
208
212
  it "should retrieve a channel information when the channel exists" do
@@ -419,22 +423,24 @@ describe Connfu::Provisioning do
419
423
 
420
424
  stub_request(:post, "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted").
421
425
  with(:body => "{\"name\":\"juan\",\"phone\":\"#{PHONE_NUMBER}\"}", :headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
422
- to_return(:status => 200, :body => "", :headers => {})
426
+ to_return(:status => 200, :body => "{\"name\":\"juan\",\"phone\":\"#{PHONE_NUMBER}\"}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted/#{PHONE_NUMBER}"})
423
427
 
424
428
  response = @application.add_whitelist(VOICE_KEY, 'juan', PHONE_NUMBER)
425
- response.should eql("")
426
-
429
+ response.should be_instance_of(Connfu::Provisioning::WhitelistUser)
430
+ response.name.should eql("juan")
431
+ response.phone.should eql(PHONE_NUMBER)
427
432
  end
428
433
 
429
434
  it "should create a whitelist number with 1 parameter (WhitelistUser)" do
430
435
 
431
436
  stub_request(:post, "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted").
432
437
  with(:body => "{\"name\":\"juan\",\"phone\":\"#{PHONE_NUMBER}\"}", :headers => {'Accept'=>'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
433
- to_return(:status => 200, :body => "", :headers => {})
438
+ to_return(:status => 200, :body => "{'name':'juan','phone':'#{PHONE_NUMBER}'}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{VOICE_KEY}/whitelisted/#{PHONE_NUMBER}"})
434
439
 
435
440
  response = @application.add_whitelist(VOICE_KEY, Connfu::Provisioning::WhitelistUser.new('juan', PHONE_NUMBER))
436
- response.should eql("")
437
-
441
+ response.should be_instance_of(Connfu::Provisioning::WhitelistUser)
442
+ response.name.should eql("juan")
443
+ response.phone.should eql(PHONE_NUMBER)
438
444
  end
439
445
 
440
446
  it "should update a whitelist number with 1 parameter (WhitelistUser)" do
@@ -454,10 +460,11 @@ describe Connfu::Provisioning do
454
460
  it "should create a RSS channel application" do
455
461
  stub_request(:post, "#{ENDPOINT}/channels/rss").
456
462
  with(:body => "{\"uid\":\"#{RSS_KEY}\",\"uri\":\"http://connfu.com/rss\"}", :headers => {'Accept'=>'application/json', 'Content-Type' => 'application/json', 'AUTH_TOKEN' => "#{API_KEY}"}).
457
- to_return(:status => 201, :body => "", :headers => {:location => "#{ENDPOINT}/channels/voice/#{RSS_KEY}"})
463
+ to_return(:status => 201, :body => "{'created_at':'2011-07-17T20:57:01+03:00','uri':'http://connfu.com/rss','uid':#{RSS_KEY},'updated_at':'2011-07-17T20:57:01+03:00'}", :headers => {:location => "#{ENDPOINT}/channels/voice/#{RSS_KEY}"})
458
464
 
459
- response = @application.create_rss_channel(RSS_KEY, "http://connfu.com/rss")
460
- response.should eql("#{ENDPOINT}/channels/voice/#{RSS_KEY}")
465
+ rss = @application.create_rss_channel(RSS_KEY, "http://connfu.com/rss")
466
+ rss.uid.should eql(RSS_KEY)
467
+ rss.uri.should eql("http://connfu.com/rss")
461
468
  end
462
469
 
463
470
  it "should retrieve a RSS channel information when the channel exists" do
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.2
4
+ version: 0.1.3
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-30 00:00:00.000000000Z
13
+ date: 2011-10-01 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2152345960 !ruby/object:Gem::Requirement
17
+ requirement: &2152266480 !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: *2152345960
25
+ version_requirements: *2152266480
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rest-client
28
- requirement: &2152344940 !ruby/object:Gem::Requirement
28
+ requirement: &2152265500 !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: *2152344940
36
+ version_requirements: *2152265500
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2152343700 !ruby/object:Gem::Requirement
39
+ requirement: &2152257780 !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: *2152343700
47
+ version_requirements: *2152257780
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: flog
50
- requirement: &2152342580 !ruby/object:Gem::Requirement
50
+ requirement: &2152256520 !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: *2152342580
58
+ version_requirements: *2152256520
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: flay
61
- requirement: &2152341620 !ruby/object:Gem::Requirement
61
+ requirement: &2152254840 !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: *2152341620
69
+ version_requirements: *2152254840
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: roodi
72
- requirement: &2152340500 !ruby/object:Gem::Requirement
72
+ requirement: &2152253620 !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: *2152340500
80
+ version_requirements: *2152253620
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: reek
83
- requirement: &2152336640 !ruby/object:Gem::Requirement
83
+ requirement: &2152252180 !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: *2152336640
91
+ version_requirements: *2152252180
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: simplecov
94
- requirement: &2152335400 !ruby/object:Gem::Requirement
94
+ requirement: &2152251040 !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: *2152335400
102
+ version_requirements: *2152251040
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: webmock
105
- requirement: &2152334360 !ruby/object:Gem::Requirement
105
+ requirement: &2152246400 !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: *2152334360
113
+ version_requirements: *2152246400
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: sdoc
116
- requirement: &2152332840 !ruby/object:Gem::Requirement
116
+ requirement: &2152245100 !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: *2152332840
124
+ version_requirements: *2152245100
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: metric_fu
127
- requirement: &2152331340 !ruby/object:Gem::Requirement
127
+ requirement: &2152243580 !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: *2152331340
135
+ version_requirements: *2152243580
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: metrical
138
- requirement: &2152329160 !ruby/object:Gem::Requirement
138
+ requirement: &2152241660 !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: *2152329160
146
+ version_requirements: *2152241660
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: rake
149
- requirement: &2152326400 !ruby/object:Gem::Requirement
149
+ requirement: &2152240520 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ! '>='
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: '0'
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *2152326400
157
+ version_requirements: *2152240520
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: gli
160
- requirement: &2152325260 !ruby/object:Gem::Requirement
160
+ requirement: &2152238980 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ! '>='
@@ -165,7 +165,7 @@ dependencies:
165
165
  version: '0'
166
166
  type: :runtime
167
167
  prerelease: false
168
- version_requirements: *2152325260
168
+ version_requirements: *2152238980
169
169
  description: This gem provides a smooth access to connFu capabilities
170
170
  email:
171
171
  - devs@connfu.com
@@ -204,6 +204,9 @@ files:
204
204
  - examples/provisioning/twitter/put.rb
205
205
  - examples/provisioning/voice/create.rb
206
206
  - examples/provisioning/voice/delete.rb
207
+ - examples/provisioning/voice/dtmf/create.rb
208
+ - examples/provisioning/voice/dtmf/delete.rb
209
+ - examples/provisioning/voice/dtmf/get.rb
207
210
  - examples/provisioning/voice/get.rb
208
211
  - examples/provisioning/voice/phones/create.rb
209
212
  - examples/provisioning/voice/phones/delete.rb
@@ -228,11 +231,13 @@ files:
228
231
  - lib/connfu/provisioning/application.rb
229
232
  - lib/connfu/provisioning/base.rb
230
233
  - lib/connfu/provisioning/channel.rb
234
+ - lib/connfu/provisioning/dtmf.rb
231
235
  - lib/connfu/provisioning/phone.rb
232
236
  - lib/connfu/provisioning/rss.rb
233
237
  - lib/connfu/provisioning/twitter.rb
234
238
  - lib/connfu/provisioning/voice.rb
235
239
  - lib/connfu/provisioning/whitelist.rb
240
+ - lib/connfu/provisioning/whitelist_user.rb
236
241
  - lib/connfu/version.rb
237
242
  - lib/rdoc/generator/template/connfu/_context.rhtml
238
243
  - lib/rdoc/generator/template/connfu/_head.rhtml