Sha256: 547ddddf49f5f22c5aba08f5231d0ec0b00d39bcca0ffab58ce1cd714c8fe405

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

require 'alephant/cache'
require 'alephant/lookup'
require 'alephant/broker/errors/invalid_cache_key'

module Alephant
  module Broker
    class AssetResponse < Response

      attr_reader :request

      def initialize(request, config)
        @request = request
        @lookup = Alephant::Lookup.create(config[:lookup_table_name], request.component_id)
        @cache = Cache.new(config[:bucket_id], config[:path])
        super()
      end

      def setup
        begin
          self.content_type = request.content_type
          self.content = @cache.get cache_id
        rescue AWS::S3::Errors::NoSuchKey, InvalidCacheKey
          self.status = 404
        rescue Exception => e
          self.status = 500
        end

      end

      private

      def cache_id
        @lookup.read(request.options).tap { |cache_id| raise InvalidCacheKey if cache_id.nil? }
      end

    end
  end
end


Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alephant-broker-0.0.2 lib/alephant/broker/models/response/asset_response.rb
alephant-broker-0.0.1 lib/alephant/broker/models/response/asset_response.rb