instedd-pigeon 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+
3
+ module Pigeon
4
+ describe Verboice do
5
+ let(:url) { "http://example.com" }
6
+ let(:options) { {:user => "account", :password => "password", :headers => {:content_type => 'application/json'}} }
7
+ let(:api) { Verboice.new url, 'account', 'password', 'default_channel' }
8
+ let(:schedule) { {"name" => "foo", "retries" => "1,2,3", "time_from" => "10:00", "time_to" => "18:30", "project_id" => '2'} }
9
+
10
+ it "calls by channel and address" do
11
+ should_receive_http_get "/api/call?#{api.to_query :channel => 'channel', :address => 'foo'}", '{"call_id": 1, "state": "active"}'
12
+ call = api.call 'foo', :channel => 'channel'
13
+ call['call_id'].should eq(1)
14
+ call['state'].should eq('active')
15
+ end
16
+
17
+ it "calls by address with default channel" do
18
+ should_receive_http_get "/api/call?#{api.to_query :channel => 'default_channel', :address => 'foo'}", '{"call_id": 1, "state": "active"}'
19
+ call = api.call 'foo'
20
+ call['call_id'].should eq(1)
21
+ call['state'].should eq('active')
22
+ end
23
+
24
+ it "calls by address and custom callback address" do
25
+ should_receive_http_get "/api/call?#{api.to_query :channel => 'channel', :address => 'foo', :callback_url => 'http://foo.com'}", '{"call_id": 1, "state": "active"}'
26
+ call = api.call 'foo', :channel => 'channel', :callback_url => 'http://foo.com'
27
+ call['call_id'].should eq(1)
28
+ call['state'].should eq('active')
29
+ end
30
+
31
+ it "calls by address and custom flow" do
32
+ should_receive_http_post "/api/call?#{api.to_query :channel => 'channel', :address => 'foo'}", '<Response/>', '{"call_id": 1, "state": "active"}'
33
+ call = api.call 'foo', :channel => 'channel', :flow => '<Response/>'
34
+ call['call_id'].should eq(1)
35
+ call['state'].should eq('active')
36
+ end
37
+
38
+ it "calls by using a queue" do
39
+ should_receive_http_get "/api/call?#{api.to_query :channel => 'default_channel', :address => 'foo', :queue => 'queue_name'}", '{"call_id": 1, "state": "active"}'
40
+ api.call 'foo', :queue => "queue_name"
41
+ end
42
+
43
+ it "calls using not_before" do
44
+ time = Time.now
45
+ params = api.to_query :channel => 'default_channel', :address => 'foo', :not_before => time.iso8601
46
+ should_receive_http_get "/api/call?#{params}", '{"call_id": 1, "state": "active"}'
47
+ api.call 'foo', :not_before => time
48
+ end
49
+
50
+ it "calls with schedule" do
51
+ should_receive_http_get "/api/call?#{api.to_query :channel => 'default_channel', :address => 'foo', :schedule => 'something'}", '{"call_id": 1, "state": "active"}'
52
+ api.call 'foo', :schedule => "something"
53
+ end
54
+
55
+ it "queries call state by id" do
56
+ should_receive_http_get "/api/calls/1/state", '{"call_id": 1, "state": "active"}'
57
+ call = api.call_state 1
58
+ call['call_id'].should eq(1)
59
+ call['state'].should eq('active')
60
+ end
61
+
62
+ it "gets channel by name" do
63
+ channel = {"name" => "foo", "username" => "bar"}
64
+ channel_json = channel.to_json
65
+
66
+ should_receive_http_get '/api/channels/foo.json', channel_json
67
+
68
+ result = api.channel 'foo'
69
+ result.should eq(channel)
70
+ end
71
+
72
+ it "creates channel" do
73
+ channel = {"name" => "foo", "username" => "bar"}
74
+ channel_json = channel.to_json
75
+ should_receive_http_post '/api/channels.json', channel_json, channel_json
76
+
77
+ result = api.create_channel channel
78
+ result.should eq(channel)
79
+ end
80
+
81
+ it "updates channel" do
82
+ channel = {"name" => "foo", "username" => "bar"}
83
+ channel_json = channel.to_json
84
+ should_receive_http_put '/api/channels/foo.json', channel_json, channel_json
85
+
86
+ result = api.update_channel channel
87
+ result.should eq(channel)
88
+ end
89
+
90
+ it "deletes channel", :focus => true do
91
+ should_receive_http_delete '/api/channels/foo'
92
+
93
+ api.delete_channel 'foo'
94
+ end
95
+
96
+ it "lists call queues" do
97
+ should_receive_http_get '/api/projects/2/schedules.json', '[{"name":"foo"},{"name":"bar"}]'
98
+ schedules = api.schedules 2
99
+ schedules.should have(2).items
100
+ schedules[0]["name"].should eq('foo')
101
+ schedules[1]["name"].should eq('bar')
102
+ end
103
+
104
+ it "gets a call queue by name" do
105
+ should_receive_http_get '/api/projects/2/schedules/foo.json', schedule.to_json
106
+ api.schedule(2, schedule["name"]).should eq(schedule)
107
+ end
108
+
109
+ it "creates a call queue" do
110
+ should_receive_http_post '/api/projects/2/schedules', schedule.to_json, nil
111
+ api.create_schedule 2, schedule
112
+ end
113
+
114
+ it "updates a call queue" do
115
+ should_receive_http_put "/api/projects/2/schedules/schedule_name", schedule.to_json, nil
116
+ api.update_schedule 2, "schedule_name", schedule
117
+ end
118
+
119
+ it "deletes a call queue" do
120
+ should_receive_http_delete "/api/projects/2/schedules/foo"
121
+ api.delete_schedule 2, "foo"
122
+ end
123
+
124
+ it "lists channels" do
125
+ should_receive_http_get '/api/channels.json', '["foo", "bar", "baz"]'
126
+ list = api.list_channels
127
+ list.should == ['foo', 'bar', 'baz']
128
+ end
129
+
130
+ def should_receive_http_get(path, body = nil)
131
+ resource = mock 'resource'
132
+ RestClient::Resource.should_receive(:new).with(url, options).and_return(resource)
133
+
134
+ resource2 = mock 'resource2'
135
+ resource.should_receive(:[]).with(path).and_return(resource2)
136
+
137
+ resource3 = mock 'resource3'
138
+ resource2.should_receive(:get).and_return(resource3)
139
+
140
+ resource3.should_receive(:body).and_return(body) if body
141
+ end
142
+
143
+ def should_receive_http_post(path, data, body)
144
+ resource = mock 'resource'
145
+ RestClient::Resource.should_receive(:new).with(url, options).and_return(resource)
146
+
147
+ resource2 = mock 'resource2'
148
+ resource.should_receive(:[]).with(path).and_return(resource2)
149
+
150
+ resource3 = mock 'resource3'
151
+ resource2.should_receive(:post).with(data).and_return(resource3)
152
+
153
+ resource3.stub(:body) { body }
154
+ end
155
+
156
+ def should_receive_http_put(path, data, body)
157
+ resource = mock 'resource'
158
+ RestClient::Resource.should_receive(:new).with(url, options).and_return(resource)
159
+
160
+ resource2 = mock 'resource2'
161
+ resource.should_receive(:[]).with(path).and_return(resource2)
162
+
163
+ resource3 = mock 'resource3'
164
+ resource2.should_receive(:put).with(data).and_return(resource3)
165
+
166
+ resource3.stub(:body) { body }
167
+ end
168
+
169
+ def should_receive_http_delete(path)
170
+ resource = mock 'resource'
171
+ RestClient::Resource.should_receive(:new).with(url, options).and_return(resource)
172
+
173
+ resource2 = mock 'resource2'
174
+ resource.should_receive(:[]).with(path).and_return(resource2)
175
+
176
+ resource3 = mock 'resource3'
177
+ resource2.should_receive(:delete)
178
+ end
179
+ end
180
+ end
181
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instedd-pigeon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-18 00:00:00.000000000 Z
13
+ date: 2013-06-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.12
22
+ version: '3.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,41 +27,41 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 3.2.12
30
+ version: '3.2'
31
31
  - !ruby/object:Gem::Dependency
32
- name: nuntium_api
32
+ name: twitter_oauth
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
- - - ~>
36
+ - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
- version: '0.19'
38
+ version: '0'
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
- - - ~>
44
+ - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: '0.19'
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: verboice
48
+ name: rest-client
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - '='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.7.0
54
+ version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - '='
60
+ - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
- version: 0.7.0
62
+ version: '0'
63
63
  - !ruby/object:Gem::Dependency
64
- name: twitter_oauth
64
+ name: json
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -85,6 +85,7 @@ extensions: []
85
85
  extra_rdoc_files: []
86
86
  files:
87
87
  - .gitignore
88
+ - .rspec
88
89
  - .rvmrc
89
90
  - Gemfile
90
91
  - LICENSE.txt
@@ -117,9 +118,11 @@ files:
117
118
  - app/models/pigeon/nuntium_channel.rb
118
119
  - app/models/pigeon/verboice_channel.rb
119
120
  - app/views/pigeon/twitter/callback.html.erb
121
+ - config/locales/en.yml
120
122
  - config/routes.rb
121
123
  - config/schemas/nuntium/nuntium.yml
122
124
  - config/schemas/nuntium/qst-server.yml
125
+ - config/schemas/nuntium/smpp.yml
123
126
  - config/schemas/nuntium/twitter.yml
124
127
  - config/schemas/verboice/verboice.yml
125
128
  - lib/pigeon.rb
@@ -127,6 +130,7 @@ files:
127
130
  - lib/pigeon/errors.rb
128
131
  - lib/pigeon/initializer.rb
129
132
  - lib/pigeon/nuntium.rb
133
+ - lib/pigeon/utils.rb
130
134
  - lib/pigeon/verboice.rb
131
135
  - lib/pigeon/version.rb
132
136
  - pigeon.gemspec
@@ -168,6 +172,8 @@ files:
168
172
  - spec/helpers/pigeon/renderer/channel_renderer_spec.rb
169
173
  - spec/helpers/pigeon/tag_helper_spec.rb
170
174
  - spec/helpers/pigeon/template_helper_spec.rb
175
+ - spec/lib/pigeon/nuntium_spec.rb
176
+ - spec/lib/pigeon/verboice_spec.rb
171
177
  - spec/models/pigeon/channel_attribute_spec.rb
172
178
  - spec/models/pigeon/channel_schema_spec.rb
173
179
  - spec/models/pigeon/channel_spec.rb
@@ -189,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
195
  version: '0'
190
196
  segments:
191
197
  - 0
192
- hash: 1050241999
198
+ hash: -1009117297
193
199
  required_rubygems_version: !ruby/object:Gem::Requirement
194
200
  none: false
195
201
  requirements:
@@ -198,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
204
  version: '0'
199
205
  segments:
200
206
  - 0
201
- hash: 1050241999
207
+ hash: -1009117297
202
208
  requirements: []
203
209
  rubyforge_project:
204
210
  rubygems_version: 1.8.25
@@ -245,6 +251,8 @@ test_files:
245
251
  - spec/helpers/pigeon/renderer/channel_renderer_spec.rb
246
252
  - spec/helpers/pigeon/tag_helper_spec.rb
247
253
  - spec/helpers/pigeon/template_helper_spec.rb
254
+ - spec/lib/pigeon/nuntium_spec.rb
255
+ - spec/lib/pigeon/verboice_spec.rb
248
256
  - spec/models/pigeon/channel_attribute_spec.rb
249
257
  - spec/models/pigeon/channel_schema_spec.rb
250
258
  - spec/models/pigeon/channel_spec.rb