lhj-tools 0.1.73 → 0.1.75

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: ec999ed3fcb4f5fff34b2dc483b5932c77bfd34c59cee78dfcebd7ea1a10fc54
4
- data.tar.gz: c0a438db4402ef344ddf83f3acd4f3bca228c9335aa8e8d240bab02ba4745269
3
+ metadata.gz: 7dc72ca4edb2bdcb5abd9ced2b89e97843bbd4393527e28be7b0c750d3f00be7
4
+ data.tar.gz: 88b0b3444ba3c78ce03bb2bdcb32eef0fa77ea23eec27f41225ea1a7df9a6aa1
5
5
  SHA512:
6
- metadata.gz: 9201f7d556c51665acb83d63cbe4978eb6507d99d00b1da5ab92fa064557298242845fec4484d2cf327fc41a6bf1663c3648573627ecb3098338d5c591aa1d04
7
- data.tar.gz: 217cc7ee797ee78ab6a074715bf346fc3e044779e2553a20a1b813a63239a3e72611d17e439477912415ba600325ed4f1d597446e213833c6146651419a22a67
6
+ metadata.gz: 27eb16b78e42d2ea284b68cf6678949367a489a15e9fb6961b8b0d3debe74e30daa76f96079416a7f00530c72c183b1ef842882e04bfb4ecbe4a1a974ba1e37a
7
+ data.tar.gz: 6426a55e2043d21cfcd35d49b05400db2485e6433982d98348db95ef98f3d6bbce210a020d509cc9a1efe1a7fdf843be857279bc0dc72f0e8eaba490a9772304
@@ -13,6 +13,9 @@ module Lhj
13
13
  self.summary = '通过yapi接口生成请求'
14
14
  self.description = '执行`lhj api`生成接口模型'
15
15
 
16
+ API_INTERFACE_URL = 'api/interface/get?id='.freeze
17
+ API_PROJECT_URL = 'api/project/get?id='.freeze
18
+
16
19
  def self.options
17
20
  [
18
21
  %w[--id api的id],
@@ -39,7 +42,7 @@ module Lhj
39
42
  @config_model_name = 'Result'
40
43
  @model_default_suffix = 'Model'
41
44
  @type_trans = {}
42
- @http_url = ''
45
+ @base_url = 'http://yapi.xx.com'
43
46
  super
44
47
  end
45
48
 
@@ -49,13 +52,16 @@ module Lhj
49
52
 
50
53
  def process(config_file)
51
54
  load_config(config_file)
52
- res_body = req_api_model
55
+ res_body = get_interface_api_model
53
56
  unless res_body['errcode'].to_i.zero?
54
57
  puts '请执行 lhj yapi-init 初始化配置'.red
55
58
  return
56
59
  end
57
60
  return unless res_body && !res_body.empty?
58
61
 
62
+ # get project info
63
+ project_id = res_body['data']['project_id']
64
+ project_info = get_project_info(project_id)
59
65
  # 1.print request result
60
66
  result_model_name = print_res_body_model(res_body)
61
67
  # 2.print request json body
@@ -63,13 +69,13 @@ module Lhj
63
69
  # 3.print request param
64
70
  print_req_query(res_body['data'])
65
71
  # 4.print request method
66
- service_code = print_http_method(res_body['data'], result_model_name, param_model_name)
72
+ service_code = print_http_method(res_body['data'], project_info, result_model_name, param_model_name)
67
73
  # 5.save to file
68
74
  file_map = save_to_file(service_code) if @save
69
75
  # 6.push to git
70
76
  push_to_git if @sync
71
77
  # 7.notify robot
72
- notify_robot(file_map) if @notify
78
+ notify_robot(file_map, res_body, project_info) if @notify
73
79
  end
74
80
 
75
81
  def puts_h(str)
@@ -111,7 +117,7 @@ module Lhj
111
117
  File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive?
112
118
  File.write(service_file, service_code) if service_code
113
119
  puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green
114
- { h_file: h_file, m_file: m_file, s_file: service_file, api_id: api_id }
120
+ { h_file: h_file, m_file: m_file, s_file: service_file }
115
121
  end
116
122
 
117
123
  def push_to_git
@@ -121,15 +127,23 @@ module Lhj
121
127
  Actions.sh('git push')
122
128
  end
123
129
 
124
- def notify_robot(template_vars)
130
+ def notify_robot(file_info, interface_info, project_info)
131
+ temp_vars = file_info.merge({
132
+ api_id: api_id,
133
+ interface_url: "#{project_info['data']['basepath']}#{interface_info['data']['path']}"
134
+ })
125
135
  robot_url = 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
126
136
  template = Lhj::ErbTemplateHelper.load('oc_code_notify')
127
- output = Lhj::ErbTemplateHelper.render(template, template_vars, '-')
137
+ output = Lhj::ErbTemplateHelper.render(template, temp_vars, '-')
128
138
  Lhj::Dingtalk.post_message_robot(robot_url, '生成代码', output)
129
139
  end
130
140
 
131
- def url_str
132
- "#{@http_url}#{api_id}"
141
+ def interface_url_str
142
+ "#{@base_url}/#{API_INTERFACE_URL}#{api_id}"
143
+ end
144
+
145
+ def project_url_str(project_id)
146
+ "#{@base_url}/#{API_PROJECT_URL}#{project_id}"
133
147
  end
134
148
 
135
149
  def yml_file
@@ -141,7 +155,7 @@ module Lhj
141
155
  config.each do |k, v|
142
156
  @http_headers << "#{k}=#{v}" if k.eql?('__wpkreporterwid_') || k.eql?('_yapi_token') || k.eql?('_yapi_uid')
143
157
  end
144
- @http_url = config['url']
158
+ @base_url = config['base_url']
145
159
  @config_id = config['id']
146
160
  @config_model_pre = config['model_pre']
147
161
  @config_model_suffix = config['model_suffix']
@@ -169,8 +183,8 @@ module Lhj
169
183
  @config_model_suffix || @model_default_suffix
170
184
  end
171
185
 
172
- def req_api_model
173
- uri = URI.parse(url_str)
186
+ def get_interface_api_model
187
+ uri = URI.parse(interface_url_str)
174
188
  req = Net::HTTP::Get.new(uri)
175
189
  req['Cookie'] = @http_headers.join('; ')
176
190
  res = Net::HTTP.start(uri.hostname, uri.port) do |http|
@@ -182,6 +196,17 @@ module Lhj
182
196
  res_json
183
197
  end
184
198
 
199
+ def get_project_info(project_id)
200
+ url = project_url_str(project_id)
201
+ uri = URI.parse(url)
202
+ req = Net::HTTP::Get.new(uri)
203
+ req['Cookie'] = @http_headers.join('; ')
204
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
205
+ http.request(req)
206
+ end
207
+ JSON.parse(res.body)
208
+ end
209
+
185
210
  def print_res_body_model(res_json)
186
211
  res_body = fetch_res_boy(res_json)
187
212
  return unless res_body
@@ -401,7 +426,7 @@ module Lhj
401
426
  end
402
427
  end
403
428
 
404
- def print_http_method(data, result_model_name, param_model_name)
429
+ def print_http_method(data, project_info, result_model_name, param_model_name)
405
430
  return unless data
406
431
 
407
432
  path = data['path']
@@ -421,7 +446,7 @@ module Lhj
421
446
  yapi_vars = { title: data['title'],
422
447
  desc: data['desc'],
423
448
  username: data['username'],
424
- path: path,
449
+ path: "#{project_info['data']['basepath']}#{path}",
425
450
  path_key: path_key,
426
451
  path_name: path_name,
427
452
  result_model_name: result_model_name,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.73"
5
+ VERSION = "0.1.75"
6
6
  end
7
7
  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.1.73
4
+ version: 0.1.75
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-09 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj