Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Simple S3 adaptor #78

Merged
merged 2 commits into from

2 participants

@recurser

Adds a simple S3 adaptor that uploads directly through fog (using env. variables for the S3 credentials) as I didn't want to add the dependency on Carrierwave to my app.

@kjvarga kjvarga merged commit 38302dd into from
@kjvarga
Owner

Thanks! In v3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  lib/sitemap_generator.rb
@@ -11,6 +11,7 @@
module SitemapGenerator
autoload(:Interpreter, 'sitemap_generator/interpreter')
autoload(:FileAdapter, 'sitemap_generator/adapters/file_adapter')
+ autoload(:S3Adapter, 'sitemap_generator/adapters/s3_adapter')
autoload(:WaveAdapter, 'sitemap_generator/adapters/wave_adapter')
SitemapError = Class.new(StandardError)
View
25 lib/sitemap_generator/adapters/s3_adapter.rb
@@ -0,0 +1,25 @@
+require 'fog'
+
+module SitemapGenerator
+ class S3Adapter
+
+ # Call with a SitemapLocation and string data
+ def write(location, raw_data)
+ SitemapGenerator::FileAdapter.new.write(location, raw_data)
+
+ credentials = {
+ :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
+ :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
+ :provider => ENV['FOG_PROVIDER'],
+ }
+
+ storage = Fog::Storage.new(credentials)
+ directory = storage.directories.get(ENV['FOG_DIRECTORY'])
+ directory.files.create(
+ :key => location.path_in_public,
+ :body => File.open(location.path),
+ :public => true,
+ )
+ end
+ end
+end
Something went wrong with that request. Please try again.