exmail 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 874854755cac56c8f0492d41fba91f01131a085a
4
+ data.tar.gz: 69cb4d0f1c22ad6420fe58fdd20af694ae844b59
5
+ SHA512:
6
+ metadata.gz: eb90e6156b03965d911b264bc387082a58fae5ced143d34ef15ed6febf5eb438b25c24ba87e7ff79e00ffa1e67d97d7c374ce4b256480b7b7dc6c2c156b93783
7
+ data.tar.gz: c9ca333cbce5146aa7c41fe8d1f6afb7fba1bce39199b27fde894599d911b5e8cd18d5ec4fef4046f751406152fae0e35380a1fb648b75a189f0604e42c4d004
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at heimirror@163.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://ruby.taobao.org/'
2
+
3
+ # Specify your gem's dependencies in exmail.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 brucewu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # Exmail
2
+
3
+ 腾讯企业邮箱的API接口的调用,详细用法看代码,都有注释的
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'exmail'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install exmail
20
+
21
+ ## License
22
+
23
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
24
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "exmail"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exmail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exmail"
8
+ spec.version = Exmail::VERSION
9
+ spec.authors = ["brucewu"]
10
+ spec.email = ["heimirror@163.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = 'https://github.com/brucewu/exmail'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "rest-client", "~> 1.6.8"
34
+ end
@@ -0,0 +1,177 @@
1
+ require 'exmail/version'
2
+ require 'restclient'
3
+
4
+ module Exmail
5
+ class Server
6
+ attr_accessor :key, :account_name, :access_token
7
+ #主要用于获取token
8
+ DOMAIN_TOKEN = 'exmail.qq.com'
9
+ #主要是调用API
10
+ DOMAIN_API = 'openapi.exmail.qq.com:12211'
11
+
12
+ def initialize(account_name, key)
13
+ @account_name, @key=account_name, key
14
+ end
15
+
16
+ #获取具体的邮箱的信息
17
+ #返回数据: {"PartyList"=>{"Count"=>1, "List"=>[{"Value"=>"IT部"}]},
18
+ # "OpenType"=>1, "Name"=>"bruce", "Mobile"=>"18612345678", "Status"=>1, "Tel"=>"",
19
+ # "Position"=>"IT技术", "Gender"=>1, "SlaveList"=>"", "Alias"=>"bruce.wu@ubox-xzh.com", "ExtId"=>""}
20
+ def user_get(email)
21
+ api_path = '/openapi/user/get'
22
+ result = post_api(api_path, {:alias => email})
23
+ result['error'].nil? ? result : {}
24
+ end
25
+
26
+ #检查邮件帐号是否可用,多个邮箱用数组形式传入
27
+ # user_check(['aaa@aaa.com','bbb@bbb.com'])
28
+ # 返回 {"Count"=>2, "List"=>[{"Email"=>"aaa@aaa.com", "Type"=>1}, {"Email"=>"bbb@bbb.com", "Type"=>1}]}
29
+ # Type说明: -1:帐号名无效 0: 帐号名没被占用 1:主帐号名 2:别名帐号 3:邮件群组帐 号
30
+ def user_check(emails)
31
+ emails=[emails] if emails.class!=Array
32
+ api_path = '/openapi/user/check'
33
+ post_api(api_path, 'email='+emails.join('&email='))
34
+ end
35
+
36
+ # 创建用户
37
+ # slave别名列表 # 1. 如果多个别名,传多个 Slave 2. Slave 上限为 5 个 3. Slave 为邮箱格式
38
+ # user_add('bruce.wu@ubox-xzh.com',{:slave=>"", :position=>"", :partypath=>"北京/IT技术部", :gender=>1,
39
+ # :password=>"123123", :extid=>1, :mobile=>"", :md5=>0, :tel=>"", :name=>"dede", :opentype=>1})
40
+ def user_add(email, user_attr)
41
+ params = user_attr.merge(:action => 2, :alias => email)
42
+ result = user_sync(params)
43
+ if !result.nil? && result['error']=='party_not_found'
44
+ partypath = user_attr[:partypath]||user_attr['partypath']
45
+ party_add_p(partypath)
46
+ sleep(1) #添加完部门要等一会才会有
47
+ user_sync(params)
48
+ end
49
+ end
50
+
51
+ # 修改用户,调用方法参考 user_add
52
+ def user_mod(email, user_attr)
53
+ params = user_attr.merge(:action => 3, :alias => email)
54
+ user_sync(params)
55
+ end
56
+
57
+ # 修改密码
58
+ # new_pass为新密码
59
+ def change_pass(email, new_pass)
60
+ user_sync({:alias => email, :password => new_pass, :md5 => 0, :action => 3})
61
+ end
62
+
63
+ #删除用户
64
+ def user_delete(email)
65
+ user_sync(:action => 1, :alias => email)
66
+ end
67
+
68
+ # 同步成员资料
69
+ #Action string 1=DEL, 2=ADD, 3=MOD
70
+ def user_sync(params)
71
+ api_path = '/openapi/user/sync'
72
+ post_api(api_path, params)
73
+ end
74
+
75
+ #创建部门
76
+ #多级部门用/分隔,例如: /IT部/IT产品部
77
+ def party_add(party_name)
78
+ party_sync(:action => 2, :dstpath => party_name)
79
+ end
80
+
81
+ # 自动创建所有层的部门
82
+ # 类似于 mkdir_p
83
+ # party_add_p('aa/bb/cc/dd')将创建四级部门
84
+ def party_add_p(party_name)
85
+ _party_path = ''
86
+ party_name.split('/').each do |party|
87
+ next if party.to_s==''
88
+ party_add("#{_party_path}/#{party}") unless party_exists?("#{_party_path}/#{party}")
89
+ _party_path+=('/'+party)
90
+ end
91
+ end
92
+
93
+ # 删除部门
94
+ # 多级部门用/分隔,例如: /IT部/IT产品部
95
+ def party_delete(party_name)
96
+ party_sync(:action => 1, :dstpath => party_name)
97
+ end
98
+
99
+ # 修改部门
100
+ # party_mod('/北京','/IT部/IT产品部') 将"/IT部/IT产品部"移动到根目录下,并改名为"北京"
101
+ def party_mod(party_name, parent_party)
102
+ party_sync(:action => 3, :dstpath => party_name, :srcpath => parent_party)
103
+ end
104
+
105
+ # 同步部门信息
106
+ def party_sync(params)
107
+ api_path = '/openapi/party/sync'
108
+ post_api(api_path, params)
109
+ end
110
+
111
+ #获取子部门
112
+ def party_list(partypath=nil)
113
+ api_path='/openapi/party/list'
114
+ post_api(api_path, {:partypath => partypath})
115
+ end
116
+
117
+ # 是否存在该部门
118
+ def party_exists?(party_path)
119
+ result = party_list(party_path)
120
+ result['error']!='party_not_found'
121
+ end
122
+
123
+ # 获取部门下成员
124
+ # 获取不存在的部门的子部门返回 {"error"=>"party_not_found", "errcode"=>"1310"}
125
+ # 正常结果 {"Count"=>1, "List"=>[{"Value"=>"北京1"}]}
126
+ def partyuser_list(partypath=nil)
127
+ api_path = '/openapi/partyuser/list'
128
+ post_api(api_path, {:partypath => partypath})
129
+ end
130
+
131
+ # 添加邮件群组
132
+ # group-admin==群组管理者(需要使用一个域中不存在的 邮箱地址)
133
+ # status--群组状态(分为 4 类 all,inner,group, list)
134
+ def group_add(group_name, group_admin, status, members)
135
+ api_path='/openapi/group/add'
136
+ post_api(api_path, {:group_name => group_name, :group_admin => group_admin,
137
+ :status => status, :members => members})
138
+ end
139
+
140
+ # 删除邮件群组
141
+ # group_alias--群组管理员(一个域中不存在的邮箱地址)
142
+ def group_delete(group_alias)
143
+ api_path='/openapi/group/delete'
144
+ post_api(api_path, {:group_alias => group_alias})
145
+ end
146
+
147
+ # 添加邮件群组成员
148
+ def group_add_member(group_alias, members)
149
+ api_path = '/openapi/group/addmember'
150
+ post_api(api_path, {:group_alias => group_alias, :members => members})
151
+ end
152
+
153
+ # 删除邮件群组成员
154
+ def group_del_member(group_alias, members)
155
+ api_path = '/openapi/group/deletemember'
156
+ post_api(api_path, {:group_alias => group_alias, :members => members})
157
+ end
158
+
159
+ #返回数据: {access_token":"", "token_type":"Bearer", "expires_in":86400, "refresh_token":""}
160
+ def get_token
161
+ url_path = '/cgi-bin/token'
162
+ url = "https://#{DOMAIN_TOKEN}#{url_path}"
163
+ json_str = RestClient.post(url, {:grant_type => 'client_credentials',
164
+ :client_id => @account_name,
165
+ :client_secret => @key})
166
+ json = JSON.load(json_str)
167
+ @access_token = json['access_token']
168
+ json
169
+ end
170
+
171
+ def post_api(api_path, params)
172
+ get_token if @access_token.nil?
173
+ url = "http://#{DOMAIN_API}#{api_path}"
174
+ JSON.load RestClient.post(url, params, {:Authorization => "Bearer #{@access_token}"})
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,3 @@
1
+ module Exmail
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - brucewu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-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: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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: 1.6.8
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.8
69
+ description: Write a longer description or delete this line.
70
+ email:
71
+ - heimirror@163.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exmail.gemspec
87
+ - lib/exmail.rb
88
+ - lib/exmail/version.rb
89
+ homepage: https://github.com/brucewu/exmail
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.8
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Write a short summary, because Rubygems requires one.
114
+ test_files: []