esendex 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/app/controllers/esendex/application_controller.rb +4 -4
- data/app/controllers/esendex/inbound_messages_controller.rb +11 -11
- data/app/controllers/esendex/message_delivered_events_controller.rb +11 -11
- data/app/controllers/esendex/message_failed_events_controller.rb +11 -11
- data/app/controllers/esendex/push_notification_handler.rb +41 -41
- data/config/routes.rb +5 -5
- data/lib/esendex.rb +63 -62
- data/lib/esendex/account.rb +44 -44
- data/lib/esendex/api_connection.rb +29 -29
- data/lib/esendex/dispatcher_result.rb +25 -25
- data/lib/esendex/engine.rb +4 -4
- data/lib/esendex/exceptions.rb +25 -25
- data/lib/esendex/hash_serialisation.rb +23 -23
- data/lib/esendex/inbound_message.rb +30 -30
- data/lib/esendex/message.rb +38 -38
- data/lib/esendex/message_batch_submission.rb +50 -50
- data/lib/esendex/message_delivered_event.rb +29 -29
- data/lib/esendex/message_failed_event.rb +29 -29
- data/lib/esendex/railtie.rb +11 -11
- data/lib/esendex/version.rb +3 -3
- data/lib/esendex/voice_message.rb +25 -0
- data/lib/tasks/esendex.rake +29 -29
- data/licence.txt +23 -23
- data/readme.md +186 -186
- data/spec/account_spec.rb +211 -211
- data/spec/api_connection_spec.rb +78 -78
- data/spec/controllers/message_delivered_events_controller_spec.rb +29 -29
- data/spec/controllers/push_notification_handler_spec.rb +96 -96
- data/spec/dummy/README.rdoc +261 -261
- data/spec/dummy/Rakefile +7 -7
- data/spec/dummy/app/assets/javascripts/application.js +15 -15
- data/spec/dummy/app/assets/stylesheets/application.css +13 -13
- data/spec/dummy/app/controllers/application_controller.rb +3 -3
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/views/layouts/application.html.erb +14 -14
- data/spec/dummy/config.ru +4 -4
- data/spec/dummy/config/application.rb +66 -66
- data/spec/dummy/config/boot.rb +9 -9
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +37 -37
- data/spec/dummy/config/environments/production.rb +67 -67
- data/spec/dummy/config/environments/test.rb +39 -39
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/inflections.rb +15 -15
- data/spec/dummy/config/initializers/mime_types.rb +5 -5
- data/spec/dummy/config/initializers/secret_token.rb +7 -7
- data/spec/dummy/config/initializers/session_store.rb +8 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +5 -5
- data/spec/dummy/config/routes.rb +4 -4
- data/spec/dummy/public/404.html +26 -26
- data/spec/dummy/public/422.html +26 -26
- data/spec/dummy/public/500.html +25 -25
- data/spec/dummy/script/rails +6 -6
- data/spec/hash_serialisation_spec.rb +52 -52
- data/spec/inbound_message_spec.rb +42 -42
- data/spec/message_batch_submission_spec.rb +54 -54
- data/spec/message_delivered_event_spec.rb +32 -32
- data/spec/message_failed_event_spec.rb +32 -32
- data/spec/message_spec.rb +49 -49
- data/spec/spec_helper.rb +41 -41
- data/spec/voice_message_spec.rb +29 -0
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac1d98a5009c85639396fc251b7f1fe73c709321
|
4
|
+
data.tar.gz: 1a38f74ae0ef3da6fc6f98549b9dc5512f7b57d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 375d165b04e43b38e7607d7a077395c3070f99603797249fee0432da43eb48dcedcbc982b3c11c63a195824afa2e6e37e644b8948c05ed2c2d65800352bbee5d
|
7
|
+
data.tar.gz: 70e8d44120d20d906dea4e2102b8024254f2ad1ce530a5bdaefe13b768293cf415e8054b62f86533c80a8f43089d01c2f139f6ea36af83fa90dd519149a01716
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Esendex
|
2
|
-
class ApplicationController < ActionController::Base
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module Esendex
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
end
|
4
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module Esendex
|
2
|
-
class InboundMessagesController < ApplicationController
|
3
|
-
include PushNotificationHandler
|
4
|
-
|
5
|
-
def create
|
6
|
-
process_notification :inbound_message, request.body
|
7
|
-
render text: "OK"
|
8
|
-
rescue => e
|
9
|
-
render_error e
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module Esendex
|
2
|
+
class InboundMessagesController < ApplicationController
|
3
|
+
include PushNotificationHandler
|
4
|
+
|
5
|
+
def create
|
6
|
+
process_notification :inbound_message, request.body
|
7
|
+
render text: "OK"
|
8
|
+
rescue => e
|
9
|
+
render_error e
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module Esendex
|
2
|
-
class MessageDeliveredEventsController < ApplicationController
|
3
|
-
include PushNotificationHandler
|
4
|
-
|
5
|
-
def create
|
6
|
-
process_notification :message_delivered_event, request.body
|
7
|
-
render text: "OK"
|
8
|
-
rescue => e
|
9
|
-
render_error e
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module Esendex
|
2
|
+
class MessageDeliveredEventsController < ApplicationController
|
3
|
+
include PushNotificationHandler
|
4
|
+
|
5
|
+
def create
|
6
|
+
process_notification :message_delivered_event, request.body
|
7
|
+
render text: "OK"
|
8
|
+
rescue => e
|
9
|
+
render_error e
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module Esendex
|
2
|
-
class MessageFailedEventsController < ApplicationController
|
3
|
-
include PushNotificationHandler
|
4
|
-
|
5
|
-
def create
|
6
|
-
process_notification :message_failed_event, request.body
|
7
|
-
render text: "OK"
|
8
|
-
rescue => e
|
9
|
-
render_error e
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module Esendex
|
2
|
+
class MessageFailedEventsController < ApplicationController
|
3
|
+
include PushNotificationHandler
|
4
|
+
|
5
|
+
def create
|
6
|
+
process_notification :message_failed_event, request.body
|
7
|
+
render text: "OK"
|
8
|
+
rescue => e
|
9
|
+
render_error e
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
# Common behaviour for all push notification controllers
|
2
|
-
#
|
3
|
-
module Esendex
|
4
|
-
module PushNotificationHandler
|
5
|
-
|
6
|
-
# Used by controllers to handle incoming push notification
|
7
|
-
#
|
8
|
-
# type - Symbol indicating type
|
9
|
-
# source - String request body of the notification
|
10
|
-
#
|
11
|
-
# Returns nothing
|
12
|
-
def process_notification(type, source)
|
13
|
-
|
14
|
-
if handler = Esendex.send("#{type}_handler")
|
15
|
-
notification_class = Esendex.const_get(type.to_s.camelize)
|
16
|
-
notification = notification_class.from_xml source
|
17
|
-
handler.call notification
|
18
|
-
else
|
19
|
-
logger.info "Received #{type} push notification but no handler configured" if defined?(logger)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def render_error(error)
|
25
|
-
lines = []
|
26
|
-
lines << "Path: #{request.path}"
|
27
|
-
request.body.rewind
|
28
|
-
lines << "Notification XML:\r\n#{request.body.read}"
|
29
|
-
lines << "Error: #{error.class.name} #{error.message}"
|
30
|
-
if Esendex.suppress_error_backtrace
|
31
|
-
lines << "[backtrace suppressed]"
|
32
|
-
else
|
33
|
-
lines << error.backtrace.join("\r\n")
|
34
|
-
end
|
35
|
-
lines << "---"
|
36
|
-
lines << "Ruby #{RUBY_VERSION}"
|
37
|
-
lines << "Rails #{Rails::VERSION::STRING}"
|
38
|
-
lines << Esendex.user_agent
|
39
|
-
render text: lines.join("\r\n"), status: 500
|
40
|
-
end
|
41
|
-
end
|
1
|
+
# Common behaviour for all push notification controllers
|
2
|
+
#
|
3
|
+
module Esendex
|
4
|
+
module PushNotificationHandler
|
5
|
+
|
6
|
+
# Used by controllers to handle incoming push notification
|
7
|
+
#
|
8
|
+
# type - Symbol indicating type
|
9
|
+
# source - String request body of the notification
|
10
|
+
#
|
11
|
+
# Returns nothing
|
12
|
+
def process_notification(type, source)
|
13
|
+
|
14
|
+
if handler = Esendex.send("#{type}_handler")
|
15
|
+
notification_class = Esendex.const_get(type.to_s.camelize)
|
16
|
+
notification = notification_class.from_xml source
|
17
|
+
handler.call notification
|
18
|
+
else
|
19
|
+
logger.info "Received #{type} push notification but no handler configured" if defined?(logger)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_error(error)
|
25
|
+
lines = []
|
26
|
+
lines << "Path: #{request.path}"
|
27
|
+
request.body.rewind
|
28
|
+
lines << "Notification XML:\r\n#{request.body.read}"
|
29
|
+
lines << "Error: #{error.class.name} #{error.message}"
|
30
|
+
if Esendex.suppress_error_backtrace
|
31
|
+
lines << "[backtrace suppressed]"
|
32
|
+
else
|
33
|
+
lines << error.backtrace.join("\r\n")
|
34
|
+
end
|
35
|
+
lines << "---"
|
36
|
+
lines << "Ruby #{RUBY_VERSION}"
|
37
|
+
lines << "Rails #{Rails::VERSION::STRING}"
|
38
|
+
lines << Esendex.user_agent
|
39
|
+
render text: lines.join("\r\n"), status: 500
|
40
|
+
end
|
41
|
+
end
|
42
42
|
end
|
data/config/routes.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
Esendex::Engine.routes.draw do
|
2
|
-
resources :message_delivered_events, only: [:create]
|
3
|
-
resources :message_failed_events, only: [:create]
|
4
|
-
resources :inbound_messages, only: [:create]
|
5
|
-
end
|
1
|
+
Esendex::Engine.routes.draw do
|
2
|
+
resources :message_delivered_events, only: [:create]
|
3
|
+
resources :message_failed_events, only: [:create]
|
4
|
+
resources :inbound_messages, only: [:create]
|
5
|
+
end
|
data/lib/esendex.rb
CHANGED
@@ -1,62 +1,63 @@
|
|
1
|
-
module Esendex
|
2
|
-
require_relative 'esendex/version'
|
3
|
-
require_relative 'esendex/exceptions'
|
4
|
-
require_relative 'esendex/api_connection'
|
5
|
-
require_relative 'esendex/hash_serialisation'
|
6
|
-
|
7
|
-
require_relative 'esendex/account'
|
8
|
-
require_relative 'esendex/dispatcher_result'
|
9
|
-
require_relative 'esendex/inbound_message'
|
10
|
-
require_relative 'esendex/message'
|
11
|
-
require_relative 'esendex/
|
12
|
-
require_relative 'esendex/
|
13
|
-
require_relative 'esendex/
|
14
|
-
|
15
|
-
|
16
|
-
if
|
17
|
-
|
18
|
-
require_relative 'esendex/
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# config.
|
29
|
-
# config.
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
1
|
+
module Esendex
|
2
|
+
require_relative 'esendex/version'
|
3
|
+
require_relative 'esendex/exceptions'
|
4
|
+
require_relative 'esendex/api_connection'
|
5
|
+
require_relative 'esendex/hash_serialisation'
|
6
|
+
|
7
|
+
require_relative 'esendex/account'
|
8
|
+
require_relative 'esendex/dispatcher_result'
|
9
|
+
require_relative 'esendex/inbound_message'
|
10
|
+
require_relative 'esendex/message'
|
11
|
+
require_relative 'esendex/voice_message'
|
12
|
+
require_relative 'esendex/message_batch_submission'
|
13
|
+
require_relative 'esendex/message_delivered_event'
|
14
|
+
require_relative 'esendex/message_failed_event'
|
15
|
+
|
16
|
+
# Load Rails extensions if Rails present
|
17
|
+
if defined?(Rails)
|
18
|
+
require_relative 'esendex/railtie'
|
19
|
+
require_relative 'esendex/engine'
|
20
|
+
end
|
21
|
+
|
22
|
+
API_NAMESPACE = 'http://api.esendex.com/ns/'
|
23
|
+
API_HOST = 'https://api.esendex.com'
|
24
|
+
|
25
|
+
# Public - used to configure the gem prior to use
|
26
|
+
#
|
27
|
+
# Esendex.configure do |config|
|
28
|
+
# config.username = 'username'
|
29
|
+
# config.password = 'password'
|
30
|
+
# config.account_reference = 'account reference'
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
def self.configure
|
34
|
+
yield self if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
# credentials for authentication
|
39
|
+
attr_writer :account_reference, :username, :password
|
40
|
+
|
41
|
+
# lambdas for handling push notifications
|
42
|
+
attr_accessor :message_delivered_event_handler, :message_failed_event_handler, :inbound_message_handler
|
43
|
+
|
44
|
+
# behaviour config
|
45
|
+
attr_accessor :suppress_error_backtrace
|
46
|
+
|
47
|
+
def account_reference
|
48
|
+
@account_reference ||= ENV['ESENDEX_ACCOUNT']
|
49
|
+
end
|
50
|
+
|
51
|
+
def username
|
52
|
+
@username ||= ENV['ESENDEX_USERNAME']
|
53
|
+
end
|
54
|
+
|
55
|
+
def password
|
56
|
+
@password ||= ENV['ESENDEX_PASSWORD']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.user_agent
|
61
|
+
"EsendexRubyGem/#{Esendex::VERSION}"
|
62
|
+
end
|
63
|
+
end
|
data/lib/esendex/account.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
module Esendex
|
4
|
-
class Account
|
5
|
-
DEFAULT_DATE_OFFSET = 90
|
6
|
-
|
7
|
-
attr_accessor :reference
|
8
|
-
|
9
|
-
def initialize(account_reference = Esendex.account_reference)
|
10
|
-
@reference = account_reference
|
11
|
-
end
|
12
|
-
|
13
|
-
def api_connection
|
14
|
-
@api_connection ||= ApiConnection.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def messages_remaining
|
18
|
-
response = api_connection.get "/v1.0/accounts"
|
19
|
-
doc = Nokogiri::XML(response.body)
|
20
|
-
node = doc.at_xpath("//api:account[api:reference='#{@reference}']/api:messagesremaining", 'api' => Esendex::API_NAMESPACE)
|
21
|
-
raise AccountReferenceError.new if node.nil?
|
22
|
-
node.content.to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
def send_message(args={})
|
26
|
-
raise ArgumentError.new(":to required") unless args[:to]
|
27
|
-
raise ArgumentError.new(":body required") unless args[:body]
|
28
|
-
|
29
|
-
send_messages [Message.new(args[:to], args[:body], args[:from])]
|
30
|
-
end
|
31
|
-
|
32
|
-
def send_messages(messages)
|
33
|
-
batch_submission = MessageBatchSubmission.new(@reference, messages)
|
34
|
-
response = api_connection.post("/v1.0/messagedispatcher", batch_submission.to_s)
|
35
|
-
DispatcherResult.from_xml response.body
|
36
|
-
end
|
37
|
-
|
38
|
-
def sent_messages(args={})
|
39
|
-
SentMessageClient
|
40
|
-
.new(api_connection)
|
41
|
-
.get_messages(args.merge(account_reference: reference))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Esendex
|
4
|
+
class Account
|
5
|
+
DEFAULT_DATE_OFFSET = 90
|
6
|
+
|
7
|
+
attr_accessor :reference
|
8
|
+
|
9
|
+
def initialize(account_reference = Esendex.account_reference)
|
10
|
+
@reference = account_reference
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_connection
|
14
|
+
@api_connection ||= ApiConnection.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def messages_remaining
|
18
|
+
response = api_connection.get "/v1.0/accounts"
|
19
|
+
doc = Nokogiri::XML(response.body)
|
20
|
+
node = doc.at_xpath("//api:account[api:reference='#{@reference}']/api:messagesremaining", 'api' => Esendex::API_NAMESPACE)
|
21
|
+
raise AccountReferenceError.new if node.nil?
|
22
|
+
node.content.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_message(args={})
|
26
|
+
raise ArgumentError.new(":to required") unless args[:to]
|
27
|
+
raise ArgumentError.new(":body required") unless args[:body]
|
28
|
+
|
29
|
+
send_messages [Message.new(args[:to], args[:body], args[:from])]
|
30
|
+
end
|
31
|
+
|
32
|
+
def send_messages(messages)
|
33
|
+
batch_submission = MessageBatchSubmission.new(@reference, messages)
|
34
|
+
response = api_connection.post("/v1.0/messagedispatcher", batch_submission.to_s)
|
35
|
+
DispatcherResult.from_xml response.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def sent_messages(args={})
|
39
|
+
SentMessageClient
|
40
|
+
.new(api_connection)
|
41
|
+
.get_messages(args.merge(account_reference: reference))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'nestful'
|
2
|
-
|
3
|
-
module Esendex
|
4
|
-
class ApiConnection
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@connection = Nestful::Connection.new(Esendex::API_HOST)
|
8
|
-
@connection.user = Esendex.username
|
9
|
-
@connection.password = Esendex.password
|
10
|
-
@connection.auth_type = :basic
|
11
|
-
end
|
12
|
-
|
13
|
-
def default_headers
|
14
|
-
{ 'User-Agent' => Esendex.user_agent }
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(url)
|
18
|
-
@connection.get url, default_headers
|
19
|
-
rescue => e
|
20
|
-
raise Esendex::ApiErrorFactory.new.get_api_error(e)
|
21
|
-
end
|
22
|
-
|
23
|
-
def post(url, body)
|
24
|
-
@connection.post url, body, default_headers
|
25
|
-
rescue => e
|
26
|
-
raise Esendex::ApiErrorFactory.new.get_api_error(e)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
require 'nestful'
|
2
|
+
|
3
|
+
module Esendex
|
4
|
+
class ApiConnection
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@connection = Nestful::Connection.new(Esendex::API_HOST)
|
8
|
+
@connection.user = Esendex.username
|
9
|
+
@connection.password = Esendex.password
|
10
|
+
@connection.auth_type = :basic
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_headers
|
14
|
+
{ 'User-Agent' => Esendex.user_agent }
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(url)
|
18
|
+
@connection.get url, default_headers
|
19
|
+
rescue => e
|
20
|
+
raise Esendex::ApiErrorFactory.new.get_api_error(e)
|
21
|
+
end
|
22
|
+
|
23
|
+
def post(url, body)
|
24
|
+
@connection.post url, body, default_headers
|
25
|
+
rescue => e
|
26
|
+
raise Esendex::ApiErrorFactory.new.get_api_error(e)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|