Class: Pixaven::Request::Upload

Inherits:
Base
  • Object
show all
Defined in:
lib/pixaven/request.rb

Overview

Responsible for handling Upload requests

Constant Summary

Constants inherited from Base

Base::API_URL

Instance Attribute Summary

Attributes inherited from Base

#data, #proxy, #type

Instance Method Summary collapse

Constructor Details

#initialize(key, upload_path, proxy = nil) ⇒ Upload

Returns a new instance of Upload.



108
109
110
111
112
# File 'lib/pixaven/request.rb', line 108

def initialize(key, upload_path, proxy = nil)
    @type = :upload
    @upload_path = upload_path
    super(key, proxy)
end

Instance Method Details

#perform(binary: false, save_path: nil) ⇒ Object



114
115
116
117
118
119
# File 'lib/pixaven/request.rb', line 114

def perform(binary: false, save_path: nil)
    unless File.exist?(@upload_path)
        return "Input file #{@upload_path} does not exist", nil, nil
    end
    super
end

#request_dataObject

Returns upload request data. Multipart containing uploaded file and operations performed on it



126
127
128
129
130
131
# File 'lib/pixaven/request.rb', line 126

def request_data
    {
        file: File.new(@upload_path, "rb"),
        data: @data.to_json
    }
end