class CartBinaryUploader::GoogleCloudStorage
Constants
- FRAMEWORK_EXTENSION_NAME
- JSON_EXTENSION_NAME
- JSON_EXTENSION_ZIP
Attributes
bucket[RW]
bucketName[RW]
credentialsFilePath[RW]
frameworkName[RW]
frameworkVersion[RW]
projectId[RW]
storage[RW]
Public Class Methods
new( projectId, credentialsFile, bucketName, frameworkName, frameworkVersion )
click to toggle source
# File lib/google_cloud_storage.rb, line 22 def initialize( projectId, credentialsFile, bucketName, frameworkName, frameworkVersion ) @projectId = projectId @credentialsFilePath = credentialsFile @bucketName = bucketName @frameworkName = frameworkName @frameworkVersion = frameworkVersion createStorage createBucket end
Public Instance Methods
createBucket()
click to toggle source
# File lib/google_cloud_storage.rb, line 40 def createBucket puts "Creating bucket name: " + @bucketName @bucket = @storage.bucket @bucketName end
createStorage()
click to toggle source
# File lib/google_cloud_storage.rb, line 32 def createStorage puts "Creating google storage with id: " + @projectId + "credenciasPath: " + @credentialsFilePath @storage = Google::Cloud::Storage.new( project_id: @projectId, credentials: @credentialsFilePath ) end
downloadZConfigJsonFile(fromFile)
click to toggle source
# File lib/google_cloud_storage.rb, line 83 def downloadZConfigJsonFile fromFile #jsonPath = 'CarrefourAPI.json' jsonFile = @bucket.file fromFile jsonFile.download fromFile jsonFile end
hasFileOnGoogleCloud(file)
click to toggle source
# File lib/google_cloud_storage.rb, line 77 def hasFileOnGoogleCloud file puts "Verifying if the version file "+ file +" already exists" bucketFile = bucket.file file !bucketFile.nil? end
loadJSONObject(jsonPath)
click to toggle source
# File lib/google_cloud_storage.rb, line 90 def loadJSONObject jsonPath puts "Loading JSON file" json = File.read(jsonPath) object = JSON.parse(json) puts object puts "JSON Loaded" object end
saveJSONObject(jsonPath, jsonObject)
click to toggle source
# File lib/google_cloud_storage.rb, line 99 def saveJSONObject(jsonPath, jsonObject) binaryJson = JSON.pretty_generate(jsonObject) puts "Saving JSON Object in: " + jsonPath + "JSON: " + binaryJson File.write(jsonPath, binaryJson) puts "JSON Saved" end
uploadFrameWork()
click to toggle source
# File lib/google_cloud_storage.rb, line 45 def uploadFrameWork puts "Prepering to upload file to google cloud" frameworkNameSource = @frameworkName + FRAMEWORK_EXTENSION_NAME + JSON_EXTENSION_ZIP frameworkNameDestination = @frameworkName + FRAMEWORK_EXTENSION_NAME + "." + @frameworkVersion + JSON_EXTENSION_ZIP jsonPath = @frameworkName + JSON_EXTENSION_NAME puts "Framework Source: " + frameworkNameSource puts "Framework Destination: " + frameworkNameDestination puts "JSON Path: " + jsonPath unless !hasFileOnGoogleCloud frameworkNameDestination throw :the_version_file_already_exists, "The current version: " + @frameworkVersion + " already exists on google cloud" else puts "File version "+ @frameworkVersion +" not exists yet, starting generate file on google cloud" jsonFile = downloadZConfigJsonFile(jsonPath) if jsonFile.nil? throw :could_not_download_json_file, "JSON With name: " + jsonPath end frameworkFile = bucket.create_file(frameworkNameSource, frameworkNameDestination) sharedUrl = frameworkFile.signed_url(method: 'GET', expires: 3.154e+8) jsonObject = loadJSONObject jsonPath jsonObject[@frameworkVersion] = sharedUrl saveJSONObject(jsonPath, jsonObject) uploadJson jsonPath end end
uploadJson(jsonPath)
click to toggle source
# File lib/google_cloud_storage.rb, line 107 def uploadJson jsonPath puts "Starting upload file to google cloud" @bucket.create_file(jsonPath, jsonPath) puts "Uploaded complete" end