sendable_rails 0.2.0 → 0.3.0

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: f8d50a75f166eadfbd955b0036f6267889f39613
4
- data.tar.gz: 8af4aa8d5308bf41f8e4e277e51a004a214d5ebd
3
+ metadata.gz: 8e7a7b7072278d02807d8013a0b7968f0b45a800
4
+ data.tar.gz: ecd2478ca8c0e4311d25ec1bdf37aaf4b12bcdf8
5
5
  SHA512:
6
- metadata.gz: 5ea541928c19560789624d4528a30b8018106dcd756ea5ff6e4de6a4ffb197fd7a63cf38fe9f8e5d1d98d20fe3f582d77cb8be95a73f67e72db233d44dfc6dd4
7
- data.tar.gz: 37fe0658e9f719e594380b8ed0f5452cfbc39e3d3bc37fe2bcec9cdb26642367a5d458b5902c18f3c0fbe2e06000160e2ecd5414a6153783ed8aee0b8e6f60a0
6
+ metadata.gz: 3d803428c4deaf0a5b7ffabc18cdcc629a8fe9915957b12792a553640d759637584e4276c2ef42aa9ab35fce0efddb97eda55819ac45f222d30cf8f3365ab9fe
7
+ data.tar.gz: e015e31307e7315adb04529350e71f1bbcb9875cbce68ac784024814e1e079ceca7760a7f3ad0963f35e07a813f947c2722303c57d813fdf4f4d7ff44a9308cb
@@ -1,56 +1,20 @@
1
- require 'net/http'
2
- require 'uri'
3
- require 'json'
1
+ require 'sendable'
4
2
 
5
3
  module SendableRails
6
- module ActionMailerExt
7
- def collect_responses(headers)
8
- if sendable = headers.delete(:sendable)
9
- project_id = SendableRails.config.project_id
10
- api_key = SendableRails.config.api_key
11
-
12
- uri = URI("https://api.sendable.io/v1/project/#{project_id}/template/#{sendable[:template_id]}/render")
13
-
14
- assigns = {}
15
- instance_variables.each do |key|
16
- if match = key.to_s.match(/@([^\_]+)/)
17
- assigns[match[1]] = instance_variable_get(match[0])
18
- end
19
- end
20
-
21
- params = {
22
- assigns: assigns,
23
- }
24
-
25
- headers = {
26
- 'Authorization': "ApiKey #{api_key}",
27
- }
28
-
29
- http = Net::HTTP.new(uri.host, uri.port)
30
- http.use_ssl = true
31
-
32
- request = Net::HTTP::Post.new(uri.request_uri, headers)
33
- request.set_form_data(params)
34
- response = http.request(request)
35
-
36
- email = JSON.parse(response.body)
37
-
38
- formats = []
39
-
40
- if (email['html'])
41
- formats << { content_type: 'text/html', body: email['html'] }
4
+ module ActionMailerWithSendable
5
+ def sendable_mail(params = {})
6
+ template_id = params.delete(:template_id)
7
+
8
+ assigns = {}
9
+ instance_variables.each do |key|
10
+ if match = key.to_s.match(/@([^\_]+)/)
11
+ assigns[match[1]] = instance_variable_get(match[0])
42
12
  end
43
-
44
- if (email['plain'])
45
- formats << { content_type: 'text/plain', body: email['text'] }
46
- end
47
-
48
- formats
49
- else
50
- super
51
13
  end
14
+
15
+ Sendable.client.email(template_id, params.merge(assigns: assigns))
52
16
  end
53
17
  end
54
18
  end
55
19
 
56
- ActionMailer::Base.send(:prepend, SendableRails::ActionMailerExt)
20
+ ActionMailer::Base.send(:prepend, SendableRails::ActionMailerWithSendable)
@@ -1,9 +1,11 @@
1
+ require 'sendable'
2
+
1
3
  module SendableRails
2
4
  class Railtie < Rails::Railtie
3
5
  config.sendable = ActiveSupport::OrderedOptions.new
4
6
 
5
7
  initializer "sendable.configure" do |app|
6
- SendableRails.config do |config|
8
+ Sendable.config do |config|
7
9
  if app.config.sendable[:project_id]
8
10
  config.project_id = app.config.sendable[:project_id]
9
11
  end
@@ -1,3 +1,3 @@
1
1
  module SendableRails
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -2,40 +2,4 @@ require "sendable_rails/action_mailer_ext"
2
2
  require "sendable_rails/railtie"
3
3
 
4
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
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendable_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Umair Siddique
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sendable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.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.1.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement