class RenuoUpload::Uploader

Public Class Methods

new(config) click to toggle source
# File lib/renuo_upload/uploader.rb, line 7
def initialize(config)
  @config = config
  @policy = retrieve_policy
end

Public Instance Methods

upload(file) click to toggle source
# File lib/renuo_upload/uploader.rb, line 12
def upload(file)
  RestClient.post upload_url, upload_hash(file)
  uploaded_file_url file
end

Private Instance Methods

retrieve_policy() click to toggle source
# File lib/renuo_upload/uploader.rb, line 19
def retrieve_policy
  response = RestClient.post @config.signing_url, api_key: @config.api_key
  JSON.parse response.body
end
upload_data() click to toggle source
# File lib/renuo_upload/uploader.rb, line 28
def upload_data
  @policy['data']
end
upload_hash(file) click to toggle source
# File lib/renuo_upload/uploader.rb, line 32
def upload_hash(file)
  Hash[upload_data.map { |key, value| [key.tr('_', '-'), value] }].merge file: file
end
upload_url() click to toggle source
# File lib/renuo_upload/uploader.rb, line 24
def upload_url
  @policy['url']
end
uploaded_file_url(file) click to toggle source
# File lib/renuo_upload/uploader.rb, line 36
def uploaded_file_url(file)
  @policy['file_url_path'].concat File.basename(file)
end