lhj-tools 0.1.73 → 0.1.74

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: f86764f14d88348e59221a4e339765a6ec4488a815d179a710d15e7c415471a1
4
+ data.tar.gz: 9f5635a3e149ce527aea1c298fa7a39316c446e75aaed941d23c6010ce0896de
5
5
  SHA512:
6
- metadata.gz: 9201f7d556c51665acb83d63cbe4978eb6507d99d00b1da5ab92fa064557298242845fec4484d2cf327fc41a6bf1663c3648573627ecb3098338d5c591aa1d04
7
- data.tar.gz: 217cc7ee797ee78ab6a074715bf346fc3e044779e2553a20a1b813a63239a3e72611d17e439477912415ba600325ed4f1d597446e213833c6146651419a22a67
6
+ metadata.gz: 144bfb6d35d9190b81ed1715dd518c2b707971815a3412f279f673faffb4c6dd36768c05c86da1249d9eed7328620a0588fe62a3753b249fd9fd8625726bb0d3
7
+ data.tar.gz: 6d875c726247374420c5b2856614283a817078e073517a3dc5849b7a9258567eefffc9df76f3d54ec58836f647ef922ea6169c5fe9211d53630ab39a2fe78570
@@ -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,7 +69,7 @@ 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
@@ -128,8 +134,12 @@ module Lhj
128
134
  Lhj::Dingtalk.post_message_robot(robot_url, '生成代码', output)
129
135
  end
130
136
 
131
- def url_str
132
- "#{@http_url}#{api_id}"
137
+ def interface_url_str
138
+ "#{@base_url}/#{API_INTERFACE_URL}#{api_id}"
139
+ end
140
+
141
+ def project_url_str(project_id)
142
+ "#{@base_url}/#{API_PROJECT_URL}#{project_id}"
133
143
  end
134
144
 
135
145
  def yml_file
@@ -141,7 +151,7 @@ module Lhj
141
151
  config.each do |k, v|
142
152
  @http_headers << "#{k}=#{v}" if k.eql?('__wpkreporterwid_') || k.eql?('_yapi_token') || k.eql?('_yapi_uid')
143
153
  end
144
- @http_url = config['url']
154
+ @base_url = config['base_url']
145
155
  @config_id = config['id']
146
156
  @config_model_pre = config['model_pre']
147
157
  @config_model_suffix = config['model_suffix']
@@ -169,8 +179,8 @@ module Lhj
169
179
  @config_model_suffix || @model_default_suffix
170
180
  end
171
181
 
172
- def req_api_model
173
- uri = URI.parse(url_str)
182
+ def get_interface_api_model
183
+ uri = URI.parse(interface_url_str)
174
184
  req = Net::HTTP::Get.new(uri)
175
185
  req['Cookie'] = @http_headers.join('; ')
176
186
  res = Net::HTTP.start(uri.hostname, uri.port) do |http|
@@ -182,6 +192,17 @@ module Lhj
182
192
  res_json
183
193
  end
184
194
 
195
+ def get_project_info(project_id)
196
+ url = project_url_str(project_id)
197
+ uri = URI.parse(url)
198
+ req = Net::HTTP::Get.new(uri)
199
+ req['Cookie'] = @http_headers.join('; ')
200
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
201
+ http.request(req)
202
+ end
203
+ JSON.parse(res.body)
204
+ end
205
+
185
206
  def print_res_body_model(res_json)
186
207
  res_body = fetch_res_boy(res_json)
187
208
  return unless res_body
@@ -401,7 +422,7 @@ module Lhj
401
422
  end
402
423
  end
403
424
 
404
- def print_http_method(data, result_model_name, param_model_name)
425
+ def print_http_method(data, project_info, result_model_name, param_model_name)
405
426
  return unless data
406
427
 
407
428
  path = data['path']
@@ -421,7 +442,7 @@ module Lhj
421
442
  yapi_vars = { title: data['title'],
422
443
  desc: data['desc'],
423
444
  username: data['username'],
424
- path: path,
445
+ path: "#{project_info['data']['basepath']}#{path}",
425
446
  path_key: path_key,
426
447
  path_name: path_name,
427
448
  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.74"
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.74
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