action-texter 0.2.0.pre → 0.2.1.pre
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/Gemfile.lock +1 -1
- data/lib/action_texter/configuration.rb +2 -2
- data/lib/action_texter/delivery_methods.rb +5 -5
- data/lib/action_texter/gem_version.rb +1 -1
- data/lib/action_texter/provider/mail/delivery.rb +17 -19
- data/lib/action_texter/provider/messagebird/delivery.rb +18 -20
- data/lib/action_texter/provider/messagebird/response.rb +21 -23
- data/lib/action_texter/provider/messagebird/response_error.rb +20 -22
- data/lib/action_texter/provider/messagebird/response_recipient.rp +13 -0
- data/lib/action_texter/provider/messagebird/response_recipients.rb +22 -0
- data/lib/action_texter/provider/messagebird/response_success.rb +45 -64
- data/lib/action_texter/provider/test_message/test_message.rb +20 -0
- data/lib/action_texter.rb +11 -13
- metadata +5 -3
- data/lib/action_texter/provider/test_message/delivery.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3365998189231761f4c8d7a5d15ac96bd8a4b13d
|
4
|
+
data.tar.gz: 9edb21e259152ac8557be7c4664ac2a877418006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d78b996d9ca7b094b2b6dd3b218be54b3b9993ac2033696608e3f8839ede40b1dfbc9d2248a4f2713709d30d0c828f020de2f2af0c80641e29f1e8ebcde7db7
|
7
|
+
data.tar.gz: e9ecd898ee8d64ddd7c75454ef2258c7efd7b425e4f5b05e5d62e9422519f59ee4c30e1ec9020451c48b26069b2aa008a4b732abde1b3915c0ce409b3ada1271
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module ActionTexter
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :from, :to, :endpoint, :path, :product_token, :content_type, :delivery_method
|
3
|
+
attr_accessor :from, :to, :subject, :endpoint, :path, :product_token, :content_type, :delivery_method
|
4
4
|
|
5
5
|
alias_method :api_key=, :product_token=
|
6
6
|
|
7
7
|
def defaults
|
8
|
-
@defaults ||= { from: from, to: to }
|
8
|
+
@defaults ||= { from: from, to: to, subject: subject }
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize
|
@@ -21,9 +21,9 @@ module ActionTexter
|
|
21
21
|
|
22
22
|
# add_delivery_method :file, ActionTexter::FileDelivery,
|
23
23
|
#:location => defined?(Rails.root) ? "#{Rails.root}/tmp/texts" : "#{Dir.tmpdir}/texts"
|
24
|
-
add_delivery_method :test, ActionTexter::
|
25
|
-
add_delivery_method :messagebird, ActionTexter::
|
26
|
-
add_delivery_method :mail, ActionTexter::
|
24
|
+
add_delivery_method :test, ActionTexter::TestMessage
|
25
|
+
add_delivery_method :messagebird, ActionTexter::Messagebird::Delivery, { endpoint: 'https://rest.messagebird.com', path: '/messages' }
|
26
|
+
add_delivery_method :mail, ActionTexter::Mail::Delivery, { charset: 'utf8' }
|
27
27
|
# add_delivery_method :twilio, ActionTexter::TwilioDelivery
|
28
28
|
# add_delivery_method :whitelist_proxy, ActionTexter::WhitelistProxyDelivery
|
29
29
|
end
|
@@ -34,8 +34,8 @@ module ActionTexter
|
|
34
34
|
cattr_accessor :delivery_methods, :delivery_method
|
35
35
|
# attr_accessor
|
36
36
|
# Provides a list of SMS messages that have been delivered by ActionTexter::TestDelivery
|
37
|
-
delegate deliveries: ActionTexter::
|
38
|
-
delegate :deliveries= => ActionTexter::
|
37
|
+
delegate deliveries: ActionTexter::TestMessage
|
38
|
+
delegate :deliveries= => ActionTexter::TestMessage
|
39
39
|
|
40
40
|
# Adds a new delivery method through the given class using the given symbol
|
41
41
|
# as alias and the default options supplied:
|
@@ -1,30 +1,28 @@
|
|
1
1
|
require 'mail'
|
2
2
|
module ActionTexter
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
module Mail
|
4
|
+
class Delivery
|
5
|
+
|
6
|
+
def initialize(settings = {})
|
7
|
+
@charset = settings[:charset]
|
8
|
+
end
|
10
9
|
|
11
|
-
|
10
|
+
def deliver(message)
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
mail = ::Mail.new do |mail|
|
13
|
+
from message.from
|
14
|
+
to message.to
|
15
|
+
cc message.cc
|
16
|
+
subject message.subject
|
17
|
+
body message.body.to_s
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
self.charset = @charset
|
20
|
+
end
|
22
21
|
|
23
|
-
|
22
|
+
#LOGGER.info(mail.body)
|
24
23
|
|
25
|
-
|
24
|
+
mail.deliver!
|
26
25
|
|
27
|
-
end
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -1,29 +1,27 @@
|
|
1
1
|
require 'json'
|
2
2
|
module ActionTexter
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
attr_reader :response
|
3
|
+
module Messagebird
|
4
|
+
class Delivery
|
5
|
+
attr_accessor :body
|
6
|
+
attr_reader :response
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def initialize(settings)
|
9
|
+
@endpoint = settings[:endpoint]
|
10
|
+
@path = settings[:path]
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
response
|
13
|
+
def deliver message
|
14
|
+
uri = URI.parse( @endpoint )
|
15
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
16
|
+
@response = Response.new(http.post(@path, to_json(message), 'Authorization' => "AccessKey #{ActionTexter.config.product_token}", 'Content-Type' => 'application/json'))
|
20
17
|
end
|
18
|
+
response
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
21
|
+
def to_json message
|
22
|
+
JSON.generate(recipients: message.to,
|
23
|
+
originator: message.from,
|
24
|
+
body: message.body)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -1,33 +1,31 @@
|
|
1
1
|
module ActionTexter
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :net_http_response, :body, :code
|
2
|
+
module Messagebird
|
3
|
+
|
4
|
+
class Response
|
5
|
+
attr_reader :net_http_response, :body, :code
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def initialize(net_http_response)
|
8
|
+
@net_http_response = net_http_response
|
9
|
+
@body = @net_http_response.body
|
10
|
+
@code = @net_http_response.code
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def success?
|
14
|
+
code.to_i == 201
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def failure?
|
18
|
+
!success?
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
21
|
+
def body
|
22
|
+
if success?
|
23
|
+
SuccessResponse.new(@body)
|
24
|
+
else
|
25
|
+
ErrorResponse.new(@body)
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
31
28
|
end
|
29
|
+
|
32
30
|
end
|
33
31
|
end
|
@@ -1,32 +1,30 @@
|
|
1
1
|
require 'json'
|
2
2
|
module ActionTexter
|
3
|
-
module
|
4
|
-
|
5
|
-
class ErrorResponse
|
3
|
+
module Messagebird
|
4
|
+
class ErrorResponse
|
6
5
|
|
7
|
-
|
6
|
+
attr_reader :code, :description
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
ERROR_CODES = {
|
9
|
+
2 => 'Request not allowed',
|
10
|
+
9 => 'Missing params',
|
11
|
+
10 => 'Invalid params',
|
12
|
+
20 => 'Not found',
|
13
|
+
25 => 'Not enough balance',
|
14
|
+
98 => 'API not found',
|
15
|
+
99 => 'Internal error'
|
16
|
+
}
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def initialize(error)
|
19
|
+
@errors = JSON.parse(error, symbolize_names: true)[:errors]
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def errors
|
23
|
+
@errors.map { |e| e.merge(error_message: ERROR_CODES[e[:code]]) }
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
26
|
+
def count
|
27
|
+
@errors.count
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActionTexter
|
2
|
+
module Messagebird
|
3
|
+
class Recipient
|
4
|
+
attr_reader :recipient, :status, :status_datetime
|
5
|
+
|
6
|
+
def initializer(recipient)
|
7
|
+
@recipient = recipient[:recipient]
|
8
|
+
@status = recipient[:status]
|
9
|
+
@status_datetime = recipient[:statusDatetime]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActionTexter
|
2
|
+
module Messagebird
|
3
|
+
class Response
|
4
|
+
class Rcipients
|
5
|
+
attr_reader :total_count, :total_sent_count, :total_delivered_count, :items
|
6
|
+
|
7
|
+
def initiliazer(recipients)
|
8
|
+
@recipients = recipients
|
9
|
+
@total_count = recipients[:totalCount]
|
10
|
+
@total_sent_count = recipients[:totalSentCount]
|
11
|
+
@total_count = recipients[:totalDeliveredCount]
|
12
|
+
end
|
13
|
+
|
14
|
+
def items
|
15
|
+
@recipients[:items].map do |i|
|
16
|
+
ActionTexter::Messagebird::Recipient.new(item(i))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,74 +1,55 @@
|
|
1
1
|
# rubocop:disable Metrics/AbcSize
|
2
2
|
# rubocop:disable MethodLength
|
3
3
|
require 'json'
|
4
|
-
module
|
5
|
-
|
6
|
-
class
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Date.parse(@scheduled_datetime) unless @scheduled_datetime.nil?
|
42
|
-
end
|
43
|
-
|
44
|
-
def created_datetime
|
45
|
-
Date.parse(@created_datetime) unless @created_datetime.nil?
|
46
|
-
end
|
47
|
-
|
48
|
-
def recipients
|
49
|
-
OpenStruct.new(
|
50
|
-
total_count: @recipients[:totalCount],
|
51
|
-
total_sent_count: @recipients[:totalSentCount],
|
52
|
-
total_delivered_count: @recipients[:totalDeliveredCount],
|
53
|
-
items: items
|
54
|
-
|
55
|
-
) unless @recipients.nil?
|
56
|
-
end
|
4
|
+
module ActionTexter
|
5
|
+
module Messagebird
|
6
|
+
class Response
|
7
|
+
class Success
|
8
|
+
|
9
|
+
attr_reader :id,
|
10
|
+
:href,
|
11
|
+
:direction,
|
12
|
+
:type,
|
13
|
+
:originator,
|
14
|
+
:content,
|
15
|
+
:reference,
|
16
|
+
:validity,
|
17
|
+
:gateway,
|
18
|
+
:datacoding,
|
19
|
+
:mclass,
|
20
|
+
:scheduled_datetime,
|
21
|
+
:created_datetime,
|
22
|
+
:recipients
|
23
|
+
|
24
|
+
def initialize(body)
|
25
|
+
parsed_body = JSON.parse(body, symbolize_names: true)
|
26
|
+
@id = parsed_body[:id]
|
27
|
+
@href = parsed_body[:href]
|
28
|
+
@direction = parsed_body[:direction]
|
29
|
+
@type = parsed_body[:type]
|
30
|
+
@originator = parsed_body[:originator]
|
31
|
+
@content = parsed_body[:body]
|
32
|
+
@reference = parsed_body[:reference]
|
33
|
+
@validity = parsed_body[:validity]
|
34
|
+
@gateway = parsed_body[:gateway]
|
35
|
+
@datacoding = parsed_body[:datacoding]
|
36
|
+
@mclass = parsed_body[:mclass]
|
37
|
+
@scheduled_datetime = parsed_body[:scheduledDatetime]
|
38
|
+
@created_datetime = parsed_body[:createdDatetime]
|
39
|
+
@recipients = parsed_body[:recipients]
|
40
|
+
end
|
57
41
|
|
58
|
-
|
42
|
+
def scheduled_datetime
|
43
|
+
Date.parse(@scheduled_datetime) unless @scheduled_datetime.nil?
|
44
|
+
end
|
59
45
|
|
60
|
-
|
61
|
-
|
62
|
-
OpenStruct.new(item(i))
|
46
|
+
def created_datetime
|
47
|
+
Date.parse(@created_datetime) unless @created_datetime.nil?
|
63
48
|
end
|
64
|
-
end
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
status: item[:status],
|
70
|
-
status_datetime: Date.parse(item[:statusDatetime])
|
71
|
-
}
|
50
|
+
def recipients
|
51
|
+
ActionTexter::Messagbird::Recipients.new(@recipients) unless @recipients.nil?
|
52
|
+
end
|
72
53
|
end
|
73
54
|
end
|
74
55
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'class_attribute'
|
2
|
+
module ActionTexter
|
3
|
+
class TestMessage
|
4
|
+
include ClassAttribute
|
5
|
+
cattr_accessor :deliveries
|
6
|
+
self.deliveries = []
|
7
|
+
|
8
|
+
def initialize(config = {})
|
9
|
+
end
|
10
|
+
|
11
|
+
def deliver(message)
|
12
|
+
self.class.deliveries << message
|
13
|
+
deliveries
|
14
|
+
end
|
15
|
+
|
16
|
+
def truncate
|
17
|
+
self.class.deliveries = []
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/action_texter.rb
CHANGED
@@ -9,22 +9,20 @@ module ActionTexter
|
|
9
9
|
autoload :MessageDelivery, 'action_texter/message_delivery'
|
10
10
|
autoload :DeliveryMethods, 'action_texter/delivery_methods'
|
11
11
|
|
12
|
-
module Provider
|
13
|
-
module Mail
|
14
|
-
autoload :Delivery, 'action_texter/provider/mail/delivery'
|
15
|
-
end
|
16
|
-
module Messagebird
|
17
|
-
autoload :Delivery, 'action_texter/provider/messagebird/delivery'
|
18
|
-
autoload :Response, 'action_texter/provider/messagebird/response'
|
19
|
-
autoload :ErrorResponse, 'action_texter/provider/messagebird/response_error'
|
20
|
-
autoload :SuccessMessagebird, 'action_texter/provider/messagebird/response_success'
|
21
|
-
end
|
22
12
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
13
|
+
module Mail
|
14
|
+
autoload :Delivery, 'action_texter/provider/mail/delivery'
|
26
15
|
end
|
27
16
|
|
17
|
+
module Messagebird
|
18
|
+
autoload :Delivery, 'action_texter/provider/messagebird/delivery'
|
19
|
+
autoload :Response, 'action_texter/provider/messagebird/response'
|
20
|
+
autoload :ErrorResponse, 'action_texter/provider/messagebird/response_error'
|
21
|
+
autoload :SuccessMessagebird, 'action_texter/provider/messagebird/response_success'
|
22
|
+
end
|
23
|
+
|
24
|
+
autoload :TestMessage, 'action_texter/provider/test_message/test_message'
|
25
|
+
|
28
26
|
class << self
|
29
27
|
|
30
28
|
def configure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-texter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oliverzeyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -169,8 +169,10 @@ files:
|
|
169
169
|
- lib/action_texter/provider/messagebird/delivery.rb
|
170
170
|
- lib/action_texter/provider/messagebird/response.rb
|
171
171
|
- lib/action_texter/provider/messagebird/response_error.rb
|
172
|
+
- lib/action_texter/provider/messagebird/response_recipient.rp
|
173
|
+
- lib/action_texter/provider/messagebird/response_recipients.rb
|
172
174
|
- lib/action_texter/provider/messagebird/response_success.rb
|
173
|
-
- lib/action_texter/provider/test_message/
|
175
|
+
- lib/action_texter/provider/test_message/test_message.rb
|
174
176
|
- lib/action_texter/request.rb
|
175
177
|
- lib/action_texter/response.rb
|
176
178
|
- lib/action_texter/version.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'class_attribute'
|
2
|
-
module ActionTexter
|
3
|
-
module Provider
|
4
|
-
module TestMessage
|
5
|
-
class Delivery
|
6
|
-
include ClassAttribute
|
7
|
-
cattr_accessor :deliveries
|
8
|
-
self.deliveries = []
|
9
|
-
|
10
|
-
def initialize(config = {})
|
11
|
-
end
|
12
|
-
|
13
|
-
def deliver(message)
|
14
|
-
self.class.deliveries << message
|
15
|
-
deliveries
|
16
|
-
end
|
17
|
-
|
18
|
-
def truncate
|
19
|
-
self.class.deliveries = []
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|