class Jet::Client::Files

Files client

Public Class Methods

new(client) click to toggle source
# File lib/jet/client/files.rb, line 8
def initialize(client)
  @client = client
end

Public Instance Methods

file_upload(url, body) click to toggle source
# File lib/jet/client/files.rb, line 16
def file_upload(url, body)
  headers = { 'x-ms-blob-type' => 'blockblob' }
  io = StringIO.new
  gz = Zlib::GzipWriter.new(io)
  gz.write(body)
  gz.close
  gzipped_body = io.string
  response = RestClient.put(url, gzipped_body, headers)
  { status: :success, http_status: :created } if response.code == 201
end
jet_file_id(file_id) click to toggle source
# File lib/jet/client/files.rb, line 34
def jet_file_id(file_id)
  @client.rest_get_with_token("/files/#{file_id}")
end
upload_token() click to toggle source
# File lib/jet/client/files.rb, line 12
def upload_token
  @client.rest_get_with_token('/files/uploadToken')
end
uploaded_files(url, file_type, file_name) click to toggle source
# File lib/jet/client/files.rb, line 27
def uploaded_files(url, file_type, file_name)
  headers = @client.token
  body = { url: url, file_type: file_type, file_name: file_name }
  response = RestClient.post("#{Jet::Client::API_URL}/files/uploaded", @client.encode_json(body), headers)
  @client.decode_json(response.body) if response.code == 200
end