Class: SitemapGenerator::S3Adapter

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

Instance Method Summary (collapse)

Constructor Details

- (S3Adapter) initialize(opts = {})

Returns a new instance of S3Adapter



10
11
12
13
14
15
16
17
18
# File 'lib/sitemap_generator/adapters/s3_adapter.rb', line 10

def initialize(opts = {})
  @aws_access_key_id = opts[:aws_access_key_id] || ENV['AWS_ACCESS_KEY_ID']
  @aws_secret_access_key = opts[:aws_secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY']
  @fog_provider = opts[:fog_provider] || ENV['FOG_PROVIDER']
  @fog_directory = opts[:fog_directory] || ENV['FOG_DIRECTORY']
  @fog_region = opts[:fog_region] || ENV['FOG_REGION']
  @fog_path_style = opts[:fog_path_style] || ENV['FOG_PATH_STYLE']
  @fog_storage_options = opts[:fog_storage_options] || {}
end

Instance Method Details

- (Object) write(location, raw_data)

Call with a SitemapLocation and string data



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sitemap_generator/adapters/s3_adapter.rb', line 21

def write(location, raw_data)
  SitemapGenerator::FileAdapter.new.write(location, raw_data)

  credentials = {
    :aws_access_key_id     => @aws_access_key_id,
    :aws_secret_access_key => @aws_secret_access_key,
    :provider              => @fog_provider,
  }
  credentials[:region] = @fog_region if @fog_region
  credentials[:path_style] = @fog_path_style if @fog_path_style

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