instedd-pigeon 0.2.2 → 0.3.0
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.
- data/app/assets/javascripts/pigeon/twilio-twizard.js.coffee +60 -0
- data/app/controllers/pigeon/twilio_controller.rb +23 -0
- data/app/helpers/pigeon/renderer/base.rb +1 -0
- data/app/models/pigeon/nuntium_channel.rb +10 -4
- data/app/models/pigeon/verboice_channel.rb +9 -3
- data/config/routes.rb +2 -0
- data/config/schemas/nuntium/nuntium.yml +0 -15
- data/config/schemas/nuntium/twilio.yml +49 -0
- data/lib/pigeon/initializer.rb +29 -2
- data/lib/pigeon/version.rb +1 -1
- data/pigeon.gemspec +1 -0
- metadata +21 -8
@@ -0,0 +1,60 @@
|
|
1
|
+
#= require pigeon/template
|
2
|
+
|
3
|
+
class TwilioTemplate extends PigeonTemplate
|
4
|
+
checkCredentials: =>
|
5
|
+
account_sid = @attribute('configuration[account_sid]').val()
|
6
|
+
auth_token = @attribute('configuration[auth_token]').val()
|
7
|
+
|
8
|
+
if account_sid != @account_sid || auth_token != @auth_token
|
9
|
+
@account_sid = account_sid
|
10
|
+
@auth_token = auth_token
|
11
|
+
|
12
|
+
if $.trim(@account_sid).length > 0 && $.trim(@auth_token).length > 0
|
13
|
+
client = new TwilioClient(@div, @account_sid, @auth_token)
|
14
|
+
|
15
|
+
phones_div = $('#twilio-phone-number-div')
|
16
|
+
phones_div.hide()
|
17
|
+
|
18
|
+
feedback = $('#twilio-feedback-div')
|
19
|
+
feedback.text("Fetching phone numbers from your account, please wait...")
|
20
|
+
feedback.show()
|
21
|
+
|
22
|
+
client.get_incoming_phone_numbers
|
23
|
+
success: (data) =>
|
24
|
+
@phone_numbers = data
|
25
|
+
if @phone_numbers.length == 0
|
26
|
+
feedback.text("It seems you don't have any phone number in your twilio account. Please buy one and then come back to this page.")
|
27
|
+
else
|
28
|
+
phone_select = $('#twilio-phone-number')
|
29
|
+
options = ""
|
30
|
+
for phone in @phone_numbers
|
31
|
+
options += "<option name=\"#{phone.phone_number}\">#{phone.friendly_name}</option>"
|
32
|
+
phone_select.html(options)
|
33
|
+
|
34
|
+
phones_div.show()
|
35
|
+
feedback.hide()
|
36
|
+
error: =>
|
37
|
+
feedback.text("Couldn't authenticate with Twilio.\nPlease check that you account sid and auth token are correct.")
|
38
|
+
|
39
|
+
run: ->
|
40
|
+
setInterval @checkCredentials, 500
|
41
|
+
|
42
|
+
password_field = @attribute('configuration[incoming_password]')
|
43
|
+
if password_field.val() == ''
|
44
|
+
password_field.val(@generatePassword())
|
45
|
+
|
46
|
+
class TwilioClient
|
47
|
+
constructor: (@div, @account_sid, @auth_token) ->
|
48
|
+
|
49
|
+
get_incoming_phone_numbers: (options) ->
|
50
|
+
url = $(@div).data('twilio-get-incoming-numbers-path')
|
51
|
+
$.ajax
|
52
|
+
url: url
|
53
|
+
type: "GET"
|
54
|
+
data:
|
55
|
+
account_sid: @account_sid
|
56
|
+
auth_token: @auth_token
|
57
|
+
success: options.success
|
58
|
+
error: options.error
|
59
|
+
|
60
|
+
PigeonTemplate.registerClass 'twilio', TwilioTemplate
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'twilio-ruby'
|
2
|
+
|
3
|
+
module Pigeon
|
4
|
+
class TwilioController < ActionController::Base
|
5
|
+
def get_incoming_phone_numbers
|
6
|
+
account_sid = params[:account_sid].strip
|
7
|
+
auth_token = params[:auth_token].strip
|
8
|
+
|
9
|
+
client = Twilio::REST::Client.new account_sid, auth_token
|
10
|
+
incoming_phones = client.account.incoming_phone_numbers.list
|
11
|
+
json = incoming_phones.map do |phone|
|
12
|
+
{
|
13
|
+
sid: phone.sid,
|
14
|
+
phone_number: phone.phone_number,
|
15
|
+
friendly_name: phone.friendly_name,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
render json: json
|
19
|
+
rescue Twilio::REST::RequestError => ex
|
20
|
+
head :unauthorized
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -121,6 +121,7 @@ module Pigeon
|
|
121
121
|
if %w(@template @wizard).include?(command)
|
122
122
|
options["data-application-name"] ||= Pigeon.config.application_name
|
123
123
|
options["data-twitter-path"] = Pigeon::Engine.routes.url_helpers.twitter_path
|
124
|
+
options["data-twilio-get-incoming-numbers-path"] = Pigeon::Engine.routes.url_helpers.twilio_get_incoming_phone_numbers_path
|
124
125
|
end
|
125
126
|
|
126
127
|
case command
|
@@ -4,8 +4,14 @@ module Pigeon
|
|
4
4
|
class << self
|
5
5
|
def type() :nuntium end
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
if Rails.env.development?
|
8
|
+
def schemas
|
9
|
+
load_schemas
|
10
|
+
end
|
11
|
+
else
|
12
|
+
def schemas
|
13
|
+
@schemas ||= load_schemas
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
def list
|
@@ -26,7 +32,7 @@ module Pigeon
|
|
26
32
|
|
27
33
|
def load_schemas
|
28
34
|
if Pigeon.config.nuntium_configured?
|
29
|
-
Pigeon::ChannelSchema.list_from_hash(:nuntium, PigeonConfig
|
35
|
+
Pigeon::ChannelSchema.list_from_hash(:nuntium, PigeonConfig.nuntium_channel_schemas).reject do |schema|
|
30
36
|
schema.kind == 'twitter' && !Pigeon.config.twitter_configured?
|
31
37
|
end
|
32
38
|
else
|
@@ -40,7 +46,7 @@ module Pigeon
|
|
40
46
|
|
41
47
|
validates_numericality_of :priority, only_integer: true
|
42
48
|
validates_presence_of :protocol
|
43
|
-
validates_inclusion_of :direction,
|
49
|
+
validates_inclusion_of :direction,
|
44
50
|
:in => %w(incoming outgoing bidirectional),
|
45
51
|
:message => "must be incoming, outgoing or bidirectional"
|
46
52
|
|
@@ -4,8 +4,14 @@ module Pigeon
|
|
4
4
|
class << self
|
5
5
|
def type() :verboice end
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
if Rails.env.development?
|
8
|
+
def schemas
|
9
|
+
load_schemas
|
10
|
+
end
|
11
|
+
else
|
12
|
+
def schemas
|
13
|
+
@schemas ||= load_schemas
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
def list
|
@@ -24,7 +30,7 @@ module Pigeon
|
|
24
30
|
|
25
31
|
def load_schemas
|
26
32
|
if Pigeon.config.verboice_configured?
|
27
|
-
Pigeon::ChannelSchema.list_from_hash(:verboice, PigeonConfig::
|
33
|
+
Pigeon::ChannelSchema.list_from_hash(:verboice, PigeonConfig::verboice_channel_schemas)
|
28
34
|
else
|
29
35
|
[]
|
30
36
|
end
|
data/config/routes.rb
CHANGED
@@ -161,21 +161,6 @@ smtp:
|
|
161
161
|
type: boolean
|
162
162
|
label: "Use SSL?"
|
163
163
|
|
164
|
-
twilio:
|
165
|
-
humanized_name: 'Twilio channel'
|
166
|
-
attributes:
|
167
|
-
- name: protocol
|
168
|
-
value: sms
|
169
|
-
user: false
|
170
|
-
- name: configuration
|
171
|
-
attributes:
|
172
|
-
- name: account_sid
|
173
|
-
- name: auth_token
|
174
|
-
- name: from
|
175
|
-
- name: incoming_password
|
176
|
-
type: password
|
177
|
-
label: Incoming password (to use for the callback URLs)
|
178
|
-
|
179
164
|
xmpp:
|
180
165
|
humanized_name: 'XMPP channel'
|
181
166
|
attributes:
|
@@ -0,0 +1,49 @@
|
|
1
|
+
twilio:
|
2
|
+
humanized_name: 'Twilio channel'
|
3
|
+
attributes:
|
4
|
+
- name: protocol
|
5
|
+
value: sms
|
6
|
+
user: false
|
7
|
+
- name: configuration
|
8
|
+
attributes:
|
9
|
+
- name: account_sid
|
10
|
+
- name: auth_token
|
11
|
+
- name: from
|
12
|
+
- name: incoming_password
|
13
|
+
type: password
|
14
|
+
label: Incoming password (to use for the callback URLs)
|
15
|
+
template:
|
16
|
+
- "@template"
|
17
|
+
- type: twilio
|
18
|
+
-
|
19
|
+
- div
|
20
|
+
- "Open your "
|
21
|
+
-
|
22
|
+
- a
|
23
|
+
- href: https://www.twilio.com/
|
24
|
+
- Twilio
|
25
|
+
- " account and copy/paste your AccountSID and AuthToken. You will find that information on the top of the Dashboard page."
|
26
|
+
-
|
27
|
+
- "@attr"
|
28
|
+
- configuration[account_sid]
|
29
|
+
-
|
30
|
+
- "@attr"
|
31
|
+
- configuration[auth_token]
|
32
|
+
-
|
33
|
+
- div
|
34
|
+
- id: twilio-feedback-div
|
35
|
+
style: "display:none"
|
36
|
+
-
|
37
|
+
- p
|
38
|
+
- "Fetching phone numbers from your account, please wait..."
|
39
|
+
-
|
40
|
+
- div
|
41
|
+
- id: twilio-phone-number-div
|
42
|
+
style: "display:none"
|
43
|
+
-
|
44
|
+
- p
|
45
|
+
- "Select a phone number to use for this channel:"
|
46
|
+
-
|
47
|
+
- select
|
48
|
+
- id: twilio-phone-number
|
49
|
+
name: "channel_data[configuration][from]"
|
data/lib/pigeon/initializer.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
module PigeonConfig
|
2
|
+
@@nuntium_channel_schemas = {}
|
3
|
+
@@verboice_channel_schemas = {}
|
4
|
+
|
5
|
+
def self.reload_schemas()
|
6
|
+
@@nuntium_channel_schemas.replace load_schemas(File.join Pigeon.root, 'config/schemas/nuntium')
|
7
|
+
@@verboice_channel_schemas.replace load_schemas(File.join Pigeon.root, 'config/schemas/verboice')
|
8
|
+
end
|
9
|
+
|
2
10
|
def self.load_schemas(path)
|
3
11
|
schemas = {}
|
4
12
|
Dir.glob(File.join(path, '*.yml')).each do |f|
|
@@ -7,7 +15,26 @@ module PigeonConfig
|
|
7
15
|
schemas
|
8
16
|
end
|
9
17
|
|
10
|
-
|
11
|
-
|
18
|
+
if Rails.env.development?
|
19
|
+
def self.nuntium_channel_schemas
|
20
|
+
reload_schemas
|
21
|
+
@@nuntium_channel_schemas
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.verboice_channel_schemas
|
25
|
+
reload_schemas
|
26
|
+
@@verboice_channel_schemas
|
27
|
+
end
|
28
|
+
else
|
29
|
+
def self.nuntium_channel_schemas
|
30
|
+
@@nuntium_channel_schemas
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.verboice_channel_schemas
|
34
|
+
@@verboice_channel_schemas
|
35
|
+
end
|
36
|
+
|
37
|
+
reload_schemas()
|
38
|
+
end
|
12
39
|
end
|
13
40
|
|
data/lib/pigeon/version.rb
CHANGED
data/pigeon.gemspec
CHANGED
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.
|
4
|
+
version: 0.3.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-
|
13
|
+
date: 2013-09-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -44,6 +44,22 @@ dependencies:
|
|
44
44
|
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: twilio-ruby
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
47
63
|
- !ruby/object:Gem::Dependency
|
48
64
|
name: rest-client
|
49
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,9 +113,11 @@ files:
|
|
97
113
|
- app/assets/javascripts/pigeon.js
|
98
114
|
- app/assets/javascripts/pigeon/qst-server-wizard.js.coffee
|
99
115
|
- app/assets/javascripts/pigeon/template.js.coffee
|
116
|
+
- app/assets/javascripts/pigeon/twilio-twizard.js.coffee
|
100
117
|
- app/assets/javascripts/pigeon/twitter-template.js.coffee
|
101
118
|
- app/assets/javascripts/pigeon/wizard.js.coffee
|
102
119
|
- app/assets/stylesheets/pigeon.css.sass
|
120
|
+
- app/controllers/pigeon/twilio_controller.rb
|
103
121
|
- app/controllers/pigeon/twitter_controller.rb
|
104
122
|
- app/helpers/.gitkeep
|
105
123
|
- app/helpers/pigeon/channel_helper.rb
|
@@ -123,6 +141,7 @@ files:
|
|
123
141
|
- config/schemas/nuntium/nuntium.yml
|
124
142
|
- config/schemas/nuntium/qst-server.yml
|
125
143
|
- config/schemas/nuntium/smpp.yml
|
144
|
+
- config/schemas/nuntium/twilio.yml
|
126
145
|
- config/schemas/nuntium/twitter.yml
|
127
146
|
- config/schemas/verboice/verboice.yml
|
128
147
|
- lib/pigeon.rb
|
@@ -196,18 +215,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
215
|
- - ! '>='
|
197
216
|
- !ruby/object:Gem::Version
|
198
217
|
version: '0'
|
199
|
-
segments:
|
200
|
-
- 0
|
201
|
-
hash: 4020436503618818902
|
202
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
219
|
none: false
|
204
220
|
requirements:
|
205
221
|
- - ! '>='
|
206
222
|
- !ruby/object:Gem::Version
|
207
223
|
version: '0'
|
208
|
-
segments:
|
209
|
-
- 0
|
210
|
-
hash: 4020436503618818902
|
211
224
|
requirements: []
|
212
225
|
rubyforge_project:
|
213
226
|
rubygems_version: 1.8.23
|