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
requires :rackspace_api_key , :rackspace_username , :rackspace_queues_client_id
recognizes :rackspace_auth_url
recognizes :rackspace_auth_token
recognizes :rackspace_endpoint
recognizes :rackspace_region
recognizes :rackspace_queues_url
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 ]
@rackspace_queues_client_id = options [ :rackspace_queues_client_id ]
@rackspace_auth_url = options [ :rackspace_auth_url ]
@rackspace_must_reauthenticate = false
@connection_options = options [ :connection_options ] || { }
@rackspace_endpoint = Fog :: Rackspace . normalize_url ( options [ :rackspace_queues_url ] || options [ :rackspace_endpoint ] )
unless v2_authentication?
raise Fog :: Errors :: NotImplemented . new ( " V2 authentication required for Queues " )
end
authenticate
deprecation_warnings ( options )
@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
private
def deprecation_warnings ( options )
Fog :: Logger . deprecation ( " The :rackspace_endpoint option is deprecated. Please use :rackspace_queues_url for custom endpoints " ) if options [ :rackspace_endpoint ]
# if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication?
# regions = @identity_service.service_catalog.display_service_regions(service_name)
# Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid region for :rackspace_region are #{regions}.")
# end
end
end
end
end
end