siamese 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/siamese.rb +40 -0
- data/lib/siamese/message.rb +23 -0
- data/lib/siamese/version.rb +3 -0
- data/siamese.gemspec +28 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2e543fa8e7e3ab1a9935b09bed384b17ade1f858ea3ba14dd9fe4c375b1a23c
|
4
|
+
data.tar.gz: 9deb13870059ece66e22e17358790eb892388858115d61f607ee74538c9c0487
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6697ad02d5ffcd41c899d7ba3e1c2425da0af3324fd961760a50b2d33dc1868387267a029b8f3bbd29fcd6e1a533613c6487127cd77769a371b3decf9f316e0c
|
7
|
+
data.tar.gz: 70be6ee4b77599d0ecd979194890a32adaa4244370c8400b03f5d67f13b0ece25a759e6e39336f3e86afa9fe0793ced4f45d59ad348364cdda8b2897fe6e11ad
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Micah Geisel
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Siamese
|
2
|
+
|
3
|
+
This gem aims to provide simple SMS message sending with Twilio in Rails, broadly mimicing the ActionMailer API for familiarity.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'siamese'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Configure in an initializer:
|
16
|
+
```ruby
|
17
|
+
# config/initializers/siamese.rb
|
18
|
+
require "siamese"
|
19
|
+
|
20
|
+
Siamese.configure do |config|
|
21
|
+
config.twilio_account_sid = Rails.application.credentials[:twilio_account_sid]
|
22
|
+
config.twilio_auth_token = Rails.application.credentials[:twilio_auth_token]
|
23
|
+
config.defaults = { from: "+18008675309" }
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Make a template:
|
28
|
+
```erb
|
29
|
+
<!-- app/views/sms/example.erb -->
|
30
|
+
Hello <%= context.name %>, welcome!
|
31
|
+
```
|
32
|
+
|
33
|
+
Deliver the message:
|
34
|
+
```ruby
|
35
|
+
Siamese.example(context).deliver_now
|
36
|
+
```
|
37
|
+
|
38
|
+
Siamese expects the context to have a `#phone` method to tell it where to send the message, otherwise you can specify it with the `to:` option to the template call.
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/siamese.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "siamese"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/siamese.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "twilio-ruby"
|
2
|
+
require "siamese/message"
|
3
|
+
|
4
|
+
module Siamese
|
5
|
+
mattr_accessor(:deliveries) { [] }
|
6
|
+
mattr_accessor :twilio_account_sid, :twilio_auth_token
|
7
|
+
mattr_accessor(:defaults) { Hash.new }
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def configure
|
11
|
+
yield self
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing meth, *args, **kwargs, &block
|
15
|
+
template = "sms/#{meth}"
|
16
|
+
if ApplicationController.new.lookup_context.exists?(template)
|
17
|
+
context = args.first
|
18
|
+
options = args.second || {}
|
19
|
+
Message.new(template, context, options)
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def deliver attributes
|
26
|
+
deliveries << attributes
|
27
|
+
if Rails.env.production?
|
28
|
+
while deliveries.any?
|
29
|
+
attributes = deliveries.pop
|
30
|
+
client.api.account.messages.create(attributes)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def client
|
36
|
+
@client ||= Twilio::REST::Client.new(account_sid, auth_token)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Siamese
|
2
|
+
class Message < Struct.new(:template, :context, :options)
|
3
|
+
def deliver_now
|
4
|
+
Siamese.deliver({
|
5
|
+
from: options[:from] || Siamese.defaults[:from],
|
6
|
+
to: options[:to] || context.phone || Siamese.defaults[:to],
|
7
|
+
body: options[:body] || render,
|
8
|
+
})
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def render
|
14
|
+
body = ApplicationController.render({
|
15
|
+
template: template,
|
16
|
+
locals: { context: context },
|
17
|
+
layout: false,
|
18
|
+
})
|
19
|
+
body.strip
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/siamese.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/siamese/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "siamese"
|
5
|
+
spec.version = Siamese::VERSION
|
6
|
+
spec.authors = ["Micah Geisel"]
|
7
|
+
spec.email = ["micah@botandrose.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Send SMS messages in Rails with Twilio}
|
10
|
+
spec.homepage = "https://github.com/botandrose/siamese"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
16
|
+
# spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency "twilio-ruby"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: siamese
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micah Geisel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: twilio-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- micah@botandrose.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/console
|
42
|
+
- bin/setup
|
43
|
+
- lib/siamese.rb
|
44
|
+
- lib/siamese/message.rb
|
45
|
+
- lib/siamese/version.rb
|
46
|
+
- siamese.gemspec
|
47
|
+
homepage: https://github.com/botandrose/siamese
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata:
|
51
|
+
homepage_uri: https://github.com/botandrose/siamese
|
52
|
+
source_code_uri: https://github.com/botandrose/siamese
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.3.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.0.3
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Send SMS messages in Rails with Twilio
|
72
|
+
test_files: []
|