cocoapods-aomi-bin 0.1.17 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49133e2b9dbd7b9dc71db8acab55373cdff0edc852c389d77807af522c1626dd
4
- data.tar.gz: 42f7f78c46513a26710835aa834d1e05b67e7ada7b524c87bda676e0912dd348
3
+ metadata.gz: 37116f9c50d0a054b0cdac7abf1780edb282e0fee63dd3d953ad1c106d2bb9c6
4
+ data.tar.gz: 565c6e8399328d174ec4829426462c369ae9b94e8366fa3db753ca2fce9f0d2c
5
5
  SHA512:
6
- metadata.gz: e71bf10b411685698e9f2f42ae0d4d252112cba5c63c245395aa30a66cafa44e81a8984ab67b9a31ad68aabf9a52c11f7056590bd9f6e7898c2281fef6c6a658
7
- data.tar.gz: 158c7b60ee4561488d8ad22c5e4a01bc6bdecc79cf4a37e87a3ca8362e6c541506edc29b3cbd07e98eb707990017036eccd71169e206be5680e7e27054a32c4c
6
+ metadata.gz: 974593d648b8dfc27bfa9d79d8070c022c817dbfb8b1410fbeecf3e5e5303936235080a6dccf852c686cdf9daa42080ec93e47837472074428c8b153fa6c981a
7
+ data.tar.gz: 180a3740de5aaf2e9bf540e778b50b09cc58c1f90465a11830022cc53f2755cc6a2b07c8ead33f50f0a2b256c3a3a4d6b0c19bcf4b37e99e86ce4144112c7bf2
@@ -15,6 +15,7 @@ require 'cocoapods-lhj-bin/command/bin/local/upload'
15
15
  require 'cocoapods-lhj-bin/command/bin/trans'
16
16
  require 'cocoapods-lhj-bin/command/bin/lhj'
17
17
  require 'cocoapods-lhj-bin/command/bin/model'
18
+ require 'cocoapods-lhj-bin/command/bin/yapi'
18
19
  require 'cocoapods-lhj-bin/command/bin/view'
19
20
  require 'cocoapods-lhj-bin/command/bin/config/push'
20
21
  require 'cocoapods-lhj-bin/command/bin/oss/list'
@@ -58,7 +59,7 @@ module Pod
58
59
  end
59
60
 
60
61
  def validate!
61
- # super
62
+ super
62
63
  # 这里由于 --help 是在 validate! 方法中提取的,会导致 --help 失效
63
64
  # pod lib create 也有这个问题
64
65
  banner! if @help
@@ -15,13 +15,17 @@ module Pod
15
15
  end
16
16
 
17
17
  def run
18
+ model = fetch_model
19
+ fetch_models(nil, model) if model
20
+ print_models
21
+ print_models_implementation
22
+ end
23
+
24
+ def fetch_model
18
25
  uri = URI.parse(@url)
19
26
  res = Net::HTTP.get_response(uri)
20
27
  res_body = JSON.parse(res.body)
21
- detail_msg = res_body['detailMsg']
22
- fetch_models(nil, detail_msg) if detail_msg
23
- print_models
24
- print_models_implementation
28
+ res_body['detailMsg']
25
29
  end
26
30
 
27
31
  def validate!
@@ -0,0 +1,272 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Yapi < Bin
9
+ self.summary = '通过yapi接口生成请求'
10
+
11
+ def self.options
12
+ [
13
+ %w[--id api的id],
14
+ %w[--model-pre 模型的前缀]
15
+ ]
16
+ end
17
+
18
+ def initialize(argv)
19
+ @id = argv.option('id')
20
+ @model_pre_name = argv.option('model-pre')
21
+ @http_url = ''
22
+ @http_headers = []
23
+ @data_json = {}
24
+ @models = []
25
+ @config_id = ''
26
+ @config_model_pre = 'ML'
27
+ @type_trans = {}
28
+ @config_model_names = []
29
+ @model_names = []
30
+ super
31
+ end
32
+
33
+ def run
34
+ load_config
35
+ fetch_model
36
+ print_methods
37
+ end
38
+
39
+ def test_ding
40
+ require 'net/http'
41
+ require 'uri'
42
+ body = { "msgtype" => "text", "text" => { "content" => "error:上传蒲公英超时失败!" } }.to_json
43
+ Net::HTTP.post(URI('https://oapi.dingtalk.com/robot/send?access_token=6a3519057170cdb1b7274edfe43934c84a0062ffe2c9bcced434699296a7e26e'), body, "Content-Type" => "application/json")
44
+ end
45
+
46
+ def url_str
47
+ "#{@http_url}#{api_id}"
48
+ end
49
+
50
+ def load_config
51
+ yml = File.join(Pod::Config.instance.home_dir, 'yapi.yml')
52
+ config = YAML.load_file(yml)
53
+ config.each do |k, v|
54
+ @http_headers << "#{k}=#{v}" if (k.eql?('__wpkreporterwid_') || k.eql?('_yapi_token') || k.eql?('_yapi_uid'))
55
+ end
56
+ @http_url = config['url']
57
+ @config_id = config['id']
58
+ @config_model_pre = config['model_pre']
59
+ @config_model_names = config['model_names']
60
+ @type_trans = config['type_trans']
61
+ end
62
+
63
+ def api_id
64
+ @id || @config_id.to_s
65
+ end
66
+
67
+ def model_pre
68
+ @model_pre_name || @config_model_pre
69
+ end
70
+
71
+ def req_model
72
+ uri = URI.parse(url_str)
73
+ req = Net::HTTP::Get.new(uri)
74
+ req['Cookie'] = @http_headers.join('; ')
75
+ res = Net::HTTP.start(uri.hostname, uri.port) do |http|
76
+ http.request(req)
77
+ end
78
+ puts res.body
79
+ JSON.parse(res.body)
80
+ end
81
+
82
+ def fetch_model
83
+ res_json = req_model
84
+ begin
85
+ puts "\n<===============打印返回数据模型-Begin=====================>\n"
86
+ fetch_res_boy(res_json)
87
+ print_models
88
+ print_models_implementation
89
+ puts "\n<===============打印返回数据模型-End=====================>\n"
90
+ end
91
+ begin
92
+ puts "\n<===============打印请求模型-Begin=====================>\n"
93
+ @models = []
94
+ @model_names = []
95
+ fetch_req_body(res_json)
96
+ print_models
97
+ print_models_implementation
98
+ puts "\n<===============打印请求模型-End=====================>\n"
99
+ end
100
+ end
101
+
102
+ def fetch_res_boy(res_json)
103
+ if res_json && res_json['data']
104
+ @data_json = res_json['data']
105
+ if @data_json['res_body']
106
+ begin
107
+ res_body = JSON.parse(@data_json['res_body'])
108
+ detail_obj = res_body['properties']['detailMsg'] || {}
109
+ detail_obj['name'] = gen_model_name('')
110
+ handle_model(detail_obj)
111
+ rescue => ex
112
+ puts ex
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ def fetch_req_body(res_json)
119
+ if res_json && res_json['data']
120
+ @data_json = res_json['data']
121
+ if @data_json['req_body_other']
122
+ begin
123
+ res_body = JSON.parse(@data_json['req_body_other'])
124
+ res_body['name'] = gen_model_name('')
125
+ handle_model(res_body)
126
+ rescue => ex
127
+ puts ex
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ def gen_model_name(name)
134
+ n = name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { $&.upcase }
135
+ if n.length <= 0
136
+ n = @config_model_names.detect{ |c| !@model_names.any?{ |n| n.gsub(/#{model_pre}(.*)Model/, '\1').eql?(c) } }
137
+ end
138
+ model_name = "#{model_pre}#{n}Model"
139
+ @model_names << model_name
140
+ model_name
141
+ end
142
+
143
+ def handle_model(model)
144
+ p_type = model['type']
145
+ p_name = model['name']
146
+ p_properties = model['properties']
147
+ p_model = { name: p_name }
148
+
149
+ properties = []
150
+ if p_type.eql?('object')
151
+ p_properties.each do |k, v|
152
+ c_type = @type_trans[v['type']] || v['type']
153
+ c_model = {key: k, type: c_type, description: v['description'], default: ''}
154
+ if v['type'].eql?('object') || v['type'].eql?('array')
155
+ o = v['items'] || v
156
+ o['name'] = gen_model_name(k)
157
+ if v['type'].eql?('array') && v['items']['type'].eql?('string')
158
+ c_model[:type_name] = "NSString"
159
+ else
160
+ c_model[:type_name] = o['name']
161
+ handle_model(o)
162
+ end
163
+ end
164
+ properties << c_model
165
+ end
166
+ p_model[:properties] = properties
167
+ @models << p_model
168
+ elsif p_type.eql?('array')
169
+ t = model['items']
170
+ t['name'] = p_name
171
+ handle_model(t)
172
+ end
173
+ end
174
+
175
+ def print_models
176
+ @models.each do |model|
177
+ model_name = model[:name] || ''
178
+ model_properties = model[:properties]
179
+ puts "@interface #{model_name} : NSObject"
180
+ model_properties.each do |m|
181
+ print_model(m)
182
+ end
183
+ puts "@end\n\n\n"
184
+ end
185
+ end
186
+
187
+ def print_models_implementation
188
+ @models.each do |model|
189
+ puts "@implementation #{model[:name]}"
190
+ str = model[:properties].filter { |p| p[:type].eql?('array') && !p[:type_name].eql?('NSString') }.map{ |p| "@\"#{p[:key]}\": #{p[:type_name]}.class" }.join(', ')
191
+ if str && str.length > 0
192
+ puts "+(NSDictionary *)modelContainerPropertyGenericClass {"
193
+ puts " return @{#{str}};"
194
+ puts "}"
195
+ end
196
+ puts "@end\n\n\n"
197
+ end
198
+ end
199
+
200
+ def print_model(m)
201
+ key = m[:key]
202
+ type_name = m[:type_name]
203
+ type = m[:type]
204
+ des = m[:description] || ''
205
+ des.gsub!(/\n/, ' ')
206
+ default = m[:default]
207
+ puts "///#{des} #{default}"
208
+ if type.eql?('integer')
209
+ puts "@property (nonatomic, assign) NSInteger #{key};"
210
+ if des.include?('分')
211
+ puts "/////////==========删掉其中一个属性"
212
+ puts "@property (nonatomic, strong) MLCentNumber *#{key};"
213
+ end
214
+ elsif type.eql?('cent')
215
+ puts "@property (nonatomic, strong) MLCentNumber *#{key};"
216
+ elsif type.eql?('string')
217
+ puts "@property (nonatomic, copy) NSString *#{key};"
218
+ elsif type.eql?('number')
219
+ puts "@property (nonatomic, strong) NSNumber *#{key};"
220
+ elsif type.eql?('float')
221
+ puts "@property (nonatomic, assign) CGFloat #{key};"
222
+ elsif type.eql?('double')
223
+ puts "@property (nonatomic, assign) double #{key};"
224
+ elsif type.eql?('boolean')
225
+ puts "@property (nonatomic, assign) BOOL #{key};"
226
+ elsif type.eql?('object')
227
+ puts "@property (nonatomic, strong) #{type_name} *#{key};"
228
+ elsif type.eql?('array')
229
+ puts "@property (nonatomic, strong) NSArray<#{type_name} *> *#{key};"
230
+ else
231
+ puts "@property (nonatomic, copy) NSString *#{key};"
232
+ end
233
+ end
234
+
235
+ def print_methods
236
+ puts "\n<===============方法调用=====================>\n"
237
+ puts "/**"
238
+ puts " * #{@data_json['title']} -- #{@data_json['username']}"
239
+ puts " */"
240
+ key_str = @data_json['path'].split('/').map{ |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/){ $&.upcase } }.join('')
241
+ key = "k#{key_str}URL"
242
+ puts "static NSString * const #{key} = @\"#{@data_json['path']}\";"
243
+ puts "\n\n"
244
+ puts "@interface MLParamModel : NSObject"
245
+ @data_json['req_query'].each do |h|
246
+ des = h['desc'].gsub(/\n/, ' ')
247
+ puts "///#{des} #{h['example']}"
248
+ puts "@property (nonatomic, copy) NSString *#{h['name']};"
249
+ end
250
+ puts "@end"
251
+ puts "\n\n"
252
+ model = @models.last
253
+ if @data_json['method'].eql?('GET')
254
+ puts " [MLNetworkingManager getWithUrl:#{key} params:nil response:^(MLResponseMessage *responseMessage) {"
255
+ puts " if (response.resultCode == 0 && !response.error){"
256
+ puts " NSDictionary *detailMsg = response.detailMsg"
257
+ puts " #{model[:name]} *model = [#{model[:name]} yy_modelWithDictionary:detailMsg];" if model
258
+ puts " }"
259
+ puts " }];"
260
+ else
261
+ puts " [MLNetworkingManager postWithUrl:#{key} params:nil response:^(MLResponseMessage *responseMessage) {"
262
+ puts " if (response.resultCode == 0 && !response.error){"
263
+ puts " NSDictionary *detailMsg = response.detailMsg"
264
+ puts " #{model[:name]} *model = [#{model[:name]} yy_modelWithDictionary:detailMsg];" if model
265
+ puts " }"
266
+ puts " }];"
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
272
+ end
@@ -1,5 +1,5 @@
1
1
  module CBin
2
- VERSION = '0.1.17'
2
+ VERSION = '0.1.22'
3
3
  end
4
4
 
5
5
  module Pod
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-aomi-bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -132,6 +132,7 @@ files:
132
132
  - lib/cocoapods-lhj-bin/command/bin/trans.rb
133
133
  - lib/cocoapods-lhj-bin/command/bin/update.rb
134
134
  - lib/cocoapods-lhj-bin/command/bin/view.rb
135
+ - lib/cocoapods-lhj-bin/command/bin/yapi.rb
135
136
  - lib/cocoapods-lhj-bin/config/config.rb
136
137
  - lib/cocoapods-lhj-bin/config/config_asker.rb
137
138
  - lib/cocoapods-lhj-bin/config/config_builder.rb