Sha256: 535e4ab78ec3d018d3ccb44bd833b9742a30a59c3917180932ee9572a1beb321

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'google/cloud/storage'
require 'fileutils'
require 'yaml'
require 'json'
require 'cart_logger'
require_relative 'storage_type'

module CartBinaryUploader
  class GoogleCloudStorage < Storage
    attr_accessor :credentials_file_path
    attr_accessor :project_id

    def initialize(project_id,
                   credentials_file,
                   bucket_name,
                   framework_name,
                   framework_version)
      @credentials_file_path = credentials_file
      @project_id = project_id
      super(bucket_name, framework_name, framework_version)
    end

    def create_storage
      @storage = Google::Cloud::Storage.new(project_id: @project_id,
                                            credentials: @credentials_file_path)
    end

    def create_bucket
      @bucket = @storage.bucket @bucket_name
    end

    def upload_file(file_path)
      @bucket_object = @bucket.upload_file(file_path, file_path)
      @bucket_object.signed_url(method: 'GET', expires: 3.154e+8)
    end

    def file_on_storage_cloud(file)
      bucket_file = bucket.file file
      !bucket_file.nil?
    end

    def download_config_json_file(from_file)
      json_file = @bucket.file from_file
      json_file.download from_file
      json_file
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cartup-1.0.1 lib/storage/google_cloud_storage.rb