lhj-tools 0.2.28 → 0.2.29

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e94e1905e459e9be531bc985e002c26e743c7c642d2489fb4f8ed5eb0ec84c29
4
- data.tar.gz: c381978186ef918f95428253f355ba7abef8e5d3310e905efadcac868b4b5e26
3
+ metadata.gz: c152ebec555059e05a8fe9ab9496de443546851059e51ae9799b3e8918dfee41
4
+ data.tar.gz: f73adfd0888a178b7b8d2ed60411fdd3b1b7a0673038b7e975173b7d4d375bc3
5
5
  SHA512:
6
- metadata.gz: 8f01e8a6806633435912ac4a87fbd9bf5821ebfe5c8dcc39b994628edb0e832b5605508324e6252945fb35faa263b7673668733d294201ed7a8417bb1e145b43
7
- data.tar.gz: d107bd31f5334a85265af95da2b1cf45bbb3f765582b9f20304b38f10c420fc50ef5ef56a3d405a4081aa1980b41503fbd34adfc0d1847fc7c8321439eebd3bb
6
+ metadata.gz: 659978a2a7ce730bed42798f2ba53e178dfb8078b468286374efdbfc2d6849e6fe86f76b5d1300815904409670231a286b1a9b6dc8f37903c1647b24565fc979
7
+ data.tar.gz: e3162198e303cf3a5298d0ca8b417807adc6b71f4317c40ef16c9d7d60091557bc876ecd4292141f2ab41d21555d0d235a251380fa6c84ee38f44de8c368a81e
@@ -30,15 +30,41 @@ module Lhj
30
30
  super
31
31
  end
32
32
 
33
+ def add_device(udid, name)
34
+ post_data = {
35
+ 'data' => {
36
+ 'attributes' => {
37
+ 'name' => name,
38
+ 'platform' => 'IOS',
39
+ 'udid' => udid
40
+ },
41
+ 'type' => 'devices'
42
+ }
43
+ }
44
+ res = Lhj::ConnectAPI.post('https://api.appstoreconnect.apple.com/v1/devices', post_data)
45
+ puts res.body
46
+ end
47
+
33
48
  def handle
34
- api = Lhj::YapiHelper.new(project_id: 694, interface_id: 70595, model_name: 'Order', model_pre: 'AA')
35
- api.process
36
- file_list = api.save_to_file
37
- key = Lhj::IOSRobotConfig.app_key
38
- secret = Lhj::IOSRobotConfig.app_secret
39
- conversation_id = 'cid31Wevlrdq9L4Q0WugLb0tw=='
40
- user_ids = []
41
- file_list.each { |f| Lhj::Dingtalk.upload_file_and_notify(key, secret, f, conversation_id, user_ids) }
49
+ file = File.join(Lhj::Config.instance.home_dir, 'all_device.txt')
50
+ File.open(file, 'r+') do |f|
51
+ f.each_line do |line|
52
+ ma = line.match(/(?<device>[^\s]*)(\s*)(?<name>.*)/)
53
+ device = ma[:device]
54
+ name = ma[:name].gsub(/(\S*)\s(\S*)\s(.*)/, '\\1-\\2-\\3')
55
+ name = name.gsub(/\s/, '')
56
+ add_device(device, name)
57
+ end
58
+ end
59
+
60
+ # api = Lhj::YapiHelper.new(project_id: 694, interface_id: 70595, model_name: 'Order', model_pre: 'AA')
61
+ # api.process
62
+ # file_list = api.save_to_file
63
+ # key = Lhj::IOSRobotConfig.app_key
64
+ # secret = Lhj::IOSRobotConfig.app_secret
65
+ # conversation_id = 'cid31Wevlrdq9L4Q0WugLb0tw=='
66
+ # user_ids = []
67
+ # file_list.each { |f| Lhj::Dingtalk.upload_file_and_notify(key, secret, f, conversation_id, user_ids) }
42
68
 
43
69
  #
44
70
  #
@@ -0,0 +1,102 @@
1
+ require 'lhj/config'
2
+ require 'highline'
3
+
4
+ module Lhj
5
+ class Command
6
+ # sync code to pod
7
+ class SyncDingdingUser < Command
8
+ self.summary = '同步dingding_user'
9
+
10
+ def handle
11
+ sync_data
12
+ end
13
+
14
+ def sync_data
15
+ key = Lhj::IOSRobotConfig.app_key
16
+ secret = Lhj::IOSRobotConfig.app_secret
17
+ token = Lhj::Dingtalk.get_token(key, secret)
18
+ handle_dept(token, nil)
19
+ end
20
+
21
+ def handle_dept(token, dept_id)
22
+ dept_array = fetch_department(token, dept_id)
23
+ dept_array.each do |d|
24
+ dept_json = { 'dept_id' => d['dept_id'], 'name' => d['name'], 'parent_id' => d['parent_id'] }.to_json
25
+ save_dept(dept_json)
26
+ user_ids = fetch_user_ids(token, d['dept_id'])
27
+ user_ids.each do |id|
28
+ user = fetch_user_info(token, id)
29
+ user_json = { 'avatar' => user['avatar'],
30
+ 'dept_id' => d['dept_id'],
31
+ 'email' => user['email'],
32
+ 'job_number' => user['job_number'],
33
+ 'mobile' => user['mobile'],
34
+ 'name' => user['name'],
35
+ 'telephone' => user['telephone'],
36
+ 'title' => user['title'],
37
+ 'unionid' => user['unionid'],
38
+ 'userid' => user['userid'],
39
+ 'work_place' => user['work_place'] }.to_json
40
+ save_user(user_json)
41
+ end
42
+ handle_dept(token, d['dept_id'])
43
+ end
44
+ end
45
+
46
+ def fetch_department(token, dept_id)
47
+ url = URI("https://oapi.dingtalk.com/topapi/v2/department/listsub?access_token=#{token}")
48
+ https = Net::HTTP.new(url.host, url.port)
49
+ https.use_ssl = true
50
+ request = Net::HTTP::Post.new(url)
51
+ request['Content-Type'] = 'application/json'
52
+ request.body = { 'dept_id' => dept_id }.to_json if dept_id
53
+ response = https.request(request)
54
+ res_json = JSON.parse(response.body)
55
+ res_json['result']
56
+ end
57
+
58
+ def fetch_user_ids(token, dept_id)
59
+ url = URI("https://oapi.dingtalk.com/topapi/user/listid?access_token=#{token}")
60
+ https = Net::HTTP.new(url.host, url.port)
61
+ https.use_ssl = true
62
+ request = Net::HTTP::Post.new(url)
63
+ request['Content-Type'] = 'application/json'
64
+ request.body = { 'dept_id' => dept_id }.to_json if dept_id
65
+ response = https.request(request)
66
+ res_json = JSON.parse(response.body)
67
+ res_json['result']['userid_list']
68
+ end
69
+
70
+ def fetch_user_info(token, user_id)
71
+ url = URI("https://oapi.dingtalk.com/topapi/v2/user/get?access_token=#{token}")
72
+ https = Net::HTTP.new(url.host, url.port)
73
+ https.use_ssl = true
74
+ request = Net::HTTP::Post.new(url)
75
+ request['Content-Type'] = 'application/json'
76
+ request.body = { 'userid' => user_id }.to_json
77
+ response = https.request(request)
78
+ res_json = JSON.parse(response.body)
79
+ res_json['result']
80
+ end
81
+
82
+ def save_dept(json)
83
+ url = URI("#{Lhj::IOSRobotConfig.base_url}/dept/create")
84
+ http = Net::HTTP.new(url.host, url.port)
85
+ request = Net::HTTP::Post.new(url)
86
+ request['Content-Type'] = 'application/json'
87
+ request.body = json
88
+ http.request(request)
89
+ end
90
+
91
+ def save_user(json)
92
+ url = URI("#{Lhj::IOSRobotConfig.base_url}/user/create")
93
+ http = Net::HTTP.new(url.host, url.port)
94
+ request = Net::HTTP::Post.new(url)
95
+ request['Content-Type'] = 'application/json'
96
+ request.body = json
97
+ http.request(request)
98
+ end
99
+
100
+ end
101
+ end
102
+ end
data/lib/lhj/command.rb CHANGED
@@ -35,6 +35,7 @@ module Lhj
35
35
  require 'lhj/command/pgyer_upload'
36
36
  require 'lhj/command/duplicate_imageset'
37
37
  require 'lhj/command/jenkins/jenkins_build'
38
+ require 'lhj/command/sync_dingding_user'
38
39
 
39
40
  self.abstract_command = true
40
41
  self.command = 'lhj'
@@ -241,5 +241,25 @@ module Lhj
241
241
  send_group_message(token, msg_body) if msg_body
242
242
  end
243
243
 
244
+ def self.markdown_notify(conversation_id, user_ids, title, markdown)
245
+ key = Lhj::IOSRobotConfig.app_key
246
+ secret = Lhj::IOSRobotConfig.app_secret
247
+ token = get_token(key, secret)
248
+ msg_key = 'sampleMarkdown'
249
+ msg_param = sample_markdown_param(title, markdown)
250
+ msg_body = group_message_body(key, conversation_id, user_ids, msg_key, msg_param)
251
+ send_group_message(token, msg_body)
252
+ end
253
+
254
+ def self.text_notify(conversation_id, user_ids, content)
255
+ key = Lhj::IOSRobotConfig.app_key
256
+ secret = Lhj::IOSRobotConfig.app_secret
257
+ token = get_token(key, secret)
258
+ msg_key = 'sampleText'
259
+ msg_param = sample_text_param(content)
260
+ msg_body = group_message_body(key, conversation_id, user_ids, msg_key, msg_param)
261
+ send_group_message(token, msg_body)
262
+ end
263
+
244
264
  end
245
265
  end
@@ -26,5 +26,9 @@ module Lhj
26
26
  def self.app_secret
27
27
  config['app_secret']
28
28
  end
29
+
30
+ def self.base_url
31
+ config['base_url']
32
+ end
29
33
  end
30
34
  end
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.28'
4
+ VERSION = '0.2.29'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.28
4
+ version: 0.2.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -371,6 +371,7 @@ files:
371
371
  - lib/lhj/command/refactor_rename.rb
372
372
  - lib/lhj/command/rename_image.rb
373
373
  - lib/lhj/command/reverse_import.rb
374
+ - lib/lhj/command/sync_dingding_user.rb
374
375
  - lib/lhj/command/sync_pod_code.rb
375
376
  - lib/lhj/command/sync_pod_repo.rb
376
377
  - lib/lhj/command/sync_pod_version.rb