class Q3

Constants

CREATE_QUEUE
DEFAULTS
SET_QUEUE_ATTRIBUTES

Public Class Methods

action(action, path='/', &block) click to toggle source
# File lib/q3.rb, line 35
def self.action(action, path='/', &block)
        @paths ||= Hash.new {|h, k| h[k] = [] }
        @paths[path] << {action: action, block: block}
end
dispatch!() click to toggle source
# File lib/q3.rb, line 23
def self.dispatch!
        @paths.each do |path, opts|
                [:get, :post].each do |x|
                        send(x, path) do
                                if opt = opts.find {|opt| opt[:action] == params['Action'] }
                                        instance_eval(&opt[:block])
                                end
                        end
                end
        end
end

Public Instance Methods

attributes() click to toggle source
# File lib/q3.rb, line 212
def attributes
        @attributes ||= (1..10).to_a.inject({}) do |attributes, i|
                if (name = params["Attribute.#{i.to_s}.Name"]) && (value = params["Attribute.#{i.to_s}.Value"])
                        attributes[name] = value
                end
                attributes
        end
end
now() click to toggle source
# File lib/q3.rb, line 251
def now
        (Time.now.to_f * 1000.0).to_i
end
queue() click to toggle source
# File lib/q3.rb, line 204
def queue
        @queue ||= redis.hgetall("Queues:#{params[:QueueName]}")
end
queue_url(queue_name) click to toggle source
# File lib/q3.rb, line 208
def queue_url(queue_name)
        "http://#{request.host}/*/#{queue_name}"
end
redis() click to toggle source
# File lib/q3.rb, line 196
def redis
        @redis ||= Redis::Namespace.new(:Q3, redis: Redis.new(url: ENV['REDISTOGO_URL'] || 'redis://localhost:6379/15'))
end
request_id() click to toggle source
# File lib/q3.rb, line 200
def request_id
        @request_id ||= SecureRandom.uuid
end
return_error_xml(type, code, message) click to toggle source
# File lib/q3.rb, line 233
def return_error_xml(type, code, message)
        builder do |xml|
                xml.instruct!
                xml.ErrorResponse do
                        xml.Error do
                                xml.Type type
                                xml.Code code
                                xml.Message message
                        end
                        xml.ResponseMetadata { xml.RequestId request_id }
                end
        end
end
return_xml(&block) click to toggle source
# File lib/q3.rb, line 221
def return_xml(&block)
        builder do |xml|
                xml.instruct!
                xml.tag!("#{params['Action']}Response") do
                        xml.tag!("#{params['Action']}Result") do
                                block.call(xml)
                        end
                        xml.ResponseMetadata { xml.RequestId request_id }
                end
        end
end
validate_queue_existence() click to toggle source
# File lib/q3.rb, line 247
def validate_queue_existence
        halt 400, return_error_xml('Sender', 'NonExistentQueue', 'The specified queue does not exist for this wsdl version.') if queue.empty?
end