monkey-mailer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjViOWIzNTk3ZGEyMWFhMTFhNTE5NTA2NTI4ZWE4MDNiMmQ4MDU5Yw==
5
- data.tar.gz: !binary |-
6
- YTViODJjZjExZWRmMjM0YzljMjQwZThjYjZhZGNmOGEzMTRhZGNiYQ==
2
+ SHA1:
3
+ metadata.gz: 4bdbc0d56b239046873ca0b876eaee460143425b
4
+ data.tar.gz: 9ceeada2540368ed1035b4add76197163e26842b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NjkwNzJlODAzZDVhZWNlYjMxMzI2OWQ0OGE0MjA5NmRkNmVjYmVlMzgxMDk1
10
- OTJhZWM0ZTk4MTNjZjRmMWE0MzM5Y2M1MDk2MTQxNTkwOTg1Y2VhNTk1MTMw
11
- NjU3YjdiYmUzY2QzOWViMTNkYWYzMWY3NTU2YmY2OGRkMjVlYjk=
12
- data.tar.gz: !binary |-
13
- YmUxYTg4MDRjZjM2MmUzMjIzZTZmYWE2NzY1MTg4OGM0OWMzZGMxYjM2ZmMy
14
- YWM1NjFjNjU1NWZkY2FhODljZTY5NDg4MDBjMWNjMWU0YjI1MWQzYjA4OGM2
15
- OWM3MTM2YjQyNTlmOTliNTNhMzAyODAxYzNjMjdmZWU3ZWMwMjE=
6
+ metadata.gz: 35fcff5458819a9de1d533a0a41345ff805a409877c38114ea73f167d668e1a3cd1bcb7e04efcb40bbfc70d2da8967440ad2e120c5ca35080329f7a4d72026b6
7
+ data.tar.gz: 6d8510d9388c20039581c1497fac374ea9c004d992eef9df8c0bb9a8912cc8653965930bd0c61e6c4fd3940c77130854626f5716936c9dc85dd3bcdfc35a35df
@@ -1,33 +1,32 @@
1
1
  require "net/http"
2
2
  require "uri"
3
3
  require "json"
4
+ require 'base64'
4
5
 
5
6
  module MonkeyMailer
6
7
  module Adapters
7
8
  class MandrilAPI
8
- @key = ''
9
- @request = {}
10
- @uri = ''
11
9
 
12
- ENDPOINT = 'https://mandrillapp.com/api/1.0'
10
+ @key = ''
13
11
 
14
12
  def initialize(options)
15
13
  @key = options[:mandril_api_key]
16
- @request = Hash.new
17
- @uri = URI.parse(URI.encode(ENDPOINT))
18
14
  end
19
15
 
20
16
  def send_email(email)
21
17
 
22
- @request = {
23
- :key => '',
18
+ request_body = {
19
+ :key => @key,
24
20
  :message => {
25
- :html => '',
26
- :text => '',
27
- :subject => '',
28
- :from_email => '',
29
- :from_name => '',
30
- :to => [],
21
+ :to => [{
22
+ :email => email.to_email,
23
+ :name => email.to_name
24
+ }],
25
+ :from_name => email.from_name,
26
+ :from_email => email.from_email,
27
+ :subject => email.subject,
28
+ :html => email.body,
29
+ :text => email.body.to_s.gsub(/<\/?[^>]*>/, ""),
31
30
  :headers => {},
32
31
  :track_opens => true,
33
32
  :track_clicks => true,
@@ -35,24 +34,28 @@ module MonkeyMailer
35
34
  :url_strip_qs => true,
36
35
  :preserve_recipients => false,
37
36
  :bcc_address => '',
37
+ :attachments => []
38
38
  },
39
- :async => true
39
+ :async => false
40
40
  }
41
41
 
42
- @request[:key] = @key
43
- @request[:message][:to] << { :email => email.to_email, :name => email.to_name}
44
- @request[:message][:from_name] = email.from_name
45
- @request[:message][:from_email] = email.from_email
46
- @request[:message][:html] = email.body
47
- @request[:message][:text] = email.body.gsub(/<\/?[^>]*>/, "") unless email.body.nil?
48
- @request[:message][:subject] = email.subject
49
-
50
- req = Net::HTTP::Post.new('/api/1.0/messages/send.json', initheader = {'Content-Type' =>'application/json'})
51
- req.body = @request.to_json
42
+ email.attachments.each do |attachment|
43
+ request_body[:message][:attachments] << {
44
+ :type => attachment.content_type,
45
+ :name => File.basename(attachment.file_path),
46
+ :content => Base64.encode64(File.read(attachment.file_path))
47
+ }
48
+ end
52
49
 
53
- http = Net::HTTP.new(@uri.host, @uri.port)
50
+ uri = URI('https://mandrillapp.com')
51
+ http = Net::HTTP.new(uri.host, uri.port)
54
52
  http.use_ssl = true
55
- response = http.start {|http| http.request(req)}
53
+
54
+ request = Net::HTTP::Post.new('/api/1.0/messages/send.json', initheader = {'Content-Type' =>'application/json'})
55
+ request.body = request_body.to_json
56
+
57
+ response = http.start {|http| http.request(request)}
58
+
56
59
  raise MonkeyMailer::DeliverError.new("Mandril response.code not equal to 200") unless response.code.to_i == 200
57
60
  puts "Response #{response.code} #{response.message}: #{response.body}"
58
61
  end
@@ -24,6 +24,10 @@ module MonkeyMailer
24
24
  from "#{email.from_name} <#{email.from_email}>"
25
25
  subject email.subject
26
26
 
27
+ email.attachments.each do |attachment|
28
+ add_file :filename => File.basename(attachment.file_path), :content => File.read(attachment.file_path)
29
+ end
30
+
27
31
  html_part do
28
32
  content_type 'text/html; charset=UTF-8'
29
33
  body email.body
@@ -1,12 +1,28 @@
1
1
  module MonkeyMailer
2
2
  class Email
3
3
 
4
- attr_accessor :priority, :to_email, :to_name, :from_email, :from_name, :body, :subject
4
+ attr_accessor :priority, :to_email, :to_name, :from_email, :from_name, :body, :subject, :attachments
5
5
 
6
6
  def initialize(hash=nil)
7
+ self.attachments = []
7
8
  unless hash.nil?
9
+ new_attachments = [hash.delete(:attachments)].flatten.compact
10
+ new_attachments.each do |attachment_hash|
11
+ self.attachments << Attachment.new(attachment_hash)
12
+ end
13
+
8
14
  hash.each_pair{|key, value| self.send("#{key}=", value)}
9
15
  end
10
16
  end
17
+
18
+ class Attachment
19
+ attr_accessor :file_path, :content_type
20
+
21
+ def initialize(hash=nil)
22
+ unless hash.nil?
23
+ hash.each_pair{|key, value| self.send("#{key}=", value)}
24
+ end
25
+ end
26
+ end
11
27
  end
12
28
  end
@@ -7,8 +7,14 @@ module MonkeyMailer::Loaders
7
7
  def find_emails(priority, quota)
8
8
  emails = []
9
9
  quota.times do
10
- emails << MonkeyMailer::Email.new(:priority => priority, :to_email => 'info@example.com', :to_name => 'Example user',
11
- :from_email => 'noreply@example.com', :from_name => 'No reply', :subject => 'Lorem ipsum', :body => '')
10
+ emails << MonkeyMailer::Email.new(
11
+ :priority => priority,
12
+ :to_email => 'info@example.com',
13
+ :to_name => 'Example user',
14
+ :from_email => 'noreply@example.com',
15
+ :from_name => 'No reply',
16
+ :subject => 'Lorem ipsum',
17
+ :body => '')
12
18
  end
13
19
  emails
14
20
  end
@@ -1,3 +1,3 @@
1
1
  module MonkeyMailer
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency 'clap', '>= 1.0.0'
20
- spec.add_dependency 'fallen', '>= 0.0.2'
21
- spec.add_dependency 'mail', '>= 2.4.4'
22
- spec.add_development_dependency 'rspec', '>= 2.12.0'
19
+ spec.add_dependency 'clap', '~> 1.0', '>= 1.0.0'
20
+ spec.add_dependency 'fallen', '~> 0.0', '>= 0.0.3'
21
+ spec.add_dependency 'mail', '~> 2.4','>= 2.4.4'
22
+ spec.add_development_dependency 'rspec', '~> 2.12', '>= 2.12.0'
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lautaro Orazi
@@ -9,62 +9,86 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-27 00:00:00.000000000 Z
12
+ date: 2014-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clap
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ - - '>='
19
22
  - !ruby/object:Gem::Version
20
23
  version: 1.0.0
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - ! '>='
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
31
+ - - '>='
26
32
  - !ruby/object:Gem::Version
27
33
  version: 1.0.0
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: fallen
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
- - - ! '>='
38
+ - - ~>
33
39
  - !ruby/object:Gem::Version
34
- version: 0.0.2
40
+ version: '0.0'
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.3
35
44
  type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
38
47
  requirements:
39
- - - ! '>='
48
+ - - ~>
49
+ - !ruby/object:Gem::Version
50
+ version: '0.0'
51
+ - - '>='
40
52
  - !ruby/object:Gem::Version
41
- version: 0.0.2
53
+ version: 0.0.3
42
54
  - !ruby/object:Gem::Dependency
43
55
  name: mail
44
56
  requirement: !ruby/object:Gem::Requirement
45
57
  requirements:
46
- - - ! '>='
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '2.4'
61
+ - - '>='
47
62
  - !ruby/object:Gem::Version
48
63
  version: 2.4.4
49
64
  type: :runtime
50
65
  prerelease: false
51
66
  version_requirements: !ruby/object:Gem::Requirement
52
67
  requirements:
53
- - - ! '>='
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '2.4'
71
+ - - '>='
54
72
  - !ruby/object:Gem::Version
55
73
  version: 2.4.4
56
74
  - !ruby/object:Gem::Dependency
57
75
  name: rspec
58
76
  requirement: !ruby/object:Gem::Requirement
59
77
  requirements:
60
- - - ! '>='
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '2.12'
81
+ - - '>='
61
82
  - !ruby/object:Gem::Version
62
83
  version: 2.12.0
63
84
  type: :development
64
85
  prerelease: false
65
86
  version_requirements: !ruby/object:Gem::Requirement
66
87
  requirements:
67
- - - ! '>='
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '2.12'
91
+ - - '>='
68
92
  - !ruby/object:Gem::Version
69
93
  version: 2.12.0
70
94
  description: Ruby email queueing system with priority handling
@@ -93,7 +117,7 @@ files:
93
117
  - monkey-mailer.gemspec
94
118
  - spec/adapter_spec.rb
95
119
  - spec/loader_spec.rb
96
- - spec/postman_spec.rb
120
+ - spec/monkey_mailer_spec.rb
97
121
  - spec/spec_helper.rb
98
122
  - spec/support/angry_adapter.rb
99
123
  - spec/support/email_faker.rb
@@ -109,24 +133,24 @@ require_paths:
109
133
  - lib
110
134
  required_ruby_version: !ruby/object:Gem::Requirement
111
135
  requirements:
112
- - - ! '>='
136
+ - - '>='
113
137
  - !ruby/object:Gem::Version
114
138
  version: '0'
115
139
  required_rubygems_version: !ruby/object:Gem::Requirement
116
140
  requirements:
117
- - - ! '>='
141
+ - - '>='
118
142
  - !ruby/object:Gem::Version
119
143
  version: '0'
120
144
  requirements: []
121
145
  rubyforge_project:
122
- rubygems_version: 2.1.11
146
+ rubygems_version: 2.2.2
123
147
  signing_key:
124
148
  specification_version: 4
125
149
  summary: Ruby email queueing system with priority handling
126
150
  test_files:
127
151
  - spec/adapter_spec.rb
128
152
  - spec/loader_spec.rb
129
- - spec/postman_spec.rb
153
+ - spec/monkey_mailer_spec.rb
130
154
  - spec/spec_helper.rb
131
155
  - spec/support/angry_adapter.rb
132
156
  - spec/support/email_faker.rb