class SitemapGenerator::AwsSdkAdapter
Class for uploading sitemaps to an S3 bucket using the AWS SDK gem.
Public Class Methods
new(bucket, options = {})
click to toggle source
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.
@param [String] bucket Name of the S3 bucket @param [Hash] options AWS credential overrides, see above
# 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] @aws_endpoint = options[:aws_endpoint] end
Public Instance Methods
write(location, raw_data)
click to toggle source
Call with a SitemapLocation
and string data
# File lib/sitemap_generator/adapters/aws_sdk_adapter.rb, line 31 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
Private Instance Methods
s3_resource()
click to toggle source
# File lib/sitemap_generator/adapters/aws_sdk_adapter.rb, line 43 def s3_resource @s3_resource ||= Aws::S3::Resource.new(s3_resource_options) end
s3_resource_options()
click to toggle source
# File lib/sitemap_generator/adapters/aws_sdk_adapter.rb, line 47 def s3_resource_options options = {} options[:region] = @aws_region if !@aws_region.nil? options[:endpoint] = @aws_endpoint if !@aws_endpoint.nil? if !@aws_access_key_id.nil? && !@aws_secret_access_key.nil? options[:credentials] = Aws::Credentials.new( @aws_access_key_id, @aws_secret_access_key ) end options end