class GApiRequestBase
APIリクエストの基本クラス
Constants
- METHOD_GET
- METHOD_POST
Attributes
entry_point[R]
method[R]
param[R]
Public Class Methods
new(entry_point, method, param = {})
click to toggle source
コンストラクタ @param [String] entry_point
APIリクエストのエントリポイントとなるURLパス(ex. '/page.list') @param [Enumerator] method APIリクエストのタイプ @param [Hash] param APIリクエストのパラメータ
# File lib/growi/client/apireq/api_request_base.rb, line 46 def initialize(entry_point, method, param = {}) @entry_point = entry_point @method = method @param = param.reject { |k, v| !v } end
Public Instance Methods
execute(entry_point, rest_client_param: {})
click to toggle source
リクエストを実行する @param [String] entry_point
APIのエントリーポイントとなるURL(ex. localhost:3000/_api/pages.list) @param [Hash] rest_client_param RestClientのパラメータ @return [String] リクエスト実行結果(GApiReturnオブジェクト)
# File lib/growi/client/apireq/api_request_base.rb, line 80 def execute(entry_point, rest_client_param: {}) if invalid? return validation_msg end case @method when 'GET' params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param) when 'POST' params = { method: :post, url: entry_point, content_type: :json, accept: :json, headers: { params: @param.to_json } }.merge() end ret_json = RestClient::Request.execute params ret = JSON.parse(ret_json) return GApiReturn.new(ok: ret['ok'], data: ret.reject { |k,v| k == 'ok' }) end
invalid?()
click to toggle source
パラメータのバリデーションチェックを行う @return [true/false] バリデーションチェック結果
# File lib/growi/client/apireq/api_request_base.rb, line 66 def invalid? return (_invalid) end
param=(param = {})
click to toggle source
パラメータを代入 @param [Hash] param APIリクエストのパラメータ
# File lib/growi/client/apireq/api_request_base.rb, line 54 def param=(param = {}) @param = param end
valid?()
click to toggle source
パラメータのバリデーションチェックを行う @return [true/false] バリデーションチェック結果
# File lib/growi/client/apireq/api_request_base.rb, line 60 def valid? return (!_invalid) end
validation_msg()
click to toggle source
バリデーションエラーの説明 @return [String] バリデーションエラーの説明
# File lib/growi/client/apireq/api_request_base.rb, line 72 def validation_msg return _invalid&.to_s end
Protected Instance Methods
_invalid()
click to toggle source
バリデーションエラーを取得する @return [nil/GCInvalidRequest] バリデーションエラー結果
# File lib/growi/client/apireq/api_request_base.rb, line 102 def _invalid return GCInvalidRequest "Invalid API request."; end