sendcloud-mailer 0.1.0 → 0.1.1

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: 9747b14f89fe2bc2725fb62ff673f2fc6034e793
4
- data.tar.gz: 1d05a70deb241bd2f02240b6e241ffdcf736d76d
3
+ metadata.gz: 63d2c522c2d3c92ea6088c10e05900b256345434
4
+ data.tar.gz: 610da6bd64f69c570f2ba3c6438ef036eb21428f
5
5
  SHA512:
6
- metadata.gz: 1d6bf091b8a44b61b7b8c0f471528f87694e82082633d8a629ef4a72a5ccfc83839e2983e4d1c68ade4a79067dff91af8e1421dc88a468d32e3e783394727af1
7
- data.tar.gz: 26ae7aebb40c6585f2d1a96dfec9fb6d3d2170e2ea1744c739184e82c60b2653efcd3aabdeadd6f32b47defd828bcdfb3cab366db09687138b6c01d9dfa3dac6
6
+ metadata.gz: f154355b8c697a7b0ed239e98ab952745677b6e2036354e5f5948a92c6330d98032208e2da2bf466c5ccd2894024dd9c204a141a95e2da4a363b8062f3f107bd
7
+ data.tar.gz: 3636ffc67cca86978bec151f73e601eed3eb3c121bf5672bdcc4dabde319c81d907e61b28cc4b917d8a62b64a2050387503179264ae3ec3e6ad01b6ca057f8fd
data/.travis.yml CHANGED
@@ -2,3 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
4
  before_install: gem install bundler -v 1.10.6
5
+ branches:
6
+ only:
7
+ - master
8
+ env:
9
+ - COVERALLS=1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.1 / 2016-03-20
2
+
3
+ Release project
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Chen Yi-Cyuan
3
+ Copyright (c) 2015-2016 Chen, Yi-Cyuan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # Sendcloud::Mailer
1
+ # sendcloud-mailer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sendcloud/mailer`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://api.travis-ci.org/emn178/sendcloud-mailer.png)](https://travis-ci.org/emn178/sendcloud-mailer)
4
+ [![Coverage Status](https://coveralls.io/repos/emn178/sendcloud-mailer/badge.svg?branch=master)](https://coveralls.io/r/emn178/sendcloud-mailer?branch=master)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ An Action Mailer delivery method for SendCloud email service.
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,20 +23,26 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- 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.
30
-
31
- 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).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sendcloud-mailer.
26
+ Set up delivery method and SendCloud settings in you rails config, eg. `config/environments/production.rb`
27
+ ```Ruby
28
+ config.action_mailer.delivery_method = :sendcloud
29
+ config.action_mailer.sendcloud_settings = {
30
+ :api_user => 'USER',
31
+ :api_key => 'KEY'
32
+ }
33
+ ```
34
+ If you use SMTP, you can add this interecptor to fix the problem that SendCloud does not accept <HTML> tag.
35
+ ```Ruby
36
+ ActionMailer::Base.register_interceptor(SendcloudMailer::Interceptor)
37
+ ```
36
38
 
39
+ ## Notice
40
+ This gem is to send email by using SendCloud API, but the API can only support single attachment.
37
41
 
38
42
  ## License
39
43
 
40
44
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
45
 
46
+ ## Contact
47
+ The project's website is located at https://github.com/emn178/sendcloud-mailer
48
+ Author: Chen, Yi-Cyuan (emn178@gmail.com)
@@ -1,6 +1,7 @@
1
1
  require "action_mailer"
2
2
  require "sendcloud-mailer/version"
3
3
  require "sendcloud-mailer/base"
4
+ require "sendcloud-mailer/interceptor"
4
5
 
5
6
  module SendcloudMailer
6
7
  ActionMailer::Base.add_delivery_method :sendcloud, Base
@@ -1,3 +1,5 @@
1
+ require 'rest-client'
2
+
1
3
  module SendcloudMailer
2
4
  class Base
3
5
  attr_accessor :settings
@@ -14,14 +16,27 @@ module SendcloudMailer
14
16
  :apiKey => settings[:api_key],
15
17
  :from => from,
16
18
  :to => to,
19
+ :cc => cc,
20
+ :bcc => bcc,
17
21
  :subject => mail.subject,
18
22
  :html => html,
19
- :plain => plain
23
+ :plain => plain,
24
+ :attachments => attachments
20
25
  }
26
+ params.delete_if { |k, v| v.nil? }
27
+
28
+ result = RestClient.post( 'http://api.sendcloud.net/apiv2/mail/send', params )
29
+ json = JSON.parse(result.force_encoding('UTF-8'))
30
+ error(json) unless json["result"]
31
+ unless @file.nil?
32
+ File.unlink(@file.path) rescue nil
33
+ end
34
+ end
35
+
36
+ private
21
37
 
22
- result = Net::HTTP.post_form(URI.parse("http://api.sendcloud.net/apiv2/mail/send"), params)
23
- json = JSON.parse(result.body.force_encoding('UTF-8'))
24
- ActionMailer::Base.logger.error(json) unless json["result"] && !ActionMailer::Base.logger.nil?
38
+ def error(message)
39
+ ActionMailer::Base.logger.error(message) unless ActionMailer::Base.logger.nil?
25
40
  end
26
41
 
27
42
  def from
@@ -29,8 +44,23 @@ module SendcloudMailer
29
44
  end
30
45
 
31
46
  def to
32
- addresses = @mail.header.fields.find{|f| f.name == "To"}.address_list.addresses
33
- addresses.join(';')
47
+ addresses 'To'
48
+ end
49
+
50
+ def cc
51
+ addresses 'Cc'
52
+ end
53
+
54
+ def bcc
55
+ addresses 'Bcc'
56
+ end
57
+
58
+ def addresses(name)
59
+ result = @mail.header.fields.find { |f| f.name == name }
60
+ unless result.nil?
61
+ addresses = result.address_list.addresses
62
+ addresses.join(';')
63
+ end
34
64
  end
35
65
 
36
66
  def html
@@ -40,5 +70,17 @@ module SendcloudMailer
40
70
  def plain
41
71
  @mail.multipart? ? (@mail.text_part ? @mail.text_part.body.decoded : nil) : @mail.body.decoded
42
72
  end
73
+
74
+ def attachments
75
+ return nil if @mail.attachments.length == 0
76
+
77
+ @mail.attachments.each do | attachment |
78
+ filename = attachment.filename
79
+ # sendcloud api can only single file
80
+ @file = File.new(File.join(Dir.tmpdir, filename), 'w+b')
81
+ @file.write(attachment.body.decoded)
82
+ return @file
83
+ end
84
+ end
43
85
  end
44
86
  end
@@ -0,0 +1,12 @@
1
+ module SendcloudMailer
2
+ class Interceptor
3
+ def self.delivering_email(mail)
4
+ html = mail.html_part ? mail.html_part.body.decoded : nil
5
+ return if html.nil?
6
+ html = Nokogiri::HTML(html)
7
+ body = html.xpath('//body')[0]
8
+ body.name = 'div'
9
+ mail.html_part.body = body.to_s
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module SendcloudMailer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -6,11 +6,11 @@ require 'sendcloud-mailer/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "sendcloud-mailer"
8
8
  spec.version = SendcloudMailer::VERSION
9
- spec.authors = ["Chen Yi-Cyuan"]
9
+ spec.authors = ["Chen, Yi-Cyuan"]
10
10
  spec.email = ["emn178@gmail.com"]
11
11
 
12
- spec.summary = %q{Sendcloud mailer.}
13
- spec.description = %q{Sendcloud mailer.}
12
+ spec.summary = %q{An Action Mailer delivery method for SendCloud email service.}
13
+ spec.description = %q{An Action Mailer delivery method for SendCloud email service.}
14
14
  spec.homepage = "https://github.com/emn178/sendcloud-mailer"
15
15
  spec.license = "MIT"
16
16
 
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "actionmailer"
21
+ spec.add_dependency "rest-client"
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.10"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
- # spec.add_development_dependency "rails"
25
25
  spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "rspec-its"
26
+ spec.add_development_dependency "webmock"
27
27
  spec.add_development_dependency "simplecov"
28
28
  spec.add_development_dependency "coveralls"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendcloud-mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - Chen Yi-Cyuan
7
+ - Chen, Yi-Cyuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-17 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rspec-its
84
+ name: webmock
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -108,7 +122,7 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
- description: Sendcloud mailer.
125
+ description: An Action Mailer delivery method for SendCloud email service.
112
126
  email:
113
127
  - emn178@gmail.com
114
128
  executables: []
@@ -118,6 +132,7 @@ files:
118
132
  - ".gitignore"
119
133
  - ".rspec"
120
134
  - ".travis.yml"
135
+ - CHANGELOG.md
121
136
  - Gemfile
122
137
  - LICENSE.txt
123
138
  - README.md
@@ -126,6 +141,7 @@ files:
126
141
  - bin/setup
127
142
  - lib/sendcloud-mailer.rb
128
143
  - lib/sendcloud-mailer/base.rb
144
+ - lib/sendcloud-mailer/interceptor.rb
129
145
  - lib/sendcloud-mailer/version.rb
130
146
  - sendcloud-mailer.gemspec
131
147
  homepage: https://github.com/emn178/sendcloud-mailer
@@ -151,5 +167,5 @@ rubyforge_project:
151
167
  rubygems_version: 2.4.8
152
168
  signing_key:
153
169
  specification_version: 4
154
- summary: Sendcloud mailer.
170
+ summary: An Action Mailer delivery method for SendCloud email service.
155
171
  test_files: []