twilivery 0.0.1
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/lib/twilivery.rb +30 -0
- data/lib/twilivery/delivery_method.rb +67 -0
- data/lib/twilivery/exceptions.rb +4 -0
- data/lib/twilivery/railtie.rb +9 -0
- data/lib/twilivery/version.rb +4 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4d78575236c9c655473972faf1962f147235116f
|
4
|
+
data.tar.gz: 3eb1273f24b22a9f477e405b19aeba438c318b8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9505b017ea5672a6be38f78070fb73e840de44fde90f84122c1566b76b3a382bc38739070baf11af62db27278bb2a120a3bdcfd8eedf46842d8585b28b023353
|
7
|
+
data.tar.gz: 505be969d6e4065941711d1048c0ff1215760e84796cf81406085894e2b61830ac9b41f74b8972b0cb4f6086e5bb24c2fdbe04c1be7f55a0f6e4c7bbe5d9fb52
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jesse Curry
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/lib/twilivery.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "twilivery/delivery_method"
|
2
|
+
require "twilivery/exceptions"
|
3
|
+
require "twilivery/railtie"
|
4
|
+
|
5
|
+
module Twilivery
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
self.configuration ||= Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :account_sid
|
17
|
+
attr_accessor :auth_token
|
18
|
+
attr_accessor :default_sms_sender
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
set_defaults
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_defaults
|
25
|
+
@account_sid = ENV.fetch('TWILIO_ACCOUNT_SID') { '' }
|
26
|
+
@auth_token = ENV.fetch('TWILIO_AUTH_TOKEN') { nil }
|
27
|
+
@default_sms_sender = ENV.fetch('TWILIO_SMS_SENDER') { nil }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Twilivery
|
2
|
+
class DeliveryMethod
|
3
|
+
require 'twilio-ruby'
|
4
|
+
|
5
|
+
attr_accessor :settings, :data, :response, :headers
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@settings = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def deliver!(mail)
|
12
|
+
message = prepare_message_from mail
|
13
|
+
|
14
|
+
if message[:to].empty?
|
15
|
+
raise Twilivery::DeliveryException, {}
|
16
|
+
else
|
17
|
+
post_sms_message message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
###########################################################################
|
22
|
+
private
|
23
|
+
|
24
|
+
def twilio
|
25
|
+
@twilio ||= Twilio::REST::Client.new(Twilivery.configuration.account_sid, Twilivery.configuration.auth_token)
|
26
|
+
end
|
27
|
+
|
28
|
+
def post_sms_message message
|
29
|
+
message[:to].each do |recipient|
|
30
|
+
twilio.messages.create(
|
31
|
+
from: message[:from],
|
32
|
+
to: recipient,
|
33
|
+
body: message[:body]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_message_from mail
|
39
|
+
message = {}
|
40
|
+
|
41
|
+
# Sender
|
42
|
+
message[:from] = mail.from.first || Twilivery.configuration.default_sms_sender
|
43
|
+
|
44
|
+
# Recipients
|
45
|
+
message[:to] = prepare_recipients(mail.to)
|
46
|
+
message[:to] += prepare_recipients(mail.cc).flatten unless mail.cc.nil?
|
47
|
+
message[:to] += prepare_recipients(mail.bcc).flatten unless mail.bcc.nil?
|
48
|
+
|
49
|
+
# Body
|
50
|
+
if mail.text_part
|
51
|
+
message[:body] = cleanse_encoding(mail.text_part.body.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
message
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_recipients recipients
|
58
|
+
recipients = [recipients] unless recipients.is_a?(Array)
|
59
|
+
recipients
|
60
|
+
end
|
61
|
+
|
62
|
+
def cleanse_encoding content
|
63
|
+
::JSON.parse({c: content}.to_json)["c"]
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Twilivery
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer "twilivery.add_delivery_method" do
|
4
|
+
ActiveSupport.on_load :action_mailer do
|
5
|
+
ActionMailer::Base.add_delivery_method :twilivery, Twilivery::DeliveryMethod, return_response: true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twilivery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesse Curry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: twilio-ruby
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 4.11.1
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 4.11.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.4.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.4.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.24.2
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.24.2
|
75
|
+
description: Delivery Method for Rails ActionMailer to send SMS messages using the
|
76
|
+
Twilio API
|
77
|
+
email:
|
78
|
+
- jesse@jessecurry.net
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- lib/twilivery.rb
|
86
|
+
- lib/twilivery/delivery_method.rb
|
87
|
+
- lib/twilivery/exceptions.rb
|
88
|
+
- lib/twilivery/railtie.rb
|
89
|
+
- lib/twilivery/version.rb
|
90
|
+
homepage: https://github.com/jessecurry/twilivery
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Twilivery for Rails
|
114
|
+
test_files: []
|