growi-client 0.9.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.
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "growi/client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "growi-client"
8
+ spec.version = Growi::Client::VERSION
9
+ spec.authors = ["Ryu Sato"]
10
+ spec.email = ["ryu@weseek.co.jp"]
11
+
12
+ spec.summary = %q{Client of growi}
13
+ spec.description = %q{growi-client is client of growi with use API.}
14
+ spec.homepage = "https://github.com/ryu-sato/growi-client"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ #spec.metadata["allowed_push_host"] = "http://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "rspec-json_matcher", "~> 0.1"
37
+
38
+ spec.add_dependency "rest-client", "~> 2.0"
39
+ spec.add_dependency "json", "~> 2.1"
40
+ end
@@ -0,0 +1 @@
1
+ require 'growi/client/client'
@@ -0,0 +1,140 @@
1
+ require_relative 'api_request_base'
2
+
3
+ # 添付ファイル一覧リクエスト用クラス
4
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/attachment.js
5
+ class GApiRequestAttachmentsList < GApiRequestBase
6
+
7
+ # コンストラクタ
8
+ # @override
9
+ # @param [Hash] param APIリクエストのパラメータ
10
+ def initialize(param = {})
11
+ super('/_api/attachments.list', METHOD_GET, { page_id: param[:page_id] })
12
+ end
13
+
14
+ # リクエストを実行する
15
+ # @override
16
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
17
+ # @param [Hash] rest_client_param RestClientのパラメータ
18
+ # @return [Array] リクエスト実行結果
19
+ def execute(entry_point, rest_client_param: {})
20
+ if invalid?
21
+ return validation_msg
22
+ end
23
+ params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
24
+ ret = JSON.parse RestClient::Request.execute params
25
+ if (ret['ok'] == false)
26
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
27
+ end
28
+ attachments = []
29
+ ret['attachments'].each do |attachment|
30
+ attachments.push(GrowiAttachment.new(attachment))
31
+ end
32
+ return GApiReturn.new(ok: ret['ok'], data: attachments)
33
+ end
34
+
35
+ protected
36
+
37
+ # バリデーションエラーを取得する
38
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
39
+ def _invalid
40
+ if ! (@param[:page_id])
41
+ CPInvalidRequest.new 'Parameter page_id is required.'
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ # 添付ファイル追加リクエスト用クラス
48
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/attachment.js
49
+ class GApiRequestAttachmentsAdd < GApiRequestBase
50
+
51
+ # コンストラクタ
52
+ # @override
53
+ # @param [Hash] param APIリクエストのパラメータ
54
+ def initialize(param = {})
55
+ super('/_api/attachments.add', METHOD_POST,
56
+ { page_id: param[:page_id], file: param[:file] })
57
+ end
58
+
59
+ # リクエストを実行する
60
+ # @override
61
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
62
+ # @param [Hash] rest_client_param RestClientのパラメータ
63
+ # @return [Array] リクエスト実行結果
64
+ def execute(entry_point, rest_client_param: {})
65
+ if invalid?
66
+ return validation_msg
67
+ end
68
+ params = {
69
+ method: :post,
70
+ url: entry_point,
71
+ payload: {
72
+ access_token: @param[:access_token],
73
+ page_id: @param[:page_id],
74
+ file: @param[:file]
75
+ }
76
+ }.merge(rest_client_param)
77
+ ret = JSON.parse RestClient::Request.execute params
78
+ if (ret['ok'] == false)
79
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
80
+ end
81
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
82
+ end
83
+
84
+ protected
85
+
86
+ # バリデーションエラーを取得する
87
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
88
+ def _invalid
89
+ if ! (@param[:file] && @param[:page_id])
90
+ CPInvalidRequest.new 'Parameters file and page_id are required.'
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+
97
+ # 添付ファイル削除リクエスト用クラス
98
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/attachment.js
99
+ class GApiRequestAttachmentsRemove < GApiRequestBase
100
+
101
+ # コンストラクタ
102
+ # @override
103
+ # @param [Hash] param APIリクエストのパラメータ
104
+ def initialize(param = {})
105
+ super('/_api/attachments.remove', METHOD_POST,
106
+ { attachment_id: param[:attachment_id] })
107
+ end
108
+
109
+ # リクエストを実行する
110
+ # @override
111
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
112
+ # @param [Hash] rest_client_param RestClientのパラメータ
113
+ # @return [Array] リクエスト実行結果
114
+ def execute(entry_point, rest_client_param: {})
115
+ if invalid?
116
+ return validation_msg
117
+ end
118
+ params = { method: :post, url: entry_point,
119
+ payload: @param.to_json,
120
+ headers: { content_type: :json, accept: :json }
121
+ }.merge(rest_client_param)
122
+ ret = JSON.parse RestClient::Request.execute params
123
+ if (ret['ok'] == false)
124
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
125
+ end
126
+ return GApiReturn.new(ok: ret['ok'], data: nil)
127
+ end
128
+
129
+ protected
130
+
131
+ # バリデーションエラーを取得する
132
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
133
+ def _invalid
134
+ if ! (@param[:attachment_id])
135
+ CPInvalidRequest.new 'Parameter attachment_id is required.'
136
+ end
137
+ end
138
+
139
+ end
140
+
@@ -0,0 +1,106 @@
1
+ # APIリクエストのバリデーションエラー
2
+ # @note rescue する必要はないので Exception クラスは継承しない
3
+ class CPInvalidRequest
4
+ attr_reader :msg
5
+
6
+ # コンストラクタ
7
+ # @param [String] msg エラーメッセージ(原因と対策が分かるとよい)
8
+ def initialize(msg)
9
+ @msg = msg
10
+ end
11
+
12
+ # Convert string
13
+ # @return [String] Message
14
+ def to_s
15
+ return @msg
16
+ end
17
+ end
18
+
19
+ # APIリクエストの応答基本クラス
20
+ class GApiReturn
21
+ attr_accessor :ok, :data
22
+
23
+ # Constractor
24
+ # @param [String] ok Result of API
25
+ def initialize(params = {})
26
+ if (! params[:ok].is_a?(TrueClass) && ! params[:ok].is_a?(FalseClass))
27
+ raise ArgumentError.new('Parameter ok is needed true or false.')
28
+ end
29
+ @ok = params[:ok]
30
+ @data = params[:data]
31
+ end
32
+
33
+ end
34
+
35
+ # APIリクエストの基本クラス
36
+ class GApiRequestBase
37
+ METHOD_GET = "GET"
38
+ METHOD_POST = "POST"
39
+ attr_reader :entry_point, :method, :param
40
+
41
+ # コンストラクタ
42
+ # @param [String] entry_point APIリクエストのエントリポイントとなるURLパス(ex. '/page.list')
43
+ # @param [Enumerator] method APIリクエストのタイプ
44
+ # @param [Hash] param APIリクエストのパラメータ
45
+ def initialize(entry_point, method, param = {})
46
+ @entry_point = entry_point
47
+ @method = method
48
+ @param = param.reject { |k, v| !v }
49
+ end
50
+
51
+ # パラメータを代入
52
+ # @param [Hash] param APIリクエストのパラメータ
53
+ def param=(param = {})
54
+ @param = param
55
+ end
56
+
57
+ # パラメータのバリデーションチェックを行う
58
+ # @return [true/false] バリデーションチェック結果
59
+ def valid?
60
+ return (!_invalid)
61
+ end
62
+
63
+ # パラメータのバリデーションチェックを行う
64
+ # @return [true/false] バリデーションチェック結果
65
+ def invalid?
66
+ return (_invalid)
67
+ end
68
+
69
+ # バリデーションエラーの説明
70
+ # @return [String] バリデーションエラーの説明
71
+ def validation_msg
72
+ return _invalid&.to_s
73
+ end
74
+
75
+ # リクエストを実行する
76
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
77
+ # @param [Hash] rest_client_param RestClientのパラメータ
78
+ # @return [String] リクエスト実行結果(GApiReturnオブジェクト)
79
+ def execute(entry_point, rest_client_param: {})
80
+
81
+ if invalid?
82
+ return validation_msg
83
+ end
84
+
85
+ case @method
86
+ when 'GET'
87
+ params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
88
+ when 'POST'
89
+ params = { method: :post, url: entry_point, content_type: :json, accept: :json,
90
+ headers: { params: @param.to_json } }.merge()
91
+ end
92
+ ret_json = RestClient::Request.execute params
93
+ ret = JSON.parse(ret_json)
94
+ return GApiReturn.new(ok: ret['ok'], data: ret.reject { |k,v| k == 'ok' })
95
+ end
96
+
97
+ protected
98
+
99
+ # バリデーションエラーを取得する
100
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
101
+ def _invalid
102
+ return CPInvalidRequest "Invalid API request.";
103
+ end
104
+
105
+ end
106
+
@@ -0,0 +1,421 @@
1
+ require_relative 'api_request_base'
2
+ require 'growi/client/model/growi_page'
3
+
4
+ # ページ一覧リクエスト用クラス
5
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
6
+ class GApiRequestPagesList < GApiRequestBase
7
+
8
+ # コンストラクタ
9
+ # @override
10
+ # @param [Hash] param APIリクエストのパラメータ
11
+ def initialize(param = {})
12
+ super('/_api/pages.list', METHOD_GET,
13
+ { path: param[:path_exp], user: param[:user] })
14
+ end
15
+
16
+ # リクエストを実行する
17
+ # @override
18
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
19
+ # @param [Hash] rest_client_param RestClientのパラメータ
20
+ # @return [Array] リクエスト実行結果
21
+ def execute(entry_point, rest_client_param: {})
22
+
23
+ if invalid?
24
+ return validation_msg
25
+ end
26
+
27
+ params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
28
+ ret = JSON.parse RestClient::Request.execute params
29
+ if (ret['ok'] == false)
30
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
31
+ end
32
+ pages = []
33
+ ret['pages'].each do |page|
34
+ pages.push(GrowiPage.new(page))
35
+ end
36
+ return GApiReturn.new(ok: ret['ok'], data: pages)
37
+ end
38
+
39
+ protected
40
+
41
+ # バリデーションエラーを取得する
42
+ # @override
43
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
44
+ def _invalid
45
+ if ! (@param[:path] || @param[:user])
46
+ return CPInvalidRequest.new 'Parameter path or user is required.'
47
+ end
48
+ if (@param[:path] && @param[:user])
49
+ return CPInvalidRequest.new 'Parameter path and user can not be specified both.'
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+
56
+ # ページ取得リクエスト用クラス
57
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
58
+ class GApiRequestPagesGet < GApiRequestBase
59
+
60
+ # コンストラクタ
61
+ # @override
62
+ # @param [Hash] param APIリクエストのパラメータ
63
+ def initialize(param = {})
64
+ super('/_api/pages.get', METHOD_GET,
65
+ { page_id: param[:page_id],
66
+ path: param[:path], revision_id: param[:revision_id] })
67
+ end
68
+
69
+ # リクエストを実行する
70
+ # @override
71
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
72
+ # @param [Hash] rest_client_param RestClientのパラメータ
73
+ # @return [Array] リクエスト実行結果
74
+ def execute(entry_point, rest_client_param: {})
75
+
76
+ if invalid?
77
+ return validation_msg
78
+ end
79
+ params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
80
+ ret = JSON.parse RestClient::Request.execute params
81
+ if (ret['ok'] == false)
82
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
83
+ end
84
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
85
+ end
86
+
87
+ protected
88
+
89
+ # バリデーションエラーを取得する
90
+ # @override
91
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
92
+ def _invalid
93
+ if ! (@param[:path] || @param[:page_id])
94
+ return CPInvalidRequest.new 'Parameter path or page_id is required.'
95
+ end
96
+ end
97
+
98
+ end
99
+
100
+
101
+ # ページ作成リクエスト用クラス
102
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
103
+ class GApiRequestPagesCreate < GApiRequestBase
104
+
105
+ # コンストラクタ
106
+ # @override
107
+ # @param [Hash] param APIリクエストのパラメータ
108
+ def initialize(param = {})
109
+ super('/_api/pages.create', METHOD_POST,
110
+ { body: param[:body], path: param[:path], grant: param[:grant] })
111
+ end
112
+
113
+ # リクエストを実行する
114
+ # @override
115
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
116
+ # @param [Hash] rest_client_param RestClientのパラメータ
117
+ # @return [Array] リクエスト実行結果
118
+ def execute(entry_point, rest_client_param: {})
119
+
120
+ if invalid?
121
+ return validation_msg
122
+ end
123
+
124
+ params = { method: :post, url: entry_point,
125
+ payload: @param.to_json,
126
+ headers: { content_type: :json, accept: :json }
127
+ }.merge(rest_client_param)
128
+ ret = JSON.parse RestClient::Request.execute params
129
+ if (ret['ok'] == false)
130
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
131
+ end
132
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
133
+ end
134
+
135
+ protected
136
+
137
+ # バリデーションエラーを取得する
138
+ # @override
139
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
140
+ def _invalid
141
+ if ! (@param[:body] && @param[:path])
142
+ return CPInvalidRequest.new 'Parameters body and path are required.'
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ # ページ更新リクエスト用クラス
149
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
150
+ class GApiRequestPagesUpdate < GApiRequestBase
151
+
152
+ # コンストラクタ
153
+ # @override
154
+ # @param [Hash] param APIリクエストのパラメータ
155
+ def initialize(param = {})
156
+ super('/_api/pages.update', METHOD_POST,
157
+ { body: param[:body], page_id: param[:page_id],
158
+ revision_id: param[:revision_id], grant: param[:grant] })
159
+ end
160
+
161
+ # リクエストを実行する
162
+ # @override
163
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
164
+ # @param [Hash] rest_client_param RestClientのパラメータ
165
+ # @return [Array] リクエスト実行結果
166
+ def execute(entry_point, rest_client_param: {})
167
+
168
+ if invalid?
169
+ return validation_msg
170
+ end
171
+ params = { method: :post, url: entry_point,
172
+ payload: @param.to_json,
173
+ headers: { content_type: :json, accept: :json }
174
+ }.merge(rest_client_param)
175
+ ret = JSON.parse RestClient::Request.execute params
176
+ if (ret['ok'] == false)
177
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
178
+ end
179
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
180
+ end
181
+
182
+ protected
183
+
184
+ # バリデーションエラーを取得する
185
+ # @override
186
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
187
+ def _invalid
188
+ if ! (@param[:page_id] && @param[:body])
189
+ return CPInvalidRequest.new 'Parameters page_id and body are required.'
190
+ end
191
+ end
192
+
193
+ end
194
+
195
+ # ページ閲覧済マークを付与リクエスト用クラス
196
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
197
+ # @note 詳細不明
198
+ class GApiRequestPagesSeen < GApiRequestBase
199
+
200
+ # コンストラクタ
201
+ # @override
202
+ # @param [Hash] param APIリクエストのパラメータ
203
+ def initialize(param = {})
204
+ super('/_api/pages.seen', METHOD_POST, { page_id: param[:page_id] })
205
+ end
206
+
207
+ # リクエストを実行する
208
+ # @override
209
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
210
+ # @param [Hash] rest_client_param RestClientのパラメータ
211
+ # @return [Array] リクエスト実行結果
212
+ def execute(entry_point, rest_client_param: {})
213
+
214
+ if invalid?
215
+ return validation_msg
216
+ end
217
+ params = { method: :post, url: entry_point,
218
+ payload: @param.to_json,
219
+ headers: { content_type: :json, accept: :json }
220
+ }.merge(rest_client_param)
221
+ ret = JSON.parse RestClient::Request.execute params
222
+ if (ret['ok'] == false)
223
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
224
+ end
225
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['seenUser']))
226
+ end
227
+
228
+ protected
229
+
230
+ # バリデーションエラーを取得する
231
+ # @override
232
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
233
+ def _invalid
234
+ if ! (@param[:page_id])
235
+ return CPInvalidRequest.new 'Parameter page_id required.'
236
+ end
237
+ end
238
+
239
+ end
240
+
241
+ # ライクページ指定リクエスト用クラス
242
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
243
+ class GApiRequestLikesAdd < GApiRequestBase
244
+
245
+ # コンストラクタ
246
+ # @override
247
+ # @param [Hash] param APIリクエストのパラメータ
248
+ def initialize(param = {})
249
+ super('/_api/likes.add', METHOD_POST, { page_id: param[:page_id] })
250
+ end
251
+
252
+ # リクエストを実行する
253
+ # @override
254
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
255
+ # @param [Hash] rest_client_param RestClientのパラメータ
256
+ # @return [Array] リクエスト実行結果
257
+ def execute(entry_point, rest_client_param: {})
258
+
259
+ if invalid?
260
+ return validation_msg
261
+ end
262
+ params = { method: :post, url: entry_point,
263
+ payload: @param.to_json,
264
+ headers: { content_type: :json, accept: :json }
265
+ }.merge(rest_client_param)
266
+ ret = JSON.parse RestClient::Request.execute params
267
+ if (ret['ok'] == false)
268
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
269
+ end
270
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
271
+ end
272
+
273
+ protected
274
+
275
+ # バリデーションエラーを取得する
276
+ # @override
277
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
278
+ def _invalid
279
+ if ! (@param[:page_id])
280
+ return CPInvalidRequest.new 'Parameter page_id required.'
281
+ end
282
+ end
283
+
284
+ end
285
+
286
+ # ライクページ指定解除リクエスト用クラス
287
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
288
+ class GApiRequestLikesRemove < GApiRequestBase
289
+
290
+ # コンストラクタ
291
+ # @override
292
+ # @param [Hash] param APIリクエストのパラメータ
293
+ def initialize(param = {})
294
+ super('/_api/likes.remove', METHOD_POST, { page_id: param[:page_id] })
295
+ end
296
+
297
+ # リクエストを実行する
298
+ # @override
299
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
300
+ # @param [Hash] rest_client_param RestClientのパラメータ
301
+ # @return [Array] リクエスト実行結果
302
+ def execute(entry_point, rest_client_param: {})
303
+
304
+ if invalid?
305
+ return validation_msg
306
+ end
307
+ params = { method: :post, url: entry_point,
308
+ payload: @param.to_json,
309
+ headers: { content_type: :json, accept: :json }
310
+ }.merge(rest_client_param)
311
+ ret = JSON.parse RestClient::Request.execute params
312
+ if (ret['ok'] == false)
313
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
314
+ end
315
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
316
+ end
317
+
318
+ protected
319
+
320
+ # バリデーションエラーを取得する
321
+ # @override
322
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
323
+ def _invalid
324
+ if ! (@param[:page_id])
325
+ return CPInvalidRequest.new 'Parameter page_id required.'
326
+ end
327
+ end
328
+
329
+ end
330
+
331
+ # 更新ページ一覧リクエスト用クラス
332
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
333
+ # @note notification for 3rd party tool (like Slack)
334
+ class GApiRequestPagesUpdatePost < GApiRequestBase
335
+
336
+ # コンストラクタ
337
+ # @override
338
+ # @param [Hash] param APIリクエストのパラメータ
339
+ def initialize(param = {})
340
+ super('/_api/pages.updatePost', METHOD_GET, { path: param[:path] })
341
+ end
342
+
343
+ # リクエストを実行する
344
+ # @override
345
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
346
+ # @param [Hash] rest_client_param RestClientのパラメータ
347
+ # @return [Array] リクエスト実行結果
348
+ def execute(entry_point, rest_client_param: {})
349
+
350
+ if invalid?
351
+ return validation_msg
352
+ end
353
+ params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
354
+ ret = JSON.parse RestClient::Request.execute params
355
+ if (ret['ok'] == false)
356
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
357
+ end
358
+ posts = []
359
+ ret['updatePost'].each do |post|
360
+ pages.push(GrowiPage.new(post))
361
+ end
362
+ return GApiReturn.new(ok: ret['ok'], data: posts)
363
+ end
364
+
365
+ protected
366
+
367
+ # バリデーションエラーを取得する
368
+ # @override
369
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
370
+ def _invalid
371
+ if ! (@param[:path])
372
+ return CPInvalidRequest.new 'Parameter path required.'
373
+ end
374
+ end
375
+
376
+ end
377
+
378
+ # ページ削除リクエスト用クラス(API利用不可)
379
+ # @ref https://github.com/growi/growi/blob/master/lib/routes/page.js
380
+ class GApiRequestPagesRemove < GApiRequestBase
381
+
382
+ # コンストラクタ
383
+ # @override
384
+ # @param [Hash] param APIリクエストのパラメータ
385
+ def initialize(param = {})
386
+ raise Exception, 'API of pages.remove is forbidden'
387
+ super('/_api/pages.remove', METHOD_GET,
388
+ { page_id: param[:page_id], revision_id: param[:revision_id] })
389
+ end
390
+
391
+ # リクエストを実行する
392
+ # @override
393
+ # @param [String] entry_point APIのエントリーポイントとなるURL(ex. http://localhost:3000/_api/pages.list)
394
+ # @param [Hash] rest_client_param RestClientのパラメータ
395
+ # @return [Array] リクエスト実行結果
396
+ def execute(entry_point, rest_client_param: {})
397
+
398
+ if invalid?
399
+ return validation_msg
400
+ end
401
+ param = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
402
+ ret = JSON.parse RestClient::Request.execute param
403
+ if (ret['ok'] == false)
404
+ return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
405
+ end
406
+ return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
407
+ end
408
+
409
+ protected
410
+
411
+ # バリデーションエラーを取得する
412
+ # @override
413
+ # @return [nil/CPInvalidRequest] バリデーションエラー結果
414
+ def _invalid
415
+ if ! (@param[:page_id] || @param[:revision_id])
416
+ return CPInvalidRequest.new 'Parameter page_id or revision_id is required.'
417
+ end
418
+ end
419
+
420
+ end
421
+