jpsclient 0.2.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 (88) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/bin/jpsclient +28 -0
  4. data/lib/jpsclient/api/app_level.rb +138 -0
  5. data/lib/jpsclient/api/app_resource.rb +164 -0
  6. data/lib/jpsclient/api/app_resource_version.rb +52 -0
  7. data/lib/jpsclient/api/apple_account.rb +140 -0
  8. data/lib/jpsclient/api/application.rb +268 -0
  9. data/lib/jpsclient/api/application_category.rb +120 -0
  10. data/lib/jpsclient/api/application_design.rb +118 -0
  11. data/lib/jpsclient/api/application_income.rb +54 -0
  12. data/lib/jpsclient/api/application_sales.rb +52 -0
  13. data/lib/jpsclient/api/application_version.rb +77 -0
  14. data/lib/jpsclient/api/assets_category.rb +120 -0
  15. data/lib/jpsclient/api/bug.rb +140 -0
  16. data/lib/jpsclient/api/cert.rb +27 -0
  17. data/lib/jpsclient/api/client.rb +268 -0
  18. data/lib/jpsclient/api/collect.rb +52 -0
  19. data/lib/jpsclient/api/collection.rb +162 -0
  20. data/lib/jpsclient/api/commit_log.rb +104 -0
  21. data/lib/jpsclient/api/creative.rb +52 -0
  22. data/lib/jpsclient/api/custom_application.rb +230 -0
  23. data/lib/jpsclient/api/custom_application_web.rb +52 -0
  24. data/lib/jpsclient/api/document_text.rb +30 -0
  25. data/lib/jpsclient/api/experience.rb +143 -0
  26. data/lib/jpsclient/api/experience_category.rb +97 -0
  27. data/lib/jpsclient/api/fgui_export.rb +52 -0
  28. data/lib/jpsclient/api/file.rb +84 -0
  29. data/lib/jpsclient/api/game_assets.rb +140 -0
  30. data/lib/jpsclient/api/healthy.rb +30 -0
  31. data/lib/jpsclient/api/icon_and_snapshot.rb +54 -0
  32. data/lib/jpsclient/api/idea.rb +121 -0
  33. data/lib/jpsclient/api/jssdk.rb +30 -0
  34. data/lib/jpsclient/api/lark_bitable.rb +30 -0
  35. data/lib/jpsclient/api/lark_chat_group.rb +30 -0
  36. data/lib/jpsclient/api/lark_comment.rb +118 -0
  37. data/lib/jpsclient/api/lark_task.rb +140 -0
  38. data/lib/jpsclient/api/lark_task_list.rb +118 -0
  39. data/lib/jpsclient/api/lark_task_section.rb +74 -0
  40. data/lib/jpsclient/api/lark_user.rb +30 -0
  41. data/lib/jpsclient/api/lark_wiki_node.rb +30 -0
  42. data/lib/jpsclient/api/lark_wiki_space.rb +30 -0
  43. data/lib/jpsclient/api/lazy_client.rb +290 -0
  44. data/lib/jpsclient/api/login.rb +96 -0
  45. data/lib/jpsclient/api/m3u8.rb +30 -0
  46. data/lib/jpsclient/api/menu.rb +143 -0
  47. data/lib/jpsclient/api/modular_client.rb +228 -0
  48. data/lib/jpsclient/api/project.rb +46 -0
  49. data/lib/jpsclient/api/project_package.rb +249 -0
  50. data/lib/jpsclient/api/publisher.rb +165 -0
  51. data/lib/jpsclient/api/publisher_category.rb +142 -0
  52. data/lib/jpsclient/api/publisher_group.rb +118 -0
  53. data/lib/jpsclient/api/publisher_group_category.rb +120 -0
  54. data/lib/jpsclient/api/requirements.rb +143 -0
  55. data/lib/jpsclient/api/requirements_category.rb +97 -0
  56. data/lib/jpsclient/api/resource_category.rb +120 -0
  57. data/lib/jpsclient/api/role.rb +165 -0
  58. data/lib/jpsclient/api/simple_search.rb +162 -0
  59. data/lib/jpsclient/api/sketch.rb +74 -0
  60. data/lib/jpsclient/api/sketch_category.rb +97 -0
  61. data/lib/jpsclient/api/sov.rb +30 -0
  62. data/lib/jpsclient/api/statistics.rb +30 -0
  63. data/lib/jpsclient/api/store.rb +30 -0
  64. data/lib/jpsclient/api/survey.rb +143 -0
  65. data/lib/jpsclient/api/survey_category.rb +97 -0
  66. data/lib/jpsclient/api/tag.rb +142 -0
  67. data/lib/jpsclient/api/tool.rb +121 -0
  68. data/lib/jpsclient/api/tool_category.rb +120 -0
  69. data/lib/jpsclient/api/trending.rb +30 -0
  70. data/lib/jpsclient/api/ud_id.rb +118 -0
  71. data/lib/jpsclient/api/user.rb +99 -0
  72. data/lib/jpsclient/api/util.rb +30 -0
  73. data/lib/jpsclient/api/video_cover.rb +30 -0
  74. data/lib/jpsclient/api/webhook.rb +118 -0
  75. data/lib/jpsclient/api/workflow.rb +118 -0
  76. data/lib/jpsclient/auth/auth.rb +676 -0
  77. data/lib/jpsclient/auth/token.rb +209 -0
  78. data/lib/jpsclient/base/api_config.rb +225 -0
  79. data/lib/jpsclient/base/exception.rb +5 -0
  80. data/lib/jpsclient/http/http_client.rb +148 -0
  81. data/lib/jpsclient/upload/upload_client.rb +334 -0
  82. data/lib/jpsclient/upload/upload_config.rb +128 -0
  83. data/lib/jpsclient/upload/upload_progress.rb +73 -0
  84. data/lib/jpsclient/utils/aes.rb +49 -0
  85. data/lib/jpsclient/utils/logger.rb +38 -0
  86. data/lib/jpsclient/version.rb +3 -0
  87. data/lib/jpsclient.rb +34 -0
  88. metadata +269 -0
@@ -0,0 +1,120 @@
1
+ module JPSClient
2
+ module API
3
+ # AssetsCategory 相关 API
4
+ # 自动生成的模块,处理 assets_category 相关接口
5
+ module AssetsCategory
6
+
7
+ # Update Assets Category
8
+ #
9
+ # @param params [Hash] 请求参数
10
+ # @return [Hash] API响应
11
+ def update_assets_category(categoryId:, params: {})
12
+ config = @request_config && @request_config["assets_category_assets_category"]
13
+ raise JPSClient::ExceptionError, "Missing config for assets_category_assets_category" unless config && config["url"]
14
+
15
+ path = config["url"]
16
+ path = path.gsub("{categoryId}", categoryId.to_s)
17
+
18
+ response = @http_client.put(path, body: params)
19
+ result = JPSClient::Response.new(response)
20
+
21
+ if result.need_login?
22
+ do_login(force_login: true)
23
+ response = @http_client.put(path, body: params)
24
+ result = JPSClient::Response.new(response)
25
+ end
26
+
27
+ return result.to_h
28
+ end
29
+
30
+ # Delete Assets Category
31
+ #
32
+ # @param params [Hash] 请求参数
33
+ # @return [Hash] API响应
34
+ def delete_assets_category(categoryId:, params: {})
35
+ config = @request_config && @request_config["assets_category_assets_category"]
36
+ raise JPSClient::ExceptionError, "Missing config for assets_category_assets_category" unless config && config["url"]
37
+
38
+ path = config["url"]
39
+ path = path.gsub("{categoryId}", categoryId.to_s)
40
+
41
+ response = @http_client.delete(path)
42
+ result = JPSClient::Response.new(response)
43
+
44
+ if result.need_login?
45
+ do_login(force_login: true)
46
+ response = @http_client.delete(path)
47
+ result = JPSClient::Response.new(response)
48
+ end
49
+
50
+ return result.to_h
51
+ end
52
+
53
+ # Create Assets Category
54
+ #
55
+ # @param params [Hash] 请求参数
56
+ # @return [Hash] API响应
57
+ def create_assets_category(params: {})
58
+ config = @request_config && @request_config["assets_category_assets_category"]
59
+ raise JPSClient::ExceptionError, "Missing config for assets_category_assets_category" unless config && config["url"]
60
+
61
+ path = config["url"]
62
+
63
+ response = @http_client.post(path, body: params)
64
+ result = JPSClient::Response.new(response)
65
+
66
+ if result.need_login?
67
+ do_login(force_login: true)
68
+ response = @http_client.post(path, body: params)
69
+ result = JPSClient::Response.new(response)
70
+ end
71
+
72
+ return result.to_h
73
+ end
74
+
75
+ # Create Weights
76
+ #
77
+ # @param params [Hash] 请求参数
78
+ # @return [Hash] API响应
79
+ def create_weights(params: {})
80
+ config = @request_config && @request_config["assets_category_weights"]
81
+ raise JPSClient::ExceptionError, "Missing config for assets_category_weights" unless config && config["url"]
82
+
83
+ path = config["url"]
84
+
85
+ response = @http_client.post(path, body: params)
86
+ result = JPSClient::Response.new(response)
87
+
88
+ if result.need_login?
89
+ do_login(force_login: true)
90
+ response = @http_client.post(path, body: params)
91
+ result = JPSClient::Response.new(response)
92
+ end
93
+
94
+ return result.to_h
95
+ end
96
+
97
+ # Create Assets Categories
98
+ #
99
+ # @param params [Hash] 请求参数
100
+ # @return [Hash] API响应
101
+ def create_assets_categories(params: {})
102
+ config = @request_config && @request_config["assets_category_assets_categories"]
103
+ raise JPSClient::ExceptionError, "Missing config for assets_category_assets_categories" unless config && config["url"]
104
+
105
+ path = config["url"]
106
+
107
+ response = @http_client.post(path, body: params)
108
+ result = JPSClient::Response.new(response)
109
+
110
+ if result.need_login?
111
+ do_login(force_login: true)
112
+ response = @http_client.post(path, body: params)
113
+ result = JPSClient::Response.new(response)
114
+ end
115
+
116
+ return result.to_h
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,140 @@
1
+ module JPSClient
2
+ module API
3
+ # Bug 相关 API
4
+ # 自动生成的模块,处理 bug 相关接口
5
+ module Bug
6
+
7
+ # Create Update
8
+ #
9
+ # @param params [Hash] 请求参数
10
+ # @return [Hash] API响应
11
+ def create_update(params: {})
12
+ config = @request_config && @request_config["bug_update"]
13
+ raise JPSClient::ExceptionError, "Missing config for bug_update" unless config && config["url"]
14
+
15
+ path = config["url"]
16
+
17
+ response = @http_client.post(path, body: params)
18
+ result = JPSClient::Response.new(response)
19
+
20
+ if result.need_login?
21
+ do_login(force_login: true)
22
+ response = @http_client.post(path, body: params)
23
+ result = JPSClient::Response.new(response)
24
+ end
25
+
26
+ return result.to_h
27
+ end
28
+
29
+ # Get List
30
+ #
31
+ # @param params [Hash] 请求参数
32
+ # @return [Hash] API响应
33
+ def get_list(params: {})
34
+ config = @request_config && @request_config["bug_list"]
35
+ raise JPSClient::ExceptionError, "Missing config for bug_list" unless config && config["url"]
36
+
37
+ path = config["url"]
38
+
39
+ response = @http_client.post(path, body: params)
40
+ result = JPSClient::Response.new(response)
41
+
42
+ if result.need_login?
43
+ do_login(force_login: true)
44
+ response = @http_client.post(path, body: params)
45
+ result = JPSClient::Response.new(response)
46
+ end
47
+
48
+ return result.to_h
49
+ end
50
+
51
+ # Create Delete
52
+ #
53
+ # @param params [Hash] 请求参数
54
+ # @return [Hash] API响应
55
+ def create_delete(params: {})
56
+ config = @request_config && @request_config["bug_delete"]
57
+ raise JPSClient::ExceptionError, "Missing config for bug_delete" unless config && config["url"]
58
+
59
+ path = config["url"]
60
+
61
+ response = @http_client.post(path, body: params)
62
+ result = JPSClient::Response.new(response)
63
+
64
+ if result.need_login?
65
+ do_login(force_login: true)
66
+ response = @http_client.post(path, body: params)
67
+ result = JPSClient::Response.new(response)
68
+ end
69
+
70
+ return result.to_h
71
+ end
72
+
73
+ # Create Create
74
+ #
75
+ # @param params [Hash] 请求参数
76
+ # @return [Hash] API响应
77
+ def create_create(params: {})
78
+ config = @request_config && @request_config["bug_create"]
79
+ raise JPSClient::ExceptionError, "Missing config for bug_create" unless config && config["url"]
80
+
81
+ path = config["url"]
82
+
83
+ response = @http_client.post(path, body: params)
84
+ result = JPSClient::Response.new(response)
85
+
86
+ if result.need_login?
87
+ do_login(force_login: true)
88
+ response = @http_client.post(path, body: params)
89
+ result = JPSClient::Response.new(response)
90
+ end
91
+
92
+ return result.to_h
93
+ end
94
+
95
+ # Get Fields
96
+ #
97
+ # @param params [Hash] 请求参数
98
+ # @return [Hash] API响应
99
+ def get_fields(params: {})
100
+ config = @request_config && @request_config["bug_fields"]
101
+ raise JPSClient::ExceptionError, "Missing config for bug_fields" unless config && config["url"]
102
+
103
+ path = config["url"]
104
+
105
+ response = @http_client.get(path, params: params)
106
+ result = JPSClient::Response.new(response)
107
+
108
+ if result.need_login?
109
+ do_login(force_login: true)
110
+ response = @http_client.get(path, params: params)
111
+ result = JPSClient::Response.new(response)
112
+ end
113
+
114
+ return result.to_h
115
+ end
116
+
117
+ # Get Detail
118
+ #
119
+ # @param params [Hash] 请求参数
120
+ # @return [Hash] API响应
121
+ def get_detail(params: {})
122
+ config = @request_config && @request_config["bug_detail"]
123
+ raise JPSClient::ExceptionError, "Missing config for bug_detail" unless config && config["url"]
124
+
125
+ path = config["url"]
126
+
127
+ response = @http_client.get(path, params: params)
128
+ result = JPSClient::Response.new(response)
129
+
130
+ if result.need_login?
131
+ do_login(force_login: true)
132
+ response = @http_client.get(path, params: params)
133
+ result = JPSClient::Response.new(response)
134
+ end
135
+
136
+ return result.to_h
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,27 @@
1
+ module JPSClient
2
+ module API
3
+ # 证书相关 API
4
+ # 处理 /api/cert/* 路径的所有接口
5
+ module Cert
6
+
7
+ # 获取证书列表
8
+ def get_cert_list()
9
+ path = @request_config["cert_list"]["url"]
10
+
11
+ response = @http_client.get(path)
12
+ result = JPSClient::Response.new(response)
13
+
14
+ # 处理 401 错误,自动重新登录
15
+ if result.need_login?
16
+ do_login(force_login: true)
17
+ # 重试请求
18
+ response = @http_client.get(path)
19
+ result = JPSClient::Response.new(response)
20
+ end
21
+
22
+ return result.to_h
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,268 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'jpsclient/base/exception'
4
+ require 'jpsclient/base/api_config'
5
+ require 'jpsclient/utils/aes'
6
+ require 'jpsclient/http/http_client'
7
+ require 'jpsclient/auth/auth'
8
+ require 'jpsclient/auth/token'
9
+ require 'jpsclient/utils/logger'
10
+
11
+ # 加载 API 模块
12
+ require 'jpsclient/api/app_level'
13
+ require 'jpsclient/api/app_resource'
14
+ require 'jpsclient/api/app_resource_version'
15
+ require 'jpsclient/api/apple_account'
16
+ require 'jpsclient/api/application'
17
+ require 'jpsclient/api/application_category'
18
+ require 'jpsclient/api/application_design'
19
+ require 'jpsclient/api/application_income'
20
+ require 'jpsclient/api/application_sales'
21
+ require 'jpsclient/api/application_version'
22
+ require 'jpsclient/api/assets_category'
23
+ require 'jpsclient/api/bug'
24
+ require 'jpsclient/api/cert'
25
+ require 'jpsclient/api/collect'
26
+ require 'jpsclient/api/collection'
27
+ require 'jpsclient/api/commit_log'
28
+ require 'jpsclient/api/creative'
29
+ require 'jpsclient/api/custom_application'
30
+ require 'jpsclient/api/custom_application_web'
31
+ require 'jpsclient/api/document_text'
32
+ require 'jpsclient/api/experience'
33
+ require 'jpsclient/api/experience_category'
34
+ require 'jpsclient/api/fgui_export'
35
+ require 'jpsclient/api/file'
36
+ require 'jpsclient/api/game_assets'
37
+ require 'jpsclient/api/healthy'
38
+ require 'jpsclient/api/icon_and_snapshot'
39
+ require 'jpsclient/api/idea'
40
+ require 'jpsclient/api/jssdk'
41
+ require 'jpsclient/api/lark_bitable'
42
+ require 'jpsclient/api/lark_chat_group'
43
+ require 'jpsclient/api/lark_comment'
44
+ require 'jpsclient/api/lark_task'
45
+ require 'jpsclient/api/lark_task_list'
46
+ require 'jpsclient/api/lark_task_section'
47
+ require 'jpsclient/api/lark_user'
48
+ require 'jpsclient/api/lark_wiki_node'
49
+ require 'jpsclient/api/lark_wiki_space'
50
+ require 'jpsclient/api/login'
51
+ require 'jpsclient/api/m3u8'
52
+ require 'jpsclient/api/menu'
53
+ require 'jpsclient/api/project'
54
+ require 'jpsclient/api/project_package'
55
+ require 'jpsclient/api/publisher'
56
+ require 'jpsclient/api/publisher_category'
57
+ require 'jpsclient/api/publisher_group'
58
+ require 'jpsclient/api/publisher_group_category'
59
+ require 'jpsclient/api/requirements'
60
+ require 'jpsclient/api/requirements_category'
61
+ require 'jpsclient/api/resource_category'
62
+ require 'jpsclient/api/role'
63
+ require 'jpsclient/api/simple_search'
64
+ require 'jpsclient/api/sketch'
65
+ require 'jpsclient/api/sketch_category'
66
+ require 'jpsclient/api/sov'
67
+ require 'jpsclient/api/statistics'
68
+ require 'jpsclient/api/store'
69
+ require 'jpsclient/api/survey'
70
+ require 'jpsclient/api/survey_category'
71
+ require 'jpsclient/api/tag'
72
+ require 'jpsclient/api/tool'
73
+ require 'jpsclient/api/tool_category'
74
+ require 'jpsclient/api/trending'
75
+ require 'jpsclient/api/ud_id'
76
+ require 'jpsclient/api/user'
77
+ require 'jpsclient/api/util'
78
+ require 'jpsclient/api/video_cover'
79
+ require 'jpsclient/api/webhook'
80
+ require 'jpsclient/api/workflow'
81
+
82
+ module JPSClient
83
+
84
+ class Client
85
+ # 引入各个 API 模块
86
+ include API::AppLevel
87
+ include API::AppResource
88
+ include API::AppResourceVersion
89
+ include API::AppleAccount
90
+ include API::Application
91
+ include API::ApplicationCategory
92
+ include API::ApplicationDesign
93
+ include API::ApplicationIncome
94
+ include API::ApplicationSales
95
+ include API::ApplicationVersion
96
+ include API::AssetsCategory
97
+ include API::Bug
98
+ include API::Cert
99
+ include API::Collect
100
+ include API::Collection
101
+ include API::CommitLog
102
+ include API::Creative
103
+ include API::CustomApplication
104
+ include API::CustomApplicationWeb
105
+ include API::DocumentText
106
+ include API::Experience
107
+ include API::ExperienceCategory
108
+ include API::FguiExport
109
+ include API::File
110
+ include API::GameAssets
111
+ include API::Healthy
112
+ include API::IconAndSnapshot
113
+ include API::Idea
114
+ include API::Jssdk
115
+ include API::LarkBitable
116
+ include API::LarkChatGroup
117
+ include API::LarkComment
118
+ include API::LarkTask
119
+ include API::LarkTaskList
120
+ include API::LarkTaskSection
121
+ include API::LarkUser
122
+ include API::LarkWikiNode
123
+ include API::LarkWikiSpace
124
+ include API::Login
125
+ include API::M3u8
126
+ include API::Menu
127
+ include API::Project
128
+ include API::ProjectPackage
129
+ include API::Publisher
130
+ include API::PublisherCategory
131
+ include API::PublisherGroup
132
+ include API::PublisherGroupCategory
133
+ include API::Requirements
134
+ include API::RequirementsCategory
135
+ include API::ResourceCategory
136
+ include API::Role
137
+ include API::SimpleSearch
138
+ include API::Sketch
139
+ include API::SketchCategory
140
+ include API::Sov
141
+ include API::Statistics
142
+ include API::Store
143
+ include API::Survey
144
+ include API::SurveyCategory
145
+ include API::Tag
146
+ include API::Tool
147
+ include API::ToolCategory
148
+ include API::Trending
149
+ include API::UdId
150
+ include API::User
151
+ include API::Util
152
+ include API::VideoCover
153
+ include API::Webhook
154
+ include API::Workflow
155
+
156
+ attr_accessor :token
157
+ attr_accessor :baseurl
158
+ attr_accessor :request_config
159
+ attr_accessor :http_client
160
+ attr_accessor :api_config
161
+ attr_reader :config_json # 暴露配置供其他模块使用
162
+ attr_reader :config_file # 配置文件路径
163
+
164
+ def initialize(config_file:)
165
+ begin
166
+ @config_file = config_file
167
+
168
+ raise ExceptionError, "必须提供配置文件路径" unless @config_file
169
+ raise ExceptionError, "配置文件不存在: #{@config_file}" unless File.exist?(@config_file)
170
+
171
+ @config_json = JSON.parse(File.read(@config_file))
172
+
173
+ @baseurl = @config_json["pgyerapps_base_url"]
174
+ @request_config = @config_json["api_path_config"]
175
+
176
+ # 初始化API配置管理器
177
+ @api_config = ApiConfig.new(@config_json)
178
+
179
+ # 从 auth_config 获取配置
180
+ auth_config = @config_json["auth_config"]
181
+ @pgyer_aes_key = auth_config["aes_key"]
182
+
183
+ # 加载 JPS 登录配置
184
+ @jps_config = LoginConfig.from_json(auth_config)
185
+
186
+ # 初始化 token 管理器
187
+ @token_manager = Token.new(@jps_config)
188
+
189
+ # 尝试加载已保存的 token
190
+ if @token_manager.load && @token_manager.valid?
191
+ @token = @token_manager.to_h
192
+ end
193
+
194
+ # 初始化共享的 HTTP 客户端
195
+ @http_client = HttpClient.new(base_url: @baseurl)
196
+ @http_client.update_token(@token["token"]) if @token && @token["token"]
197
+
198
+ rescue JSON::ParserError => error
199
+ raise ExceptionError.new("配置文件格式错误 (#{@config_file}): #{error.message}")
200
+ rescue ExceptionError
201
+ raise # 重新抛出 JPS 异常
202
+ rescue => error
203
+ raise ExceptionError.new("加载配置文件失败 (#{@config_file}): #{error.message}")
204
+ end
205
+ end
206
+
207
+ # 提供共享的HTTP客户端给其他模块
208
+ def shared_http_client
209
+ @http_client
210
+ end
211
+
212
+ # 核心登录功能
213
+ def do_login(force_login:false)
214
+ # 使用 token 管理器统一处理
215
+ if force_login
216
+ # 强制重新登录
217
+ @token_manager.clear # 清除旧 token
218
+ auth = Auth.new(@jps_config)
219
+ result = auth.login
220
+
221
+ if result == :user_cancelled
222
+ Logger.instance.fancyinfo_error("用户取消了登录操作")
223
+ return false
224
+ elsif result == true
225
+ # 保存新 token
226
+ @token_manager.save(auth.access_token, auth.username, auth.expires_at)
227
+ update_token_everywhere()
228
+ return true
229
+ else
230
+ Logger.instance.fancyinfo_error("登录失败,未能获取有效token")
231
+ return false
232
+ end
233
+ else
234
+ # 尝试加载并验证现有 token
235
+ if @token_manager.load && @token_manager.valid?
236
+ update_token_everywhere()
237
+ return true
238
+ else
239
+ # Token 无效或不存在,需要重新登录
240
+ auth = Auth.new(@jps_config)
241
+ result = auth.login
242
+
243
+ if result == :user_cancelled
244
+ Logger.instance.fancyinfo_error("用户取消了登录操作")
245
+ return false
246
+ elsif result == true
247
+ # 保存新 token
248
+ @token_manager.save(auth.access_token, auth.username, auth.expires_at)
249
+ update_token_everywhere()
250
+ return true
251
+ else
252
+ Logger.instance.fancyinfo_error("登录失败,未能获取有效token")
253
+ return false
254
+ end
255
+ end
256
+ end
257
+ end
258
+
259
+ private
260
+
261
+ # 统一更新token到所有组件
262
+ def update_token_everywhere
263
+ @token = @token_manager.to_h
264
+ @http_client.update_token(@token["token"]) if @http_client && @token
265
+ end
266
+
267
+ end
268
+ end
@@ -0,0 +1,52 @@
1
+ module JPSClient
2
+ module API
3
+ # Collect 相关 API
4
+ # 自动生成的模块,处理 collect 相关接口
5
+ module Collect
6
+
7
+ # Create Collect
8
+ #
9
+ # @param params [Hash] 请求参数
10
+ # @return [Hash] API响应
11
+ def create_collect(params: {})
12
+ config = @request_config && @request_config["collect_collect"]
13
+ raise JPSClient::ExceptionError, "Missing config for collect_collect" unless config && config["url"]
14
+
15
+ path = config["url"]
16
+
17
+ response = @http_client.post(path, body: params)
18
+ result = JPSClient::Response.new(response)
19
+
20
+ if result.need_login?
21
+ do_login(force_login: true)
22
+ response = @http_client.post(path, body: params)
23
+ result = JPSClient::Response.new(response)
24
+ end
25
+
26
+ return result.to_h
27
+ end
28
+
29
+ # Delete Collect
30
+ #
31
+ # @param params [Hash] 请求参数
32
+ # @return [Hash] API响应
33
+ def delete_collect(params: {})
34
+ config = @request_config && @request_config["collect_collect"]
35
+ raise JPSClient::ExceptionError, "Missing config for collect_collect" unless config && config["url"]
36
+
37
+ path = config["url"]
38
+
39
+ response = @http_client.delete(path)
40
+ result = JPSClient::Response.new(response)
41
+
42
+ if result.need_login?
43
+ do_login(force_login: true)
44
+ response = @http_client.delete(path)
45
+ result = JPSClient::Response.new(response)
46
+ end
47
+
48
+ return result.to_h
49
+ end
50
+ end
51
+ end
52
+ end