Sha256: 8fa9fe9333b3143f53d0309bf2f053eddaa361e7b3a6f3e7af3f3b38b95013e2

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

require 'json'

module Sdbport
  class Domain
    class Export

      def initialize(args)
        @name       = args[:name]
        @logger     = args[:logger]
        @access_key = args[:access_key]
        @secret_key = args[:secret_key]
        @region     = args[:region]
      end

      def export(output)
        @logger.info "Export #{@name} in #{@region} to #{output}"
        file = File.open(output, 'w')
        export_domain.each do |item| 
          file.write convert_to_string item
          file.write "\n"
        end
        return true if file.close.nil?
      end

      private

      def sdb
        @sdb ||= AWS::SimpleDB.new :access_key => @access_key,
                                   :secret_key => @secret_key,
                                   :region     => @region
      end

      def export_domain
        sdb.select "select * from `#{@name}`"
      end

      def convert_to_string(item)
        item.to_json
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sdbport-0.1.0 lib/sdbport/domain/export.rb