class SitemapGenerator::FogAdapter

Class for uploading sitemaps to a Fog supported endpoint.

Public Class Methods

new(opts = {}) click to toggle source

Requires Fog::Storage to be defined.

@param [Hash] opts Fog configuration options @option :fog_credentials [Hash] Credentials for connecting to the remote server @option :fog_directory [String] Your AWS S3 bucket or similar directory name

# File lib/sitemap_generator/adapters/fog_adapter.rb, line 14
def initialize(opts = {})
  @fog_credentials = opts[:fog_credentials]
  @fog_directory = opts[:fog_directory]
end

Public Instance Methods

write(location, raw_data) click to toggle source

Call with a SitemapLocation and string data

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

  storage   = Fog::Storage.new(@fog_credentials)
  directory = storage.directories.new(:key => @fog_directory)
  directory.files.create(
    :key    => location.path_in_public,
    :body   => File.open(location.path),
    :public => true
  )
end