customers_mail_cloud 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: f7259d0be394aa904ee51f4cadd3b42a38ee7aa7cb257953f4fee5421f14fc0e
4
- data.tar.gz: ac609b1e65b77cb8f2bea01559b2828e17d239ad15d04707630795fd3d9f4320
3
+ metadata.gz: 6613c90dcec96e35935ff0c7a8bacf5fb0f542ef9b3fd90fc836ee2efbbf78cf
4
+ data.tar.gz: 68daccd52615ec358995d5ea54594d37988cd65263646c62f6a99ad3dad1fe49
5
5
  SHA512:
6
- metadata.gz: 41c91f2bb547e90aa83a948118eec304582005d84bf38062b45b593c54259a70a22b17f26f103705c772893919923d0f025a7a8793c9e0d76aa7be9f5e2b7e37
7
- data.tar.gz: 23e2b971ef79123df3b52c13dad2e7e5fb589d40bca95b8f5fc94d2d7b589a4761f982c1af3237aec757812414283dffb684890a187c25f3ee3cc4226c2d5857
6
+ metadata.gz: 50c9cfa817d82ccd7d296456c0b0e610cd815853b8290fc43e35984912d5d33f906b8d37bfe50fc198beec59faa49d80ae05c8c59844ee50b3c34570fd6f173a
7
+ data.tar.gz: dc2e82fad147ff7443e42a28b54c6eff57fc70cecfa99c3204b3cf55ca2547a3d066a7709f0a687148b63d4abb015e3e60c4d48f7119e6a84be1688a6d2154a8
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  config.json
13
+ test.rb
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+ gem "multipart-post"
9
+ gem "mime-types"
@@ -7,6 +7,10 @@ GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.4.4)
10
+ mime-types (3.3.1)
11
+ mime-types-data (~> 3.2015)
12
+ mime-types-data (3.2020.0512)
13
+ multipart-post (2.1.1)
10
14
  rake (12.3.3)
11
15
  rspec (3.9.0)
12
16
  rspec-core (~> 3.9.0)
@@ -27,6 +31,8 @@ PLATFORMS
27
31
 
28
32
  DEPENDENCIES
29
33
  customers_mail_cloud!
34
+ mime-types
35
+ multipart-post
30
36
  rake (~> 12.0)
31
37
  rspec (~> 3.0)
32
38
 
data/README.md CHANGED
@@ -34,6 +34,15 @@ client.subject = 'Mail subject'
34
34
  client.text = 'Mail body'
35
35
  ```
36
36
 
37
+ ### Attach file(s)
38
+
39
+ ```ruby
40
+ # File path by sting
41
+ client.attachments << "./Rakefile"
42
+ # File object
43
+ client.attachments << open("./test.rb")
44
+ ```
45
+
37
46
  ### Send email
38
47
 
39
48
  ```ruby
@@ -1,5 +1,7 @@
1
1
  require "net/http"
2
2
  require "json"
3
+ require "net/http/post/multipart"
4
+ require 'mime/types'
3
5
 
4
6
  module CustomersMailCloud
5
7
  class Client
@@ -55,9 +57,29 @@ module CustomersMailCloud
55
57
  'Accept': 'application/json'
56
58
  }
57
59
  uri = URI.parse(@url)
58
- http = Net::HTTP.new(uri.host, uri.port)
60
+ if @attachments.size > 0
61
+ params[:attachments] = @attachments.size
62
+ [:to, :from].each do |k|
63
+ params[k] = params[k].to_json
64
+ end
65
+ @attachments.each_with_index do |a, i|
66
+ if a.is_a? String
67
+ a = File.new(a)
68
+ end
69
+ mimeType = MIME::Types.type_for(a.path)[0]
70
+ params["attachment#{i + 1}"] = UploadIO.new a, mimeType ? mimeType.to_s : 'application/octet-stream', File.basename(a)
71
+ end
72
+ req = Net::HTTP::Post::Multipart.new(uri.path, params)
73
+ else
74
+ req = Net::HTTP::Post.new(uri.path)
75
+ req.body = params.to_json
76
+ headers.each do |k, v|
77
+ req[k] = v
78
+ end
79
+ end
80
+ http = Net::HTTP.new uri.host, uri.port
59
81
  http.use_ssl = true
60
- response = http.post(uri.path, params.to_json, headers)
82
+ response = http.request req
61
83
  if response.code == "200"
62
84
  return JSON.parse response.body
63
85
  else
@@ -1,3 +1,3 @@
1
1
  module CustomersMailCloud
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customers_mail_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-25 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby library for Customers Mail Cloud. Customers Mail Cloud is email
14
14
  sending service provider that supports SMTP or Web API.