class SitemapGenerator::GoogleStorageAdapter

Class for uploading sitemaps to a Google Storage using `google-cloud-storage` gem.

Public Class Methods

new(opts = {}) click to toggle source

Requires Google::Cloud::Storage to be defined.

@param [Hash] opts Google::Cloud::Storage configuration options. @option :bucket [String] Required. Name of Google Storage Bucket where the file is to be uploaded.

All options other than the `:bucket` option are passed to the `Google::Cloud::Storage.new` initializer. See googleapis.dev/ruby/google-cloud-storage/latest/file.AUTHENTICATION.html for all the supported environment variables and github.com/googleapis/google-cloud-ruby/blob/master/google-cloud-storage/lib/google/cloud/storage.rb for supported options.

Suggested Options: @option :credentials [String] Path to Google service account JSON file, or JSON contents. @option :project_id [String] Google Accounts project id where the storage bucket resides.

# File lib/sitemap_generator/adapters/google_storage_adapter.rb, line 22
def initialize(opts = {})
  opts = opts.clone
  @bucket = opts.delete(:bucket)
  @storage_options = opts
end

Public Instance Methods

write(location, raw_data) click to toggle source

Call with a SitemapLocation and string data

# File lib/sitemap_generator/adapters/google_storage_adapter.rb, line 29
def write(location, raw_data)
  SitemapGenerator::FileAdapter.new.write(location, raw_data)

  storage = Google::Cloud::Storage.new(@storage_options)
  bucket = storage.bucket(@bucket)
  bucket.create_file(location.path, location.path_in_public, acl: 'public')
end