class GApiRequestPagesList

ページ一覧リクエスト用クラス @ref github.com/weseek/growi/blob/master/src/server/routes/page.js

Public Class Methods

new(param = {}) click to toggle source

コンストラクタ @override @param [Hash] param APIリクエストのパラメータ

Calls superclass method GApiRequestBase::new
# 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

Public Instance Methods

execute(entry_point, rest_client_param: {}) click to toggle source

リクエストを実行する

TODO

pagination に対応する

@override @param [String] entry_point APIのエントリーポイントとなるURL(ex. localhost:3000/_api/pages.list) @param [Hash] rest_client_param RestClientのパラメータ @return [Array] リクエスト実行結果

# 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

Protected Instance Methods

_invalid() click to toggle source

バリデーションエラーを取得する @override @return [nil/GCInvalidRequest] バリデーションエラー結果

# File lib/growi/client/apireq/api_request_pages.rb, line 62
def _invalid
  if ! (@param[:path] || @param[:user])
    return GCInvalidRequest.new 'Parameter path or user is required.'
  end
  if (@param[:path] && @param[:user])
    return GCInvalidRequest.new 'Parameter path and user can not be specified both.'
  end
end