Class: SitemapGenerator::AwsSdkAdapter

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

Overview

Class for uploading sitemaps to an S3 bucket using the AWS SDK gem.

Instance Method Summary collapse

Constructor Details

#initialize(bucket, options = {}) ⇒ AwsSdkAdapter

Specify your AWS bucket name, credentials, and/or region. By default the AWS SDK will auto-detect your credentials and region, but you can use the following options to configure - or override - them manually:

Options:

:aws_access_key_id [String] Your AWS access key id
:aws_secret_access_key [String] Your AWS secret access key
:aws_region [String] Your AWS region

Requires Aws::S3::Resource and Aws::Credentials to be defined.


22
23
24
25
26
27
# File 'lib/sitemap_generator/adapters/aws_sdk_adapter.rb', line 22

def initialize(bucket, options = {})
  @bucket = bucket
  @aws_access_key_id = options[:aws_access_key_id]
  @aws_secret_access_key = options[:aws_secret_access_key]
  @aws_region = options[:aws_region]
end

Instance Method Details

#write(location, raw_data) ⇒ Object

Call with a SitemapLocation and string data


30
31
32
33
34
35
36
37
38
# File 'lib/sitemap_generator/adapters/aws_sdk_adapter.rb', line 30

def write(location, raw_data)
  SitemapGenerator::FileAdapter.new.write(location, raw_data)
  s3_object = s3_resource.bucket(@bucket).object(location.path_in_public)
  s3_object.upload_file(location.path,
    acl: 'public-read',
    cache_control: 'private, max-age=0, no-cache',
    content_type: location[:compress] ? 'application/x-gzip' : 'application/xml'
  )
end