Class: CPApiRequestAttachmentsRemove

Inherits:
CPApiRequestBase show all
Defined in:
lib/crowi/client/apireq/api_request_attachments.rb

Overview

添付ファイル削除リクエスト用クラス

Constant Summary

Constants inherited from CPApiRequestBase

CPApiRequestBase::METHOD_GET, CPApiRequestBase::METHOD_POST

Instance Attribute Summary

Attributes inherited from CPApiRequestBase

#entry_point, #method, #param

Instance Method Summary collapse

Methods inherited from CPApiRequestBase

#invalid?, #valid?, #validation_msg

Constructor Details

#initialize(param = {}) ⇒ CPApiRequestAttachmentsRemove

コンストラクタ

Parameters:

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

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



104
105
106
107
# File 'lib/crowi/client/apireq/api_request_attachments.rb', line 104

def initialize(param = {})
  super('/_api/attachments.remove', METHOD_POST,
        { attachment_id: param[:attachment_id] })
end

Instance Method Details

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

リクエストを実行する

Parameters:

  • entry_point (String)

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

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

    RestClientのパラメータ

Returns:

  • (Array)

    リクエスト実行結果



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/crowi/client/apireq/api_request_attachments.rb', line 114

def execute(entry_point, rest_client_param: {})
  if invalid?
    return validation_msg
  end
  params = { method: :post, url: entry_point,
             payload: @param.to_json,
             headers: { content_type: :json, accept: :json }
           }.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
  return CPApiReturn.new(ok: ret['ok'], data: nil)
end