send-cloud 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4c01bf0526d1a0faefc4ad338886a137c1f24be
4
+ data.tar.gz: 8125c76a37c03270a49ddb7206575d9e7b276646
5
+ SHA512:
6
+ metadata.gz: c785198d8072319d02d70974dc33438d25772ca42f354782adb0c967be0fa5a53d9cc8901bd53198761b28fc929b98f698cae899d0f05d2196db5feb1c245c1e
7
+ data.tar.gz: 431c88a1c838b40c2900977b9a9daf8a5a21a5221c900606f220c871608e95635bc8830baf5de3c833cbb4639579572230db580bb8215eda37eb441f210ccc27
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ .DS_Store
21
+ *.swp
22
+ /make_tags*
23
+ /tags
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Ruchee
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # SendCloud
2
+
3
+ Ruby client for sohu sendcloud api
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'send-cloud'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install send-cloud
18
+
19
+ ## Usage
20
+
21
+ #### Configure
22
+
23
+ ```ruby
24
+ SendCloud.setup do |config|
25
+ config.api_user = 'your api user'
26
+ config.api_key = 'your api key'
27
+ end
28
+ ```
29
+
30
+ #### Call the api
31
+
32
+ ```ruby
33
+ SendCloud::Mail.send(from: 'test@example.com', to: 'test@example.com', subject: 'test', html: 'test')
34
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/send-cloud.rb ADDED
@@ -0,0 +1,90 @@
1
+ require 'action_mailer'
2
+ require 'rest-client'
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ require 'send-cloud/addresslist'
7
+ require 'send-cloud/addressmember'
8
+ require 'send-cloud/apiuser'
9
+ require 'send-cloud/domain'
10
+ require 'send-cloud/label'
11
+ require 'send-cloud/mail'
12
+ require 'send-cloud/template'
13
+ require 'send-cloud/userinfo'
14
+ require 'send-cloud/version'
15
+
16
+
17
+ module SendCloud
18
+
19
+ API_BASE = 'http://api.sendcloud.net/apiv2'
20
+
21
+ class Error < StandardError; end
22
+
23
+
24
+ class DeliveryClass
25
+ attr_accessor :settings
26
+
27
+ def initialize (settings)
28
+ SendCloud.api_user = settings[:api_user]
29
+ SendCloud.api_key = settings[:api_key]
30
+ end
31
+
32
+ def deliver! (mail)
33
+ begin
34
+ SendCloud::Mail.send({
35
+ from: mail.from_addrs.first,
36
+ to: mail.destinations.join(';'),
37
+ subject: mail.subject,
38
+ html: mail.body.encoded,
39
+ fromname: mail[:fromname].to_s
40
+ })
41
+ rescue => e
42
+ raise e
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ ActionMailer::Base.add_delivery_method :sendcloud, SendCloud::DeliveryClass
49
+
50
+
51
+ def self.setup
52
+ yield self
53
+ end
54
+
55
+ class << self
56
+ attr_accessor :api_user, :api_key
57
+ end
58
+
59
+ def self.get(path, params, necessary = [])
60
+ request(path, params, necessary) do |url, options|
61
+ RestClient.get(url, {params: options})
62
+ end
63
+ end
64
+
65
+ def self.post(path, params, necessary = [])
66
+ request(path, params, necessary) do |url, options|
67
+ RestClient.post(url, options)
68
+ end
69
+ end
70
+
71
+ def self.request(path, params, necessary, &block)
72
+ params = { apiUser: SendCloud.api_user, apiKey: SendCloud.api_key }.merge(params)
73
+
74
+ needed_keys = necessary - params.keys
75
+ if needed_keys != []
76
+ return {
77
+ 'result' => false,
78
+ 'statusCode' => -1,
79
+ 'message' => "缺少必填参数:#{needed_keys.join(',')}"
80
+ }
81
+ end
82
+
83
+ url = "#{API_BASE}/#{path}"
84
+ begin
85
+ return JSON.parse(yield(url, params))
86
+ rescue JSON::ParserError
87
+ raise SendCloud::Error.new('send-cloud response invalid')
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,29 @@
1
+ module SendCloud
2
+
3
+ module AddressList
4
+
5
+ extend self
6
+
7
+ # 查询地址列表(批量查询)
8
+ def list (params = {})
9
+ SendCloud.post('addresslist/list', params, [])
10
+ end
11
+
12
+ # 添加地址列表
13
+ def add (params = {})
14
+ SendCloud.post('addresslist/add', params, [:address, :name])
15
+ end
16
+
17
+ # 修改地址列表
18
+ def update (params = {})
19
+ SendCloud.post('addresslist/update', params, [:address])
20
+ end
21
+
22
+ # 删除地址列表
23
+ def delete (params = {})
24
+ SendCloud.post('addresslist/delete', params, [:address])
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,34 @@
1
+ module SendCloud
2
+
3
+ module AddressMember
4
+
5
+ extend self
6
+
7
+ # 查询列表成员(批量查询)
8
+ def list (params = {})
9
+ SendCloud.post('addressmember/list', params, [:address])
10
+ end
11
+
12
+ # 查询列表成员
13
+ def get (params = {})
14
+ SendCloud.post('addressmember/get', params, [:address, :members])
15
+ end
16
+
17
+ # 添加列表成员
18
+ def add (params = {})
19
+ SendCloud.post('addressmember/add', params, [:address, :members])
20
+ end
21
+
22
+ # 修改列表成员
23
+ def update (params = {})
24
+ SendCloud.post('addressmember/update', params, [:address, :members])
25
+ end
26
+
27
+ # 删除列表成员
28
+ def delete (params = {})
29
+ SendCloud.post('addressmember/delete', params, [:address, :members])
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,19 @@
1
+ module SendCloud
2
+
3
+ module ApiUser
4
+
5
+ extend self
6
+
7
+ # 查询(批量查询)
8
+ def list (params = {})
9
+ SendCloud.post('apiuser/list', params, [])
10
+ end
11
+
12
+ # 添加
13
+ def add (params = {})
14
+ SendCloud.post('apiuser/add', params, [:name, :emailType, :domainName])
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,24 @@
1
+ module SendCloud
2
+
3
+ module Domain
4
+
5
+ extend self
6
+
7
+ # 查询(批量查询)
8
+ def list (params = {})
9
+ SendCloud.post('domain/list', params, [])
10
+ end
11
+
12
+ # 添加
13
+ def add (params = {})
14
+ SendCloud.post('domain/add', params, [:name])
15
+ end
16
+
17
+ # 修改
18
+ def update (params = {})
19
+ SendCloud.post('domain/update', params, [:name, :newName])
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,34 @@
1
+ module SendCloud
2
+
3
+ module Label
4
+
5
+ extend self
6
+
7
+ # 查询(批量查询)
8
+ def list (params = {})
9
+ SendCloud.post('label/list', params, [])
10
+ end
11
+
12
+ # 查询
13
+ def get (params = {})
14
+ SendCloud.post('label/get', params, [:labelId])
15
+ end
16
+
17
+ # 添加
18
+ def add (params = {})
19
+ SendCloud.post('label/add', params, [:labelName])
20
+ end
21
+
22
+ # 修改
23
+ def update (params = {})
24
+ SendCloud.post('label/update', params, [:labelId, :labelName])
25
+ end
26
+
27
+ # 删除
28
+ def delete (params = {})
29
+ SendCloud.post('label/delete', params, [:labelId])
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,24 @@
1
+ module SendCloud
2
+
3
+ module Mail
4
+
5
+ extend self
6
+
7
+ # 普通发送
8
+ def send (params = {})
9
+ SendCloud.post('mail/send', params, [:from, :to, :subject, :html])
10
+ end
11
+
12
+ # 模版发送
13
+ def sendtemplate (params = {})
14
+ SendCloud.post('mail/sendtemplate', params, [:from, :to, :xsmtpapi, :subject, :templateInvokeName])
15
+ end
16
+
17
+ # 地址列表发送任务查询
18
+ def taskinfo (params = {})
19
+ SendCloud.post('mail/taskinfo', params, [:maillistTaskId])
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,39 @@
1
+ module SendCloud
2
+
3
+ module Template
4
+
5
+ extend self
6
+
7
+ # 查询(批量查询)
8
+ def list (params = {})
9
+ SendCloud.post('template/list', params, [])
10
+ end
11
+
12
+ # 查询
13
+ def get (params = {})
14
+ SendCloud.post('template/get', params, [:invokeName])
15
+ end
16
+
17
+ # 添加
18
+ def add (params = {})
19
+ SendCloud.post('template/add', params, [:invokeName, :name, :html, :subject, :templateType])
20
+ end
21
+
22
+ # 修改
23
+ def update (params = {})
24
+ SendCloud.post('template/update', params, [:invokeName])
25
+ end
26
+
27
+ # 提交
28
+ def submit (params = {})
29
+ SendCloud.post('template/submit', params, [:invokeName])
30
+ end
31
+
32
+ # 删除
33
+ def delete (params = {})
34
+ SendCloud.post('template/delete', params, [:invokeName])
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,14 @@
1
+ module SendCloud
2
+
3
+ module UserInfo
4
+
5
+ extend self
6
+
7
+ # 查询
8
+ def get (params = {})
9
+ SendCloud.post('userinfo/get', params, [])
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ module SendCloud
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'send-cloud/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'send-cloud'
7
+ spec.version = SendCloud::VERSION
8
+ spec.authors = ['Ruchee']
9
+ spec.email = ['my@ruchee.com']
10
+ spec.description = %q{ruby client for sohu send-cloud api}
11
+ spec.summary = %q{use this gem to call sohu send-cloud api}
12
+ spec.homepage = 'https://github.com/ruchee/send-cloud'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'rspec'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ spec.add_dependency 'rest-client'
25
+ end
data/spec/mail_spec.rb ADDED
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../spec_helper.rb', __FILE__)
2
+
3
+ describe SendCloud::Mail do
4
+
5
+ describe 'send' do
6
+
7
+ it 'should return 200' do
8
+ response = SendCloud::Mail.send({
9
+ from: 'test1@qq.com',
10
+ to: 'test2@qq.com',
11
+ subject: 'test',
12
+ html: 'test'
13
+ })
14
+ expect(response['statusCode']).to eq(200)
15
+ end
16
+
17
+ end
18
+
19
+
20
+ describe 'sendtemplate' do
21
+
22
+ it 'should return 200' do
23
+ response = SendCloud::Mail.sendtemplate({
24
+ from: 'test1@qq.com',
25
+ to: 'test2@qq.com',
26
+ subject: 'test',
27
+ xsmtpapi: '{"to": ["test2@qq.com"]}',
28
+ templateInvokeName: 'test'
29
+ })
30
+ expect(response['statusCode']).to eq(200)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'send-cloud'
3
+
4
+ RSpec.configure do |_|
5
+ SendCloud.setup do |config|
6
+ config.api_user = 'your api user'
7
+ config.api_key = 'your api key'
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: send-cloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ruchee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ruby client for sohu send-cloud api
70
+ email:
71
+ - my@ruchee.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/send-cloud.rb
83
+ - lib/send-cloud/addresslist.rb
84
+ - lib/send-cloud/addressmember.rb
85
+ - lib/send-cloud/apiuser.rb
86
+ - lib/send-cloud/domain.rb
87
+ - lib/send-cloud/label.rb
88
+ - lib/send-cloud/mail.rb
89
+ - lib/send-cloud/template.rb
90
+ - lib/send-cloud/userinfo.rb
91
+ - lib/send-cloud/version.rb
92
+ - send-cloud.gemspec
93
+ - spec/mail_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: https://github.com/ruchee/send-cloud
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: use this gem to call sohu send-cloud api
119
+ test_files:
120
+ - spec/mail_spec.rb
121
+ - spec/spec_helper.rb
122
+ has_rdoc: