sendable_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2eccfeeb86dea973b1ddcd6273f5e685b6883976
4
+ data.tar.gz: 9c361d133be2d7d9a21a502b8929b0ac48698c96
5
+ SHA512:
6
+ metadata.gz: a4dd8b70afdf2cf8a89b2f81dd3ee93e4eb9755342c90c60d625dfafa50350a814d7060f0811e820fcaaa964e42be8e05c25e79b5386a51694e1cac4518c1d2b
7
+ data.tar.gz: 44b41da40390a61b8ff6acf5159cfb1e8c7a175d469490a74578682b52240088519e19d3d3595034ace73983205dc81a2cc11869a56947e4b2dbadd1c48c9f2a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Umair Siddique
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # SendableRails
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'sendable_rails'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install sendable_rails
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SendableRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,41 @@
1
+ require "sendable_rails/action_mailer_ext"
2
+ require "sendable_rails/railtie"
3
+
4
+ module SendableRails
5
+ class << self
6
+ attr_accessor :config
7
+ end
8
+
9
+ def self.config
10
+ @config ||= Config.new
11
+
12
+ if block_given?
13
+ yield @config
14
+ else
15
+ @config
16
+ end
17
+ end
18
+
19
+ class Config
20
+ attr_accessor :project_id
21
+ attr_accessor :api_key
22
+
23
+ def initialize
24
+ set_defaults
25
+ end
26
+
27
+ def set_defaults
28
+ if ENV.has_key?("SENDABLE_PROJECT_ID")
29
+ @project_id = ENV["SENDABLE_PROJECT_ID"]
30
+ else
31
+ @project_id = nil
32
+ end
33
+
34
+ if ENV.has_key?("SENDABLE_API_KEY")
35
+ @api_key = ENV["SENDABLE_API_KEY"]
36
+ else
37
+ @api_key = ""
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module SendableRails
5
+ module ActionMailerExt
6
+ def collect_responses(headers)
7
+ if sendable = headers.delete(:sendable)
8
+ project_id = SendableRails.config.project_id
9
+ api_key = SendableRails.config.api_key
10
+
11
+ uri = URI("https://api.sendable.io/v1/project/#{project_id}/template/#{sendable[:template_id]}/render")
12
+
13
+ assigns = {}
14
+ instance_variables.each do |key|
15
+ if match = key.to_s.match(/@([^\_]+)/)
16
+ assigns[match[1]] = instance_variable_get(match[0])
17
+ end
18
+ end
19
+
20
+ params = {
21
+ assigns: assigns,
22
+ }
23
+
24
+ headers = {
25
+ 'Authorization': "ApiKey #{api_key}",
26
+ }
27
+
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = true
30
+
31
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
32
+ request.set_form_data(params)
33
+ response = http.request(request)
34
+
35
+ content = response.body
36
+
37
+ [{
38
+ content: content
39
+ }]
40
+ else
41
+ super
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ ActionMailer::Base.send(:prepend, SendableRails::ActionMailerExt)
@@ -0,0 +1,12 @@
1
+ module SendableRails
2
+ class Railtie < Rails::Railtie
3
+ config.sendable = ActiveSupport::OrderedOptions.new
4
+
5
+ initializer "sendable.configure" do |app|
6
+ SendableRails.config do |config|
7
+ config.project_id = app.config.sendable[:project_id]
8
+ config.api_key = app.config.sendable[:api_key]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module SendableRails
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sendable_rails do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendable_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Umair Siddique
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-01 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: '5.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.1.3
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.1.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Sendable delivery method for ActionMailer.
48
+ email:
49
+ - umairsiddique@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - lib/sendable_rails.rb
58
+ - lib/sendable_rails/action_mailer_ext.rb
59
+ - lib/sendable_rails/railtie.rb
60
+ - lib/sendable_rails/version.rb
61
+ - lib/tasks/sendable_rails_tasks.rake
62
+ homepage: https://github.com/sendable/sendable_rails
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.6.13
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Sendable delivery method for ActionMailer.
86
+ test_files: []