Class: Jet::Client::Files
- Inherits:
-
Object
- Object
- Jet::Client::Files
- Defined in:
- lib/jet/client/files.rb
Overview
Files client
Instance Method Summary collapse
- #file_upload(url, body) ⇒ Object
-
#initialize(client) ⇒ Files
constructor
A new instance of Files.
- #jet_file_id(file_id) ⇒ Object
- #upload_token ⇒ Object
- #uploaded_files(url, file_type, file_name) ⇒ Object
Constructor Details
#initialize(client) ⇒ Files
Returns a new instance of Files.
8 9 10 |
# File 'lib/jet/client/files.rb', line 8 def initialize(client) @client = client end |
Instance Method Details
#file_upload(url, body) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
34 35 36 |
# 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 ⇒ Object
12 13 14 |
# 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) ⇒ Object
27 28 29 30 31 32 |
# 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 |