jpsclient 1.3.0 → 1.4.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jpsclient/api/category.rb +331 -0
  3. data/lib/jpsclient/api/cert.rb +4 -1
  4. data/lib/jpsclient/api/client.rb +68 -37
  5. data/lib/jpsclient/api/design.rb +123 -0
  6. data/lib/jpsclient/api/image_search.rb +74 -0
  7. data/lib/jpsclient/api/lark_card_message.rb +45 -0
  8. data/lib/jpsclient/api/lark_department.rb +44 -0
  9. data/lib/jpsclient/api/lark_file.rb +32 -0
  10. data/lib/jpsclient/api/lark_leave_approval.rb +47 -0
  11. data/lib/jpsclient/api/lark_message.rb +32 -0
  12. data/lib/jpsclient/api/nuget.rb +30 -0
  13. data/lib/jpsclient/api/permission.rb +137 -0
  14. data/lib/jpsclient/api/tag.rb +267 -45
  15. data/lib/jpsclient/api/template.rb +216 -0
  16. data/lib/jpsclient/auth/auth.rb +1 -1
  17. data/lib/jpsclient/http/http_client.rb +24 -4
  18. data/lib/jpsclient/upload/upload_client.rb +1 -1
  19. data/lib/jpsclient/version.rb +1 -1
  20. metadata +57 -18
  21. /data/lib/jpsclient/api/{app_resource_version.rb → archived_outdated/app_resource_version.rb} +0 -0
  22. /data/lib/jpsclient/api/{application_category.rb → archived_outdated/application_category.rb} +0 -0
  23. /data/lib/jpsclient/api/{application_design.rb → archived_outdated/application_design.rb} +0 -0
  24. /data/lib/jpsclient/api/{assets_category.rb → archived_outdated/assets_category.rb} +0 -0
  25. /data/lib/jpsclient/api/{experience.rb → archived_outdated/experience.rb} +0 -0
  26. /data/lib/jpsclient/api/{experience_category.rb → archived_outdated/experience_category.rb} +0 -0
  27. /data/lib/jpsclient/api/{icon_and_snapshot.rb → archived_outdated/icon_and_snapshot.rb} +0 -0
  28. /data/lib/jpsclient/api/{publisher_category.rb → archived_outdated/publisher_category.rb} +0 -0
  29. /data/lib/jpsclient/api/{publisher_group_category.rb → archived_outdated/publisher_group_category.rb} +0 -0
  30. /data/lib/jpsclient/api/{requirements_category.rb → archived_outdated/requirements_category.rb} +0 -0
  31. /data/lib/jpsclient/api/{resource_category.rb → archived_outdated/resource_category.rb} +0 -0
  32. /data/lib/jpsclient/api/{sketch_category.rb → archived_outdated/sketch_category.rb} +0 -0
  33. /data/lib/jpsclient/api/{survey_category.rb → archived_outdated/survey_category.rb} +0 -0
  34. /data/lib/jpsclient/api/{tool_category.rb → archived_outdated/tool_category.rb} +0 -0
  35. /data/lib/jpsclient/api/{jssdk.rb → js_sdk.rb} +0 -0
@@ -1,16 +1,63 @@
1
1
  module JPSClient
2
2
  module API
3
3
  # Tag 相关 API
4
- # 自动生成的模块,处理 tag 相关接口
4
+ # 处理标签管理相关接口
5
5
  module Tag
6
6
 
7
- # Update Tag
7
+ # 创建标签
8
8
  #
9
- # @param params [Hash] 请求参数
9
+ # @param params [Hash] 标签信息参数
10
+ # - name: 标签名称(必需)
11
+ # - type: 标签类型(必需)
12
+ # - color: 标签颜色(可选)
13
+ # - description: 标签描述(可选)
14
+ # @return [Hash] API响应
15
+ def create_tag(params: {})
16
+ config = @request_config && @request_config["tag_create"]
17
+ raise JPSClient::ExceptionError, "Missing config for tag_create" unless config && config["url"]
18
+
19
+ # 参数验证
20
+ required_fields = [:name, :type]
21
+ missing_fields = required_fields.select { |field| params[field].nil? || params[field].to_s.empty? }
22
+
23
+ if missing_fields.any?
24
+ raise JPSClient::ExceptionError, "Missing required fields: #{missing_fields.join(', ')}"
25
+ end
26
+
27
+ path = config["url"]
28
+
29
+ response = @http_client.post(path, body: params)
30
+ result = JPSClient::Response.new(response)
31
+
32
+ if result.need_login?
33
+ do_login(force_login: true)
34
+ response = @http_client.post(path, body: params)
35
+ result = JPSClient::Response.new(response)
36
+ end
37
+
38
+ return result.to_h
39
+ end
40
+
41
+ # 更新标签
42
+ #
43
+ # @param params [Hash] 更新参数
44
+ # - tagId: 标签ID(必需)
45
+ # - name: 标签名称(必需)
46
+ # - type: 标签类型(必需)
47
+ # - color: 标签颜色(可选)
48
+ # - description: 标签描述(可选)
10
49
  # @return [Hash] API响应
11
50
  def update_tag(params: {})
12
- config = @request_config && @request_config["tag_tag"]
13
- raise JPSClient::ExceptionError, "Missing config for tag_tag" unless config && config["url"]
51
+ config = @request_config && @request_config["tag_update"]
52
+ raise JPSClient::ExceptionError, "Missing config for tag_update" unless config && config["url"]
53
+
54
+ # 参数验证
55
+ required_fields = [:tagId, :name, :type]
56
+ missing_fields = required_fields.select { |field| params[field].nil? || params[field].to_s.empty? }
57
+
58
+ if missing_fields.any?
59
+ raise JPSClient::ExceptionError, "Missing required fields: #{missing_fields.join(', ')}"
60
+ end
14
61
 
15
62
  path = config["url"]
16
63
 
@@ -26,37 +73,49 @@ module JPSClient
26
73
  return result.to_h
27
74
  end
28
75
 
29
- # Create Tag
76
+ # 删除标签
30
77
  #
31
- # @param params [Hash] 请求参数
78
+ # @param tagId [String, Integer] 标签ID(必需)
32
79
  # @return [Hash] API响应
33
- def create_tag(params: {})
34
- config = @request_config && @request_config["tag_tag"]
35
- raise JPSClient::ExceptionError, "Missing config for tag_tag" unless config && config["url"]
80
+ def delete_tag(tagId:)
81
+ config = @request_config && @request_config["tag_delete"]
82
+ raise JPSClient::ExceptionError, "Missing config for tag_delete" unless config && config["url"]
36
83
 
37
- path = config["url"]
84
+ path = config["url"].gsub("{tagId}", tagId.to_s)
38
85
 
39
- response = @http_client.post(path, body: params)
86
+ response = @http_client.delete(path)
40
87
  result = JPSClient::Response.new(response)
41
88
 
42
89
  if result.need_login?
43
90
  do_login(force_login: true)
44
- response = @http_client.post(path, body: params)
91
+ response = @http_client.delete(path)
45
92
  result = JPSClient::Response.new(response)
46
93
  end
47
94
 
48
95
  return result.to_h
49
96
  end
50
97
 
51
- # Create Weights
98
+ # 更新标签权重
52
99
  #
53
- # @param params [Hash] 请求参数
100
+ # @param weights [Array<Hash>] 权重数组
101
+ # 每个项包含:
102
+ # - id: 标签ID
103
+ # - weight: 权重值
104
+ # - name: 标签名称
105
+ # - type: 标签类型
106
+ # - color: 标签颜色(可选)
107
+ # - description: 标签描述(可选)
54
108
  # @return [Hash] API响应
55
- def create_weights(params: {})
109
+ def update_tag_weights(weights: [])
56
110
  config = @request_config && @request_config["tag_weights"]
57
111
  raise JPSClient::ExceptionError, "Missing config for tag_weights" unless config && config["url"]
58
112
 
113
+ if weights.empty?
114
+ raise JPSClient::ExceptionError, "Weights array cannot be empty"
115
+ end
116
+
59
117
  path = config["url"]
118
+ params = { weights: weights }
60
119
 
61
120
  response = @http_client.post(path, body: params)
62
121
  result = JPSClient::Response.new(response)
@@ -70,13 +129,20 @@ module JPSClient
70
129
  return result.to_h
71
130
  end
72
131
 
73
- # Get Tags
132
+ # 获取标签列表
74
133
  #
75
- # @param params [Hash] 请求参数
134
+ # @param params [Hash] 查询参数
135
+ # - page: 页码(可选)
136
+ # - type: 标签类型(必需)
76
137
  # @return [Hash] API响应
77
138
  def get_tags(params: {})
78
- config = @request_config && @request_config["tag_tags"]
79
- raise JPSClient::ExceptionError, "Missing config for tag_tags" unless config && config["url"]
139
+ config = @request_config && @request_config["tag_list"]
140
+ raise JPSClient::ExceptionError, "Missing config for tag_list" unless config && config["url"]
141
+
142
+ # type 参数是必需的
143
+ unless params[:type] || params["type"]
144
+ raise JPSClient::ExceptionError, "Missing required parameter: type"
145
+ end
80
146
 
81
147
  path = config["url"]
82
148
 
@@ -92,51 +158,207 @@ module JPSClient
92
158
  return result.to_h
93
159
  end
94
160
 
95
- # Get Resources Detail
161
+ # 获取标签关联的资源
96
162
  #
97
- # @param params [Hash] 请求参数
98
- # @return [Hash] API响应
99
- def get_resources_detail(tagId:, params: {})
100
- config = @request_config && @request_config["tag_resources_detail"]
101
- raise JPSClient::ExceptionError, "Missing config for tag_resources_detail" unless config && config["url"]
163
+ # @param tagId [String, Integer] 标签ID(必需)
164
+ # @return [Hash] API响应,包含applications和ideas数组
165
+ def get_tag_resources(tagId:)
166
+ config = @request_config && @request_config["tag_resources"]
167
+ raise JPSClient::ExceptionError, "Missing config for tag_resources" unless config && config["url"]
102
168
 
103
- path = config["url"]
104
- path = path.gsub("{tagId}", tagId.to_s)
169
+ path = config["url"].gsub("{tagId}", tagId.to_s)
105
170
 
106
- response = @http_client.get(path, params: params)
171
+ response = @http_client.get(path)
107
172
  result = JPSClient::Response.new(response)
108
173
 
109
174
  if result.need_login?
110
175
  do_login(force_login: true)
111
- response = @http_client.get(path, params: params)
176
+ response = @http_client.get(path)
112
177
  result = JPSClient::Response.new(response)
113
178
  end
114
179
 
115
180
  return result.to_h
116
181
  end
117
182
 
118
- # Delete Tag
183
+ # 便捷方法:按类型获取标签
119
184
  #
120
- # @param params [Hash] 请求参数
185
+ # @param type [String] 标签类型
186
+ # @param page [Integer] 页码(可选)
121
187
  # @return [Hash] API响应
122
- def delete_tag(tagId:, params: {})
123
- config = @request_config && @request_config["tag_tag"]
124
- raise JPSClient::ExceptionError, "Missing config for tag_tag" unless config && config["url"]
188
+ def get_tags_by_type(type:, page: nil)
189
+ params = { type: type }
190
+ params[:page] = page if page
191
+ get_tags(params: params)
192
+ end
125
193
 
126
- path = config["url"]
127
- path = path.gsub("{tagId}", tagId.to_s)
194
+ # 便捷方法:批量创建标签
195
+ # 注意:此方法会逐个调用 API,返回结果数组
196
+ #
197
+ # @param tags [Array<Hash>] 标签数组
198
+ # @return [Array<Hash>] 每个请求的响应结果
199
+ def batch_create_tags(tags: [])
200
+ return [] if tags.empty?
128
201
 
129
- response = @http_client.delete(path)
130
- result = JPSClient::Response.new(response)
202
+ results = []
203
+ tags.each do |tag_params|
204
+ result = create_tag(params: tag_params)
205
+ results << result
206
+ end
131
207
 
132
- if result.need_login?
133
- do_login(force_login: true)
134
- response = @http_client.delete(path)
135
- result = JPSClient::Response.new(response)
208
+ results
209
+ end
210
+
211
+ # 便捷方法:按颜色筛选标签
212
+ # 获取指定类型的标签,然后在客户端筛选颜色
213
+ #
214
+ # @param type [String] 标签类型(必需)
215
+ # @param color [String] 标签颜色
216
+ # @return [Array<Hash>] 符合条件的标签数组
217
+ def get_tags_by_color(type:, color:)
218
+ response = get_tags(params: { type: type })
219
+
220
+ # 如果请求失败,返回空数组
221
+ return [] unless response && response['data']
222
+
223
+ tags = response['data']['tags'] || response['data'][:tags] || []
224
+ tags.select { |tag|
225
+ (tag['color'] || tag[:color]) == color
226
+ }
227
+ end
228
+
229
+ # 便捷方法:搜索标签
230
+ # 获取指定类型的标签,然后在客户端搜索
231
+ #
232
+ # @param type [String] 标签类型(必需)
233
+ # @param keyword [String] 搜索关键词
234
+ # @return [Array<Hash>] 符合搜索条件的标签数组
235
+ def search_tags(type:, keyword:)
236
+ response = get_tags(params: { type: type })
237
+
238
+ # 如果请求失败,返回空数组
239
+ return [] unless response && response['data']
240
+
241
+ tags = response['data']['tags'] || response['data'][:tags] || []
242
+ tags.select { |tag|
243
+ name = (tag['name'] || tag[:name] || "").to_s
244
+ description = (tag['description'] || tag[:description] || "").to_s
245
+ name.include?(keyword) || description.include?(keyword)
246
+ }
247
+ end
248
+
249
+ # 便捷方法:获取标签的应用列表
250
+ #
251
+ # @param tagId [String, Integer] 标签ID
252
+ # @return [Array] 应用列表
253
+ def get_tag_applications(tagId:)
254
+ response = get_tag_resources(tagId: tagId)
255
+
256
+ # 如果请求失败,返回空数组
257
+ return [] unless response && response['data']
258
+
259
+ response['data']['applications'] || response['data'][:applications] || []
260
+ end
261
+
262
+ # 便捷方法:获取标签的创意列表
263
+ #
264
+ # @param tagId [String, Integer] 标签ID
265
+ # @return [Array] 创意列表
266
+ def get_tag_ideas(tagId:)
267
+ response = get_tag_resources(tagId: tagId)
268
+
269
+ # 如果请求失败,返回空数组
270
+ return [] unless response && response['data']
271
+
272
+ response['data']['ideas'] || response['data'][:ideas] || []
273
+ end
274
+
275
+ # 批量更新标签权重(便捷方法)
276
+ #
277
+ # @param tag_weights [Hash] 标签ID到权重的映射
278
+ # 例如: { "1" => 100, "2" => 90, "3" => 80 }
279
+ # @param type [String] 标签类型
280
+ # @return [Hash] API响应
281
+ def batch_update_weights(tag_weights: {}, type:)
282
+ return update_tag_weights(weights: []) if tag_weights.empty?
283
+
284
+ # 先获取所有标签信息
285
+ response = get_tags(params: { type: type })
286
+
287
+ # 如果获取标签失败,直接返回错误响应
288
+ return response unless response && response['data']
289
+
290
+ tags = response['data']['tags'] || response['data'][:tags] || []
291
+ weights_array = []
292
+
293
+ tag_weights.each do |tag_id, weight|
294
+ tag = tags.find { |t| (t['id'] || t[:id]).to_s == tag_id.to_s }
295
+ if tag
296
+ weights_array << {
297
+ id: tag['id'] || tag[:id],
298
+ weight: weight,
299
+ name: tag['name'] || tag[:name],
300
+ type: tag['type'] || tag[:type],
301
+ color: tag['color'] || tag[:color],
302
+ description: tag['description'] || tag[:description]
303
+ }
304
+ end
136
305
  end
137
306
 
138
- return result.to_h
307
+ # 如果没有找到任何有效标签,返回空权重数组的更新(将由API处理错误)
308
+ update_tag_weights(weights: weights_array)
309
+ end
310
+
311
+ # 复制标签
312
+ # 注意:此功能需要先获取标签详情,然后创建新标签
313
+ #
314
+ # @param tagId [String, Integer] 源标签ID
315
+ # @param new_name [String] 新标签名称
316
+ # @param tag_type [String] 标签类型(如果能提供)
317
+ # @return [Hash] API响应
318
+ def copy_tag(tagId:, new_name:, tag_type: nil)
319
+ # 由于没有获取单个标签详情的API,此方法暂时无法实现
320
+ # 建议使用 get_tags 获取标签列表后在客户端查找并复制
321
+ raise JPSClient::ExceptionError, "Copy tag feature requires get_tag_detail API which is not available"
139
322
  end
323
+
324
+ # 标签统计信息
325
+ # 获取标签并计算统计数据
326
+ #
327
+ # @param type [String] 标签类型
328
+ # @return [Hash] 包含统计数据的哈希
329
+ def get_tags_statistics(type:)
330
+ response = get_tags(params: { type: type })
331
+
332
+ # 如果请求失败,返回空统计
333
+ unless response && response['data']
334
+ return {
335
+ total_count: 0,
336
+ tags_with_resources: 0,
337
+ empty_tags: 0,
338
+ color_distribution: {},
339
+ top_used: []
340
+ }
341
+ end
342
+
343
+ tags = response['data']['tags'] || response['data'][:tags] || []
344
+
345
+ {
346
+ total_count: tags.size,
347
+ tags_with_resources: tags.count { |t|
348
+ (t['relatedCount'] || t[:relatedCount] || 0) > 0
349
+ },
350
+ empty_tags: tags.count { |t|
351
+ (t['relatedCount'] || t[:relatedCount] || 0) == 0
352
+ },
353
+ color_distribution: tags.group_by { |t|
354
+ t['color'] || t[:color] || "no_color"
355
+ }.transform_values(&:size),
356
+ top_used: tags.sort_by { |t|
357
+ -(t['relatedCount'] || t[:relatedCount] || 0)
358
+ }.first(10)
359
+ }
360
+ end
361
+
140
362
  end
141
363
  end
142
- end
364
+ end
@@ -0,0 +1,216 @@
1
+ module JPSClient
2
+ module API
3
+ # Template 相关 API
4
+ # 处理模板管理相关接口
5
+ module Template
6
+
7
+ # 获取模板列表
8
+ #
9
+ # @param params [Hash] 请求参数
10
+ # - page: 页码(默认1)
11
+ # - pageSize: 每页数量(默认10)
12
+ # - type: 模板类型(可选)
13
+ # - name: 模板名称(可选,用于搜索)
14
+ # @return [Hash] API响应
15
+ def get_template_list(params: {})
16
+ config = @request_config && @request_config["template_list"]
17
+ raise JPSClient::ExceptionError, "Missing config for template_list" unless config && config["url"]
18
+
19
+ path = config["url"]
20
+
21
+ # 设置默认值
22
+ default_params = {
23
+ page: 1,
24
+ pageSize: 10
25
+ }
26
+ params = default_params.merge(params)
27
+
28
+ response = @http_client.post(path, body: params)
29
+ result = JPSClient::Response.new(response)
30
+
31
+ if result.need_login?
32
+ do_login(force_login: true)
33
+ response = @http_client.post(path, body: params)
34
+ result = JPSClient::Response.new(response)
35
+ end
36
+
37
+ return result.to_h
38
+ end
39
+
40
+ # 获取模板详情
41
+ #
42
+ # @param id [String, Integer] 模板ID(必需)
43
+ # @return [Hash] API响应
44
+ def get_template_detail(id:)
45
+ config = @request_config && @request_config["template_detail"]
46
+ raise JPSClient::ExceptionError, "Missing config for template_detail" unless config && config["url"]
47
+
48
+ path = config["url"]
49
+
50
+ # GET请求,ID作为查询参数
51
+ params = { id: id }
52
+
53
+ response = @http_client.get(path, params: params)
54
+ result = JPSClient::Response.new(response)
55
+
56
+ if result.need_login?
57
+ do_login(force_login: true)
58
+ response = @http_client.get(path, params: params)
59
+ result = JPSClient::Response.new(response)
60
+ end
61
+
62
+ return result.to_h
63
+ end
64
+
65
+ # 创建模板
66
+ #
67
+ # @param params [Hash] 模板信息参数
68
+ # - name: 模板名称(必需)
69
+ # - type: 模板类型(必需)
70
+ # - content: 模板内容(必需)
71
+ # - description: 模板描述(可选)
72
+ # @return [Hash] API响应
73
+ def create_template(params: {})
74
+ config = @request_config && @request_config["template_create"]
75
+ raise JPSClient::ExceptionError, "Missing config for template_create" unless config && config["url"]
76
+
77
+ # 参数验证
78
+ required_fields = [:name, :type, :content]
79
+ missing_fields = required_fields.select { |field| params[field].nil? || params[field].to_s.empty? }
80
+
81
+ if missing_fields.any?
82
+ raise JPSClient::ExceptionError, "Missing required fields: #{missing_fields.join(', ')}"
83
+ end
84
+
85
+ path = config["url"]
86
+
87
+ response = @http_client.post(path, body: params)
88
+ result = JPSClient::Response.new(response)
89
+
90
+ if result.need_login?
91
+ do_login(force_login: true)
92
+ response = @http_client.post(path, body: params)
93
+ result = JPSClient::Response.new(response)
94
+ end
95
+
96
+ return result.to_h
97
+ end
98
+
99
+ # 更新模板
100
+ #
101
+ # @param params [Hash] 更新参数
102
+ # - id: 模板ID(必需)
103
+ # - name: 模板名称
104
+ # - type: 模板类型
105
+ # - content: 模板内容
106
+ # - description: 模板描述
107
+ # @return [Hash] API响应
108
+ def update_template(params: {})
109
+ config = @request_config && @request_config["template_update"]
110
+ raise JPSClient::ExceptionError, "Missing config for template_update" unless config && config["url"]
111
+
112
+ # ID 是必需的
113
+ raise JPSClient::ExceptionError, "Missing required field: id" unless params[:id]
114
+
115
+ path = config["url"]
116
+
117
+ response = @http_client.post(path, body: params)
118
+ result = JPSClient::Response.new(response)
119
+
120
+ if result.need_login?
121
+ do_login(force_login: true)
122
+ response = @http_client.post(path, body: params)
123
+ result = JPSClient::Response.new(response)
124
+ end
125
+
126
+ return result.to_h
127
+ end
128
+
129
+ # 删除模板
130
+ #
131
+ # @param id [String, Integer] 模板ID(必需)
132
+ # @return [Hash] API响应
133
+ def delete_template(id:)
134
+ config = @request_config && @request_config["template_delete"]
135
+ raise JPSClient::ExceptionError, "Missing config for template_delete" unless config && config["url"]
136
+
137
+ path = config["url"]
138
+
139
+ # POST请求,ID作为body参数
140
+ params = { id: id }
141
+
142
+ response = @http_client.post(path, body: params)
143
+ result = JPSClient::Response.new(response)
144
+
145
+ if result.need_login?
146
+ do_login(force_login: true)
147
+ response = @http_client.post(path, body: params)
148
+ result = JPSClient::Response.new(response)
149
+ end
150
+
151
+ return result.to_h
152
+ end
153
+
154
+ # 批量获取模板(扩展方法)
155
+ # 注意:此方法会逐个调用 API,返回结果数组
156
+ #
157
+ # @param ids [Array<String, Integer>] 模板ID列表
158
+ # @return [Array<Hash>] 每个请求的响应结果
159
+ def get_templates_by_ids(ids: [])
160
+ return [] if ids.empty?
161
+
162
+ results = []
163
+ ids.each do |id|
164
+ result = get_template_detail(id: id)
165
+ results << result
166
+ end
167
+
168
+ results
169
+ end
170
+
171
+ # 按类型获取模板列表(便捷方法)
172
+ #
173
+ # @param type [String] 模板类型(message, document, email, report, other)
174
+ # @param params [Hash] 其他查询参数
175
+ # @return [Hash] API响应
176
+ def get_templates_by_type(type:, params: {})
177
+ params[:type] = type
178
+ get_template_list(params: params)
179
+ end
180
+
181
+ # 搜索模板(便捷方法)
182
+ #
183
+ # @param keyword [String] 搜索关键词
184
+ # @param params [Hash] 其他查询参数
185
+ # @return [Hash] API响应
186
+ def search_templates(keyword:, params: {})
187
+ params[:name] = keyword
188
+ get_template_list(params: params)
189
+ end
190
+
191
+ # 复制模板(创建模板副本)
192
+ #
193
+ # @param template_id [String, Integer] 源模板ID
194
+ # @param new_name [String] 新模板名称
195
+ # @return [Hash] API响应
196
+ def copy_template(template_id:, new_name:)
197
+ # 先获取原模板
198
+ original = get_template_detail(id: template_id)
199
+
200
+ # 如果获取失败,直接返回错误响应
201
+ return original unless original && original['data']
202
+
203
+ template_data = original['data']
204
+
205
+ # 创建新模板
206
+ create_template(params: {
207
+ name: new_name,
208
+ type: template_data['type'] || template_data[:type],
209
+ content: template_data['content'] || template_data[:content],
210
+ description: "Copy of #{template_data['name'] || template_data[:name]}: #{template_data['description'] || template_data[:description]}"
211
+ })
212
+ end
213
+
214
+ end
215
+ end
216
+ end
@@ -281,7 +281,7 @@ module JPSClient
281
281
  result = JSON.parse(response.body)
282
282
  puts "API 响应: #{result.inspect}" if @verbose
283
283
 
284
- if result['meta'] && result['meta']['code'] == 200 && result['data']
284
+ if result['meta'] && result['meta']['code'] == 0 && result['data']
285
285
  data = result['data']
286
286
  @access_token = data['token'] if data['token']
287
287
  @username = data['username'] if data['username']
@@ -120,9 +120,17 @@ module JPSClient
120
120
  @need_login = http_response[:need_login]
121
121
 
122
122
  if http_response[:body].is_a?(Hash)
123
- @code = http_response[:body]['code'] || http_response[:code]
124
- @data = http_response[:body]['data']
125
- @msg = http_response[:body]['msg'] || http_response[:body]['message']
123
+ # 处理 Meta 格式响应: {meta: {code: 0, message: "..."}, data: {...}}
124
+ if http_response[:body]['meta']
125
+ @code = http_response[:body]['meta']['code']
126
+ @msg = http_response[:body]['meta']['message']
127
+ @data = http_response[:body]['data']
128
+ # 处理直接格式响应: {code: 0, data: {...}, msg: "..."}
129
+ else
130
+ @code = http_response[:body]['code'] || http_response[:code]
131
+ @data = http_response[:body]['data']
132
+ @msg = http_response[:body]['msg'] || http_response[:body]['message']
133
+ end
126
134
  else
127
135
  @code = http_response[:code]
128
136
  @data = http_response[:body]
@@ -130,7 +138,8 @@ module JPSClient
130
138
  end
131
139
 
132
140
  def success?
133
- @success && @code.to_s == '200'
141
+ # 成功码从 200 改为 0,同时向后兼容 200
142
+ @success && (@code.to_s == '0' || @code.to_s == '200')
134
143
  end
135
144
 
136
145
  def need_login?
@@ -144,5 +153,16 @@ module JPSClient
144
153
  'msg' => @msg
145
154
  }
146
155
  end
156
+
157
+ # 添加新方法返回 meta 格式响应
158
+ def to_h_with_meta
159
+ {
160
+ 'meta' => {
161
+ 'code' => @code,
162
+ 'message' => @msg
163
+ },
164
+ 'data' => @data
165
+ }
166
+ end
147
167
  end
148
168
  end
@@ -139,7 +139,7 @@ module JPSClient
139
139
  upload_config: @upload_config
140
140
  )
141
141
 
142
- if complete_result && complete_result["code"] == 200
142
+ if complete_result && (complete_result["code"] == 0 || complete_result["code"] == 200)
143
143
  # 返回 URL 字符串以保持向后兼容
144
144
  upload_result = complete_result.dig("data", "url") || s3_key
145
145
  Logger.instance.fancyinfo_success("文件#{@upload_binary_file} 上传成功! 😎😎😎")
@@ -1,3 +1,3 @@
1
1
  module JPSClient
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end