module TestStorage
 require 'rest_client'
 require 'timeout'
 require 'openssl'
 require 'google/api_client'
 
 def get_google_client
   client = Google::APIClient.new(
     :application_name => "Test-storage",
     :application_version => "1.0.0"
   )
   client.authorization = :google_app_default
   client.authorization.fetch_access_token!
   
   client
 end
 
 def get_file(file_location)
   client = get_google_client
   storage = client.discovered_api('storage', 'v1')
   result = client.execute(
     :api_method => storage.objects.get,
     :parameters => {
       :bucket => 'test-bucket',
       :object => file_location,
       :alt => 'media'
     }
   )
   if result.response.env.status == 200
     return true, result.response.env.body
   else
     return false, "ERROR WITH FINDING FILE ON GCS"
   end
 rescue => e
   return false, e
 end
 
 def store_file(put_location, local_file)
   media = Google::APIClient::UploadIO.new(local_file, 'text/plain')
   client = get_google_client
   storage = client.discovered_api('storage', 'v1')
   file_name = File.basename local_file
   result = client.execute(
     :api_method => storage.objects.get,
       :parameters => {
       :bucket => 'test-bucket',
       :object => file_location,
       :alt => 'media'
     }
   )
   if result.response.env.status == 200
     return true, result.response.env.body
   else
     return false, "ERROR WITH STORING FILE ON GCS"
   end
 rescue => e
   return false, e
 end