class CPApiRequestPagesList

ページ一覧リクエスト用クラス @ref github.com/crowi/crowi/blob/master/lib/routes/page.js

Public Class Methods

new(param = {}) click to toggle source

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

Calls superclass method CPApiRequestBase::new
# File lib/crowi/client/apireq/api_request_pages.rb, line 11
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

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

# File lib/crowi/client/apireq/api_request_pages.rb, line 21
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)
  ret = JSON.parse RestClient::Request.execute params
  if (ret['ok'] == false)
    return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
  end
  pages = []
  ret['pages'].each do |page|
    pages.push(CrowiPage.new(page))
  end
  return CPApiReturn.new(ok: ret['ok'], data: pages)
end

Protected Instance Methods

_invalid() click to toggle source

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

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