Class: SitemapGenerator::FogAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/sitemap_generator/adapters/fog_adapter.rb

Overview

Class for uploading sitemaps to a Fog supported endpoint.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FogAdapter

Requires Fog::Storage to be defined.

Parameters:

  • opts (Hash) (defaults to: {})

    Fog configuration options

  • :fog_credentials (Hash)

    a customizable set of options

  • :fog_directory (Hash)

    a customizable set of options



16
17
18
19
# File 'lib/sitemap_generator/adapters/fog_adapter.rb', line 16

def initialize(opts = {})
  @fog_credentials = opts[:fog_credentials]
  @fog_directory = opts[:fog_directory]
end

Instance Method Details

#write(location, raw_data) ⇒ Object

Call with a SitemapLocation and string data



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sitemap_generator/adapters/fog_adapter.rb', line 22

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