class GApiRequestAttachmentsAdd

添付ファイル追加リクエスト用クラス @ref github.com/growi/growi/blob/master/lib/routes/attachment.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_attachments.rb, line 54
def initialize(param = {})
  super('/_api/attachments.add', METHOD_POST,
        { page_id: param[:page_id], file: param[:file] })
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/growi/client/apireq/api_request_attachments.rb, line 64
def execute(entry_point, rest_client_param: {})
  if invalid?
    return validation_msg
  end
  params = {
    method: :post,
    url:    entry_point,
    payload: {
      access_token: @param[:access_token],
      page_id:      @param[:page_id],
      file:         @param[:file]
    }
  }.merge(rest_client_param)
  ret = JSON.parse RestClient::Request.execute params
  if (ret['ok'] == false)
    return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
  end
  data = {
    page: GrowiPage.new(ret['page']),
    attachment: GrowiAttachment.new(ret['attachment'])
  }
  return GApiReturn.new(ok: ret['ok'], data: data)
end

Protected Instance Methods

_invalid() click to toggle source

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

# File lib/growi/client/apireq/api_request_attachments.rb, line 92
def _invalid
  if ! (@param[:file] && @param[:page_id])
    GCInvalidRequest.new 'Parameters file and page_id are required.'
  end
end