Class: GApiRequestPagesSeen

Inherits:
GApiRequestBase show all
Defined in:
lib/growi/client/apireq/api_request_pages.rb

Overview

Note:

詳細不明

ページ閲覧済マークを付与リクエスト用クラス

Constant Summary

Constants inherited from GApiRequestBase

GApiRequestBase::METHOD_GET, GApiRequestBase::METHOD_POST

Instance Attribute Summary

Attributes inherited from GApiRequestBase

#entry_point, #method, #param

Instance Method Summary collapse

Methods inherited from GApiRequestBase

#invalid?, #valid?, #validation_msg

Constructor Details

#initialize(param = {}) ⇒ GApiRequestPagesSeen

コンストラクタ

Parameters:

  • param (Hash) (defaults to: {})

    APIリクエストのパラメータ



255
256
257
# File 'lib/growi/client/apireq/api_request_pages.rb', line 255

def initialize(param = {})
  super('/_api/pages.seen', METHOD_POST, { page_id: param[:page_id] })
end

Instance Method Details

#execute(entry_point, rest_client_param: {}) ⇒ Array

リクエストを実行する

Parameters:

  • entry_point (String)

    APIのエントリーポイントとなるURL(ex. localhost:3000/_api/pages.list

  • rest_client_param (Hash) (defaults to: {})

    RestClientのパラメータ

Returns:

  • (Array)

    リクエスト実行結果



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/growi/client/apireq/api_request_pages.rb', line 264

def execute(entry_point, rest_client_param: {})

  if invalid?
    return validation_msg
  end
  params = { method: :post, url: entry_point,
             payload: @param.to_json,
             headers: { content_type: :json, accept: :json }
           }.merge(rest_client_param)
  GCLogger.logger.debug('Request: ' + params.to_s)

  begin
    raw_ret = RestClient::Request.execute params
    GCLogger.logger.debug('Return: ' + raw_ret.to_s)
    ret = JSON.parse raw_ret
  rescue Exception => e
    GCLogger.logger.error(e)
    return GCInvalidRequest.new "Unknown error occured: #{e}"
  end

  if (!ret['ok'].nil? && ret['ok'] == false)
    return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
  end

  begin
    users = ret['seenUser'].map do |user|
      user.is_a?(String) ? user : GrowiUser.new(user)
    end
    return GApiReturn.new(ok: ret['ok'], data: users)
  rescue Exception => e
    GCLogger.logger.error(e)
    return GCInvalidRequest.new "Fail to parse: #{e}"
  end
end