Permalink
Browse files

Merge pull request #78 from recurser/master

Simple S3 adaptor
  • Loading branch information...
2 parents b3e488e + 15ab97f commit 38302ddcc1f4ae024cf75bb58469837eadfc428a @kjvarga committed Jul 12, 2012
Showing with 26 additions and 0 deletions.
  1. +1 −0 lib/sitemap_generator.rb
  2. +25 −0 lib/sitemap_generator/adapters/s3_adapter.rb
View
@@ -10,6 +10,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')
autoload(:BigDecimal, 'sitemap_generator/core_ext/big_decimal')
autoload(:Numeric, 'sitemap_generator/core_ext/numeric')
@@ -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

0 comments on commit 38302dd

Please sign in to comment.