Class: GApiRequestPagesList

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

Overview

ページ一覧リクエスト用クラス

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 = {}) ⇒ GApiRequestPagesList

コンストラクタ

Parameters:

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

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



12
13
14
15
# File 'lib/growi/client/apireq/api_request_pages.rb', line 12

def initialize(param = {})
  super('/_api/pages.list', METHOD_GET,
        { path: param[:path_exp], user: param[:user] })
end

Instance Method Details

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

リクエストを実行する

TODO

pagination に対応する

Parameters:

  • entry_point (String)

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

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

    RestClientのパラメータ

Returns:

  • (Array)

    リクエスト実行結果



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/growi/client/apireq/api_request_pages.rb', line 23

def execute(entry_point, rest_client_param: {})

  if invalid?
    return validation_msg
  end

  params = { method: :get, url: entry_point, headers: { params: @param } }.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
    pages = []
    ret['pages'].each do |page|
      pages.push(GrowiPage.new(page))
    end
    return GApiReturn.new(ok: ret['ok'], data: pages)
  rescue Exception => e
    GCLogger.logger.error(e)
    return GCInvalidRequest.new "Fail to parse: #{e}"
  end
end