Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
namara / lib / uploads.rb
Size: Mime:
require_relative 'rpc/uploads/uploads_twirp'

class Namara
  # Create an upload object on namara
  #
  # @param resource_type [String] type of the resource the upload is being associated it,
  #   currently only supported valued is 'dataset'
  # @param resource_id [String] UUID of the resource
  # @param content_type [String] content type of the file being uploaded, usually file extension
  # @param content_length [Integer] size of the file in number of bytes
  # @param filename [String] name of the file to be uploaded
  #
  # @return [OpenStruct] response
  #   * :id [String] id of the upload object created
  #   * :signed_url [String] GCS bucket url of where to upload to
  def create_upload(resource_type, resource_id, content_type, content_length, filename)
    create_request = {
      resource_type: resource_type,
      resource_id: resource_id,
      content_type: content_type,
      content_length: content_length,
      filename: filename
    }

    response = rpc_request(upload_client) do |client|
      client.create_upload(create_request, rpc_headers)
    end

    OpenStruct.new(response.data.to_h)
  end

  # Retrieve an `upload` object from
  #
  # @param id [String] id of the upload object
  # @param resource_type [String] type of resource, currently only 'dataset' is supported
  # @param resource_id [String] UUID of the resource upload is associated to
  #
  # @return [OpenStruct] response
  #   * :signed_url [String] GCS bucket url of where to download from
  def get_upload(id, resource_type, resource_id)
    get_request = {
      id: id,
      resource_type: resource_type,
      resource_id: resource_id
    }

    response = rpc_request(upload_client) do |client|
      client.get_upload(get_request, rpc_headers)
    end

    OpenStruct.new(response.data.to_h)
  end

  private

  def upload_client
    @upload_client ||= Uploads::UploadsServiceClient.new(api_url)
  end
end