Class: CPApiRequestBase
- Inherits:
-
Object
- Object
- CPApiRequestBase
- Defined in:
- lib/crowi/client/apireq/api_request_base.rb
Overview
APIリクエストの基本クラス
Direct Known Subclasses
CPApiRequestAttachmentsAdd, CPApiRequestAttachmentsList, CPApiRequestAttachmentsRemove, CPApiRequestLikesAdd, CPApiRequestLikesRemove, CPApiRequestPagesCreate, CPApiRequestPagesGet, CPApiRequestPagesList, CPApiRequestPagesRemove, CPApiRequestPagesSeen, CPApiRequestPagesUpdate, CPApiRequestPagesUpdatePost
Constant Summary collapse
- METHOD_GET =
"GET"
- METHOD_POST =
"POST"
Instance Attribute Summary collapse
-
#entry_point ⇒ Object
readonly
Returns the value of attribute entry_point.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#param ⇒ Object
Returns the value of attribute param.
Instance Method Summary collapse
-
#execute(entry_point, rest_client_param: {}) ⇒ String
リクエストを実行する.
-
#initialize(entry_point, method, param = {}) ⇒ CPApiRequestBase
constructor
コンストラクタ.
-
#invalid? ⇒ true/false
パラメータのバリデーションチェックを行う.
-
#valid? ⇒ true/false
パラメータのバリデーションチェックを行う.
-
#validation_msg ⇒ String
バリデーションエラーの説明.
Constructor Details
#initialize(entry_point, method, param = {}) ⇒ CPApiRequestBase
コンストラクタ
45 46 47 48 49 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 45 def initialize(entry_point, method, param = {}) @entry_point = entry_point @method = method @param = param.reject { |k, v| !v } end |
Instance Attribute Details
#entry_point ⇒ Object (readonly)
Returns the value of attribute entry_point.
39 40 41 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 39 def entry_point @entry_point end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
39 40 41 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 39 def method @method end |
#param ⇒ Object
Returns the value of attribute param.
39 40 41 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 39 def param @param end |
Instance Method Details
#execute(entry_point, rest_client_param: {}) ⇒ String
リクエストを実行する
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 79 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 CPApiReturn.new(ok: ret['ok'], data: ret.reject { |k,v| k == 'ok' }) end |
#invalid? ⇒ true/false
パラメータのバリデーションチェックを行う
65 66 67 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 65 def invalid? return (_invalid) end |
#valid? ⇒ true/false
パラメータのバリデーションチェックを行う
59 60 61 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 59 def valid? return (!_invalid) end |
#validation_msg ⇒ String
バリデーションエラーの説明
71 72 73 |
# File 'lib/crowi/client/apireq/api_request_base.rb', line 71 def validation_msg return _invalid&.to_s end |