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.


14
15
16
17
# File 'lib/sitemap_generator/adapters/fog_adapter.rb', line 14

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


20
21
22
23
24
25
26
27
28
29
30
# 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