Sha256: b59f1ee389396af24ea0bf95e75fae31a6b44194fc2e2115cebfad4511d2b7c6
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module Pinata class FilesResource < Resource def upload(file:, name: nil, mime_type: nil, metadata: nil) mime_type ||= Marcel::MimeType.for(file) payload = {file: Faraday::UploadIO.new(file, mime_type)} payload[:name] = name unless name.nil? payload[:keyvalues] = metadata unless metadata.nil? File.new upload_post_request("files", body: payload, headers: {"Content-Type" => "multipart/form-data"}).body["data"] end def list(**params) response = api_get_request("files", params: params) Collection.from_response(response, key: "files", type: File) end def sign(gateway:, file_cid:, expires:, date: Time.now.to_i, url_method: "GET") payload = { url: "https://#{gateway}/files/#{file_cid}", date: date, expires: expires, method: url_method } api_post_request("files/sign", body: payload).body["data"] end def update(file_id:, **attributes) File.new api_put_request("files/#{file_id}", body: attributes).body["data"] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pinata-1.0.1 | lib/pinata/resources/files.rb |
pinata-1.0.0 | lib/pinata/resources/files.rb |