2013-07-19 21:38:31 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace'))
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Rackspace
|
|
|
|
class Queues < Fog::Service
|
|
|
|
include Fog::Rackspace::Errors
|
|
|
|
|
|
|
|
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
|
|
|
|
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
|
|
|
|
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
|
|
|
|
class MethodNotAllowed < Fog::Rackspace::Errors::BadRequest; end
|
|
|
|
|
2013-10-10 11:25:35 -04:00
|
|
|
requires :rackspace_api_key, :rackspace_username
|
2013-07-19 21:38:31 -04:00
|
|
|
recognizes :rackspace_auth_url
|
|
|
|
recognizes :rackspace_auth_token
|
|
|
|
recognizes :rackspace_region
|
|
|
|
recognizes :rackspace_queues_url
|
2013-10-10 11:25:35 -04:00
|
|
|
recognizes :rackspace_queues_client_id
|
2013-07-19 21:38:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
model_path 'fog/rackspace/models/queues'
|
|
|
|
model :queue
|
|
|
|
collection :queues
|
|
|
|
model :message
|
|
|
|
collection :messages
|
|
|
|
model :claim
|
|
|
|
collection :claims
|
|
|
|
|
|
|
|
request_path 'fog/rackspace/requests/queues'
|
|
|
|
request :list_queues
|
|
|
|
request :get_queue
|
|
|
|
request :create_queue
|
|
|
|
request :delete_queue
|
|
|
|
request :get_queue_stats
|
|
|
|
|
|
|
|
request :list_messages
|
|
|
|
request :get_message
|
|
|
|
request :create_message
|
|
|
|
request :delete_message
|
|
|
|
request :create_claim
|
|
|
|
request :get_claim
|
|
|
|
request :update_claim
|
|
|
|
request :delete_claim
|
|
|
|
|
|
|
|
class Mock < Fog::Rackspace::Service
|
|
|
|
def request(params)
|
|
|
|
Fog::Mock.not_implemented
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real < Fog::Rackspace::Service
|
|
|
|
|
|
|
|
def service_name
|
|
|
|
:cloudQueues
|
|
|
|
end
|
|
|
|
|
|
|
|
def region
|
|
|
|
@rackspace_region
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options = {})
|
|
|
|
@rackspace_api_key = options[:rackspace_api_key]
|
|
|
|
@rackspace_username = options[:rackspace_username]
|
2013-10-10 16:19:20 -04:00
|
|
|
@rackspace_queues_client_id = options[:rackspace_queues_client_id] || Fog::UUID.uuid
|
2013-07-19 21:38:31 -04:00
|
|
|
@rackspace_auth_url = options[:rackspace_auth_url]
|
|
|
|
@rackspace_must_reauthenticate = false
|
|
|
|
@connection_options = options[:connection_options] || {}
|
2013-10-07 17:54:23 -04:00
|
|
|
@rackspace_region = options[:rackspace_region] || :ord
|
2013-07-19 21:38:31 -04:00
|
|
|
|
|
|
|
unless v2_authentication?
|
|
|
|
raise Fog::Errors::NotImplemented.new("V2 authentication required for Queues")
|
|
|
|
end
|
|
|
|
|
|
|
|
authenticate
|
|
|
|
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params, parse_json = true, &block)
|
|
|
|
super(params, parse_json, &block)
|
|
|
|
rescue Excon::Errors::NotFound => error
|
2013-09-01 14:28:42 -04:00
|
|
|
raise NotFound.slurp(error, self)
|
2013-07-19 21:38:31 -04:00
|
|
|
rescue Excon::Errors::BadRequest => error
|
2013-09-01 14:28:42 -04:00
|
|
|
raise BadRequest.slurp(error, self)
|
2013-07-19 21:38:31 -04:00
|
|
|
rescue Excon::Errors::InternalServerError => error
|
2013-09-01 14:28:42 -04:00
|
|
|
raise InternalServerError.slurp(error, self)
|
2013-07-19 21:38:31 -04:00
|
|
|
rescue Excon::Errors::MethodNotAllowed => error
|
2013-09-01 14:28:42 -04:00
|
|
|
raise MethodNotAllowed.slurp(error, self)
|
2013-07-19 21:38:31 -04:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2013-09-01 14:28:42 -04:00
|
|
|
raise ServiceError.slurp(error, self)
|
2013-07-19 21:38:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def endpoint_uri(service_endpoint_url=nil)
|
|
|
|
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_queues_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticate(options={})
|
|
|
|
super({
|
|
|
|
:rackspace_api_key => @rackspace_api_key,
|
|
|
|
:rackspace_username => @rackspace_username,
|
|
|
|
:rackspace_auth_url => @rackspace_auth_url,
|
|
|
|
:connection_options => @connection_options
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def client_id
|
|
|
|
@rackspace_queues_client_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def client_id=(client_id)
|
|
|
|
@rackspace_queues_client_id = client_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|