action-texter 0.2.0.pre → 0.2.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cea093bbb16240a1e70407f1551044dddd2884f7
4
- data.tar.gz: ba9a6f767cd07ff9ecc626742b81eeb57435d797
3
+ metadata.gz: 3365998189231761f4c8d7a5d15ac96bd8a4b13d
4
+ data.tar.gz: 9edb21e259152ac8557be7c4664ac2a877418006
5
5
  SHA512:
6
- metadata.gz: 5156997c15eeb5f73808d2073e8f97e7634d7778f2d17e291c06f9895da080e34534d02852ac7a3efade471db268bccd5357d9e305df239301829a3cee19c580
7
- data.tar.gz: a337e79222dac9079053ae5142bd569808eba1bc3f408c7c85a0d55b31f447460588f4222afeb8c2006b77413b0df1001e5badad6c04f5f797eac06b19dd2fbb
6
+ metadata.gz: 1d78b996d9ca7b094b2b6dd3b218be54b3b9993ac2033696608e3f8839ede40b1dfbc9d2248a4f2713709d30d0c828f020de2f2af0c80641e29f1e8ebcde7db7
7
+ data.tar.gz: e9ecd898ee8d64ddd7c75454ef2258c7efd7b425e4f5b05e5d62e9422519f59ee4c30e1ec9020451c48b26069b2aa008a4b732abde1b3915c0ce409b3ada1271
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action-texter (0.2.0.pre)
4
+ action-texter (0.2.1.pre)
5
5
  class_attribute (~> 0.1)
6
6
  facets (~> 3.0)
7
7
  json
@@ -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::Provider::TestMessage::Delivery
25
- add_delivery_method :messagebird, ActionTexter::Provider::Messagebird::Delivery, { endpoint: 'https://rest.messagebird.com', path: '/messages' }
26
- add_delivery_method :mail, ActionTexter::Provider::Mail::Delivery, { charset: 'utf8' }
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::Provider::TestMessage::Delivery
38
- delegate :deliveries= => ActionTexter::Provider::TestMessage::Delivery
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:
@@ -7,7 +7,7 @@ module ActionTexter
7
7
  module VERSION
8
8
  MAJOR = 0
9
9
  MINOR = 2
10
- TINY = 0
10
+ TINY = 1
11
11
  PRE = 'pre'
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -1,30 +1,28 @@
1
1
  require 'mail'
2
2
  module ActionTexter
3
- module Provider
4
- module Mail
5
- class Delivery
6
-
7
- def initialize(settings = {})
8
- @charset = settings[:charset]
9
- end
3
+ module Mail
4
+ class Delivery
5
+
6
+ def initialize(settings = {})
7
+ @charset = settings[:charset]
8
+ end
10
9
 
11
- def deliver(message)
10
+ def deliver(message)
12
11
 
13
- mail = ::Mail.new do |mail|
14
- from message.from
15
- to message.to
16
- cc message.cc
17
- subject message.subject
18
- body message.body.to_s
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
- self.charset = @charset
21
- end
19
+ self.charset = @charset
20
+ end
22
21
 
23
- #LOGGER.info(mail.body)
22
+ #LOGGER.info(mail.body)
24
23
 
25
- mail.deliver!
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 Provider
4
- module Messagebird
5
- class Delivery
6
- attr_accessor :body
7
- attr_reader :response
3
+ module Messagebird
4
+ class Delivery
5
+ attr_accessor :body
6
+ attr_reader :response
8
7
 
9
- def initialize(settings)
10
- @endpoint = settings[:endpoint]
11
- @path = settings[:path]
12
- end
8
+ def initialize(settings)
9
+ @endpoint = settings[:endpoint]
10
+ @path = settings[:path]
11
+ end
13
12
 
14
- def deliver message
15
- uri = URI.parse( @endpoint )
16
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
17
- @response = Response.new(http.post(@path, to_json(message), 'Authorization' => "AccessKey #{ActionTexter.config.product_token}", 'Content-Type' => 'application/json'))
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
- def to_json message
23
- JSON.generate(recipients: message.to,
24
- originator: message.from,
25
- body: message.body)
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 Provider
3
- module Messagebird
4
-
5
- class Response
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
- def initialize(net_http_response)
9
- @net_http_response = net_http_response
10
- @body = @net_http_response.body
11
- @code = @net_http_response.code
12
- end
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
- def success?
15
- code.to_i == 201
16
- end
13
+ def success?
14
+ code.to_i == 201
15
+ end
17
16
 
18
- def failure?
19
- !success?
20
- end
17
+ def failure?
18
+ !success?
19
+ end
21
20
 
22
- def body
23
- if success?
24
- SuccessResponse.new(@body)
25
- else
26
- ErrorResponse.new(@body)
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 Provider
4
- module Messagebird
5
- class ErrorResponse
3
+ module Messagebird
4
+ class ErrorResponse
6
5
 
7
- attr_reader :code, :description
6
+ attr_reader :code, :description
8
7
 
9
- ERROR_CODES = {
10
- 2 => 'Request not allowed',
11
- 9 => 'Missing params',
12
- 10 => 'Invalid params',
13
- 20 => 'Not found',
14
- 25 => 'Not enough balance',
15
- 98 => 'API not found',
16
- 99 => 'Internal error'
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
- def initialize(error)
20
- @errors = JSON.parse(error, symbolize_names: true)[:errors]
21
- end
18
+ def initialize(error)
19
+ @errors = JSON.parse(error, symbolize_names: true)[:errors]
20
+ end
22
21
 
23
- def errors
24
- @errors.map { |e| e.merge(error_message: ERROR_CODES[e[:code]]) }
25
- end
22
+ def errors
23
+ @errors.map { |e| e.merge(error_message: ERROR_CODES[e[:code]]) }
24
+ end
26
25
 
27
- def count
28
- @errors.count
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 MessagebirdTexter
5
- class Response
6
- class Body
7
- attr_reader :id,
8
- :href,
9
- :direction,
10
- :type,
11
- :originator,
12
- :content,
13
- :reference,
14
- :validity,
15
- :gateway,
16
- :datacoding,
17
- :mclass,
18
- :scheduled_datetime,
19
- :created_datetime,
20
- :recipients
21
-
22
- def initialize(body)
23
- parsed_body = JSON.parse(body, symbolize_names: true)
24
- @id = parsed_body[:id]
25
- @href = parsed_body[:href]
26
- @direction = parsed_body[:direction]
27
- @type = parsed_body[:type]
28
- @originator = parsed_body[:originator]
29
- @content = parsed_body[:body]
30
- @reference = parsed_body[:reference]
31
- @validity = parsed_body[:validity]
32
- @gateway = parsed_body[:gateway]
33
- @datacoding = parsed_body[:datacoding]
34
- @mclass = parsed_body[:mclass]
35
- @scheduled_datetime = parsed_body[:scheduledDatetime]
36
- @created_datetime = parsed_body[:createdDatetime]
37
- @recipients = parsed_body[:recipients]
38
- end
39
-
40
- def scheduled_datetime
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
- private
42
+ def scheduled_datetime
43
+ Date.parse(@scheduled_datetime) unless @scheduled_datetime.nil?
44
+ end
59
45
 
60
- def items
61
- @recipients[:items].map do |i|
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
- def item(item)
67
- {
68
- recipient: item[:recipient],
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
- module TestMessage
24
- autoload :Delivery, 'action_texter/provider/test_message/delivery'
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.0.pre
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 00:00:00.000000000 Z
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/delivery.rb
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