sms_carrier 0.1.1 → 0.1.2
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/CHANGELOG.md +4 -0
- data/README.md +65 -0
- data/lib/generators/rspec/carrier_generator.rb +11 -0
- data/lib/generators/rspec/templates/carrier_spec.rb +5 -0
- data/lib/generators/test_unit/carrier_generator.rb +11 -0
- data/lib/generators/test_unit/templates/carrier_test.rb +4 -0
- data/lib/rails/generators/carrier/USAGE +16 -0
- data/lib/rails/generators/carrier/carrier_generator.rb +25 -0
- data/lib/rails/generators/carrier/templates/application_carrier.rb +3 -0
- data/lib/rails/generators/carrier/templates/carrier.rb +11 -0
- data/lib/sms_carrier/base.rb +1 -5
- data/lib/sms_carrier/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee73ecb55b99a951d996f41eaf2929f11c19e3b9
|
4
|
+
data.tar.gz: 18404897e902d9789ce14382e79ee477f79da951
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b858afda7b224bd955e1408ccd9817063f4d5363cd1fea5111ced4b2aed217dffece2345aa1ec29f717a45effa738695d52bb640601e9bd3e30bf29518de550e
|
7
|
+
data.tar.gz: 7e02ab750c68e1d13211a37efe51cc9fbf1738230617d549e056389188cf861503fe5debc20e912a013f20977cbbcff42ef371fe7d62addb7d89668b8e3f1713
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -61,6 +61,15 @@ Or you can send SMS without carrier and template:
|
|
61
61
|
SmsCarrier::Base.sms(from: "+886987654321", to: "+886912345678", body: "Your token is #{token}, please confirm your phone number").deliver_now
|
62
62
|
```
|
63
63
|
|
64
|
+
### Deliver Later
|
65
|
+
SMS Carrier use Active Job like Action Mailer. So you can deliver SMS later, too:
|
66
|
+
```Ruby
|
67
|
+
sms.deliver_later
|
68
|
+
sms.deliver_later(wait_until: Date.tomorrow.noon)
|
69
|
+
sms.deliver_later(wait: 1.week)
|
70
|
+
```
|
71
|
+
Options are defined by Active Job, please refer to [Active Job](https://github.com/rails/rails/blob/7f18ea14c893cb5c9f04d4fda9661126758332b5/activejob/lib/active_job/enqueuing.rb#L32).
|
72
|
+
|
64
73
|
### Setting defaults
|
65
74
|
You can set up default settings in carrier by `default` method.
|
66
75
|
```Ruby
|
@@ -73,6 +82,62 @@ You can also set up in rails config, eg. `config/environments/production.rb`
|
|
73
82
|
config.sms_carrier.default_options = { from: "+886987654321" }
|
74
83
|
```
|
75
84
|
|
85
|
+
### Generators
|
86
|
+
You can run following commands to generate carriers:
|
87
|
+
|
88
|
+
rails g carrier [name] [action] [action]...
|
89
|
+
|
90
|
+
Eg
|
91
|
+
|
92
|
+
rails g carrier registration welcome
|
93
|
+
|
94
|
+
It creates a Registration carrier class and test:
|
95
|
+
```
|
96
|
+
Carrier: app/carriers/registration_carrier.rb
|
97
|
+
Test: test/carriers/registration_carrier_test.rb
|
98
|
+
or
|
99
|
+
RSpec: spec/carriers/registration_carrier_spec.rb
|
100
|
+
```
|
101
|
+
And class looks like this:
|
102
|
+
```Ruby
|
103
|
+
class RegistrationCarrier < ApplicationCarrier
|
104
|
+
def welcome
|
105
|
+
# ...
|
106
|
+
end
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
### Delivery Methods
|
111
|
+
You can also refer to the projects:
|
112
|
+
* [twilio-carrier](https://github.com/emn178/twilio-carrier): Twilio SMS service.
|
113
|
+
* [yunpian-carrier](https://github.com/emn178/yunpian-carrier): Yunpian(云片) SMS service.
|
114
|
+
* [dynamic-carrier](https://github.com/emn178/dynamic-carrier): A delivery method layer that decides the delivery method dynamically by your rules.
|
115
|
+
* [virtual_sms](https://github.com/emn178/virtual_sms): You can send SMS to a virtual SMS box instead of real SMS service in development environment.
|
116
|
+
|
117
|
+
You can implement your delivery method.
|
118
|
+
```Ruby
|
119
|
+
class MyCarrier
|
120
|
+
attr_accessor :settings
|
121
|
+
|
122
|
+
def initialize(settings)
|
123
|
+
self.settings = settings
|
124
|
+
end
|
125
|
+
|
126
|
+
def deliver!(sms)
|
127
|
+
# sms.to is Array
|
128
|
+
# my_deliver(sms.from, sms.to, sms.body)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
SmsCarrier::Base.add_delivery_method :my, MyCarrier
|
132
|
+
```
|
133
|
+
In your Rails project, you can set up in configuration:
|
134
|
+
```Ruby
|
135
|
+
config.sms_carrier.delivery_method = :my
|
136
|
+
config.sms_carrier.my_settings = {
|
137
|
+
:settings => :pass_to_initialize
|
138
|
+
}
|
139
|
+
```
|
140
|
+
|
76
141
|
### Difference with Action Mailer
|
77
142
|
* SMS Carrier removed preview.
|
78
143
|
* SMS Carrier removed attachments feature.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rspec
|
2
|
+
module Generators
|
3
|
+
class CarrierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
5
|
+
|
6
|
+
def create_carrier_test
|
7
|
+
template 'carrier_spec.rb', File.join('spec/carriers', class_path, "#{file_name}_carrier_spec.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module TestUnit
|
2
|
+
module Generators
|
3
|
+
class CarrierGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
5
|
+
|
6
|
+
def create_carrier_test
|
7
|
+
template 'carrier_test.rb', File.join('test/carriers', class_path, "#{file_name}_carrier_test.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
============
|
3
|
+
Stubs out a new carrier and its views. Passes the carrier name, either
|
4
|
+
CamelCased or under_scored, and an optional list of emails as arguments.
|
5
|
+
|
6
|
+
This generates a carrier class in app/carriers and invokes your template
|
7
|
+
engine and test framework generators.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
========
|
11
|
+
rails generate carrier Notifications signup forgot_password invoice
|
12
|
+
|
13
|
+
creates a Notifications carrier class and test:
|
14
|
+
Carrier: app/carriers/notifications_carrier.rb
|
15
|
+
Test: test/carriers/notifications_carrier_test.rb
|
16
|
+
Rspec: spec/carriers/notifications_carrier_spec.rb
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class CarrierGenerator < NamedBase
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
7
|
+
|
8
|
+
check_class_collision suffix: "Carrier"
|
9
|
+
|
10
|
+
def create_carrier_file
|
11
|
+
template "carrier.rb", File.join('app/carriers', class_path, "#{file_name}_carrier.rb")
|
12
|
+
if self.behavior == :invoke
|
13
|
+
template "application_carrier.rb", 'app/carriers/application_carrier.rb'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
hook_for :test_framework
|
18
|
+
|
19
|
+
protected
|
20
|
+
def file_name
|
21
|
+
@_file_name ||= super.gsub(/\_carrier/i, '')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/sms_carrier/base.rb
CHANGED
@@ -275,11 +275,7 @@ module SmsCarrier
|
|
275
275
|
templates_name = options.delete(:template_name) || action_name
|
276
276
|
|
277
277
|
template = lookup_context.find(templates_name, templates_path)
|
278
|
-
|
279
|
-
raise ActionView::MissingTemplate.new(templates_path, templates_name, templates_path, false, 'carrier')
|
280
|
-
else
|
281
|
-
return render(template: template)
|
282
|
-
end
|
278
|
+
return render(template: template)
|
283
279
|
end
|
284
280
|
end
|
285
281
|
|
data/lib/sms_carrier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sms_carrier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chen Yi-Cyuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -110,6 +110,14 @@ files:
|
|
110
110
|
- LICENSE.txt
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
113
|
+
- lib/generators/rspec/carrier_generator.rb
|
114
|
+
- lib/generators/rspec/templates/carrier_spec.rb
|
115
|
+
- lib/generators/test_unit/carrier_generator.rb
|
116
|
+
- lib/generators/test_unit/templates/carrier_test.rb
|
117
|
+
- lib/rails/generators/carrier/USAGE
|
118
|
+
- lib/rails/generators/carrier/carrier_generator.rb
|
119
|
+
- lib/rails/generators/carrier/templates/application_carrier.rb
|
120
|
+
- lib/rails/generators/carrier/templates/carrier.rb
|
113
121
|
- lib/sms_carrier.rb
|
114
122
|
- lib/sms_carrier/base.rb
|
115
123
|
- lib/sms_carrier/delivery_job.rb
|