sendcloud-mail 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sendcloud-mail.rb +112 -0
  3. metadata +58 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5cdb4e035e0d8a176cbf0481ce944980aaef0325
4
+ data.tar.gz: 4355449c829c4e0b0a108b0dac158e61337a9906
5
+ SHA512:
6
+ metadata.gz: 254ea01ae61eb421a166b4ceb4a3521d85078d3afdacdfeed22d7e4347359b10b4d192c625ecd5bd63a4bf3704a44c1368101af7cab0b211e7398c101e055029
7
+ data.tar.gz: a91bd6f602208b3166e329406fea64c089030b06ff4fb2a2fe744fc15705a85bf3ed0bb2454a4b82110e135247f29161a040e34bca043ede9778267ed37a53f3
@@ -0,0 +1,112 @@
1
+ require 'digest'
2
+ require 'rest-client'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ module SendCloud
7
+ class Mail
8
+
9
+ def self.load!(file, environment)
10
+ config = YAML.load_file(file)
11
+ self.auth(config[environment.to_s]['mail_api_user'], config[environment.to_s]['mail_api_key'])
12
+ end
13
+
14
+ def self.auth(mail_api_user, mail_api_key)
15
+ @mail_api_user = mail_api_user
16
+ @mail_api_key = mail_api_key
17
+ end
18
+
19
+ def self.send(from, fromName, subject, xsmtpapi, content, summary=nil)
20
+ # xsmtpapi comes in the following format:
21
+ #{
22
+ # "to": ["d@163.com",'i@163.com'],
23
+ # "sub": {
24
+ # "%content%": ['nihao0', 'nihao1']
25
+ # }
26
+ #}
27
+ response = RestClient.post 'https://api.sendcloud.net/apiv2/mail/send?',
28
+ apiUser: @mail_api_user,
29
+ apiKey: @mail_api_key,
30
+ from: from,
31
+ fromName: fromName,
32
+ xsmtpapi: xsmtpapi.to_json,
33
+ subject: subject,
34
+ html: content,
35
+ contentSummary: summary
36
+ JSON.parse(response.to_s)['statusCode']
37
+ end
38
+
39
+ def self.send_template(invokeName, from, fromName, xsmtpapi, subject=nil, summary=nil)
40
+ # xsmtpapi comes in the following format:
41
+ #{
42
+ # "to": ["d@163.com",'i@163.com'],
43
+ # "sub": {
44
+ # "%content%": ['nihao0', 'nihao1']
45
+ # }
46
+ #}
47
+ response = RestClient.post 'https://api.sendcloud.net/apiv2/mail/sendtemplate?',
48
+ apiUser: @mail_api_user,
49
+ apiKey: @mail_api_key,
50
+ from: from,
51
+ fromName: fromName,
52
+ xsmtpapi: xsmtpapi.to_json,
53
+ subject: subject,
54
+ templateInvokeName: invokeName,
55
+ contentSummary: summary
56
+ JSON.parse(response.to_s)['statusCode']
57
+ end
58
+
59
+ def self.get(invokeName)
60
+ params = {
61
+ apiUser: @mail_api_user,
62
+ apiKey: @mail_api_key,
63
+ invokeName: invokeName,
64
+ }
65
+ response = RestClient.get 'https://api.sendcloud.net/apiv2/template/get?', params: params
66
+ JSON.parse(response.to_s)
67
+ end
68
+
69
+ def self.list
70
+ params = {
71
+ apiUser: @mail_api_user,
72
+ apiKey: @mail_api_key
73
+ }
74
+ response = RestClient.get 'https://api.sendcloud.net/apiv2/template/list?', params: params
75
+ JSON.parse(response.to_s)
76
+ end
77
+
78
+ def self.create(invokeName, name, html, subject, templateType)
79
+ response = RestClient.post 'http://api.sendcloud.net/apiv2/template/add?',
80
+ apiUser: @mail_api_user,
81
+ apiKey: @mail_api_key,
82
+ invokeName: invokeName,
83
+ name: name,
84
+ html: html,
85
+ subject: subject,
86
+ templateType: templateType
87
+
88
+ JSON.parse(response.to_s)
89
+ end
90
+
91
+ def self.update(invokeName, name, html, subject, templateType)
92
+ response = RestClient.post 'https://api.sendcloud.net/apiv2/template/update?',
93
+ apiUser: @mail_api_user,
94
+ apiKey: @mail_api_key,
95
+ invokeName: invokeName,
96
+ name: name,
97
+ html: html,
98
+ subject: subject,
99
+ templateType: templateType
100
+ JSON.parse(response.to_s)['statusCode']
101
+ end
102
+
103
+ def self.delete(invokeName)
104
+ response = RestClient.post 'https://api.sendcloud.net/apiv2/template/delete?',
105
+ apiUser: @mail_api_user,
106
+ apiKey: @mail_api_key,
107
+ invokeName: invokeName
108
+ JSON.parse(response.to_s)['statusCode']
109
+ end
110
+
111
+ end
112
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendcloud-mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - dannio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ description: A gem to send Mail with SendCloud API
28
+ email: dcwongy@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/sendcloud-mail.rb
34
+ homepage: https://github.com/dannio/sendcloud-mail
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.6.8
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A gem to send Mail with SendCloud API
58
+ test_files: []