Class: RightScale::CloudApi::AWS::SQS::ApiManager

Inherits:
CloudApi::ApiManager
  • Object
show all
Defined in:
lib/cloud/aws/sqs/manager.rb

Overview

Amazon Simple Queue Service (SQS) compatible manager (thread unsafe).

See Also:

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_API_VERSION =

Default API version for SQS service. To override the API version use :api_version key when instantiating a manager.

'2011-10-01'

Instance Method Summary collapse

Constructor Details

#initialize(aws_access_key_id, aws_secret_access_key, aws_account_number, endpoint, options = {}) ⇒ ApiManager

Constructor

Examples:

# see Manager class

Parameters:

  • aws_access_key_id (String)
  • aws_secret_access_key (String)
  • aws_account_number (String)
  • endpoint (String)
  • options (Hash) (defaults to: {})

See Also:



238
239
240
241
242
243
# File 'lib/cloud/aws/sqs/manager.rb', line 238

def initialize(aws_access_key_id, aws_secret_access_key, , endpoint, options={})
  credentials = { :aws_account_number    => ,
                  :aws_access_key_id     => aws_access_key_id,
                  :aws_secret_access_key => aws_secret_access_key }
  super(credentials, endpoint, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Adds an ability to call SQS API methods by their names

Examples:

sqs.ListQueues
sqs.SetQueueAttributes('myCoolQueue1', {'Attribute.?.Name' => 'Attribute.?.Value'})

Returns:

  • (Object)


323
324
325
326
327
328
329
# File 'lib/cloud/aws/sqs/manager.rb', line 323

def method_missing(method_name, *args, &block)
  if method_name.to_s[/\A[A-Z]/]
    api(method_name, *args, &block)
  else
    super
  end
end

Instance Method Details

#api(action, *args) ⇒ Object

Makes an API call to AWS::Ec2 compatible cloud

Examples:

# Where opts may have next keys: :options, :headers, :body
api(action, queue_name, opts={})
api(action, opts={})
sqs.api('ListQueues')
sqs.api('SetQueueAttributes', 'myCoolQueue1', {'Attribute.?.Name' => 'Attribute.?.Value'}#

Parameters:

  • action (String)

    The action as Amazon names it in its docs.

Returns:

  • (Object)


262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/cloud/aws/sqs/manager.rb', line 262

def api(action, *args)
  queue_name = args.shift if args.first.is_a?(String)
  opts     = args.shift || {}
  # Uri Parameters
  opts['Action'] ||= action.to_s._snake_case._camelize
  options           = {}
  options[:body]    = opts.delete(:body)
  options[:headers] = opts.delete(:headers) || {}
  options[:options] = opts.delete(:options) || {}
  options[:params]  = parametrize(opts)
  # Options and Per Queue URI
  path = queue_name._blank? ? '' : "#{@credentials[:aws_account_number]}/#{queue_name}"
  process_api_request(:get, path, options)
end

#parametrize(*args) ⇒ Hash Also known as: p9e

Parametrize data to the format that Amazon EC2 and compatible services accept

See Utils::AWS.parametrize for more examples.

Examples:

parametrize( 'ParamA'             => 'a',
             'ParamB'             => ['b', 'c'],
             'ParamC.?.Something' => ['d', 'e'],
             'Filter'             => [ { 'Key' => 'A', 'Value' => ['aa','ab']},
                                       { 'Key' => 'B', 'Value' => ['ba','bb']}] ) #=>
  {
    "Filter.1.Key"       => "A",
    "Filter.1.Value.1"   => "aa",
    "Filter.1.Value.2"   => "ab",
    "Filter.2.Key"       => "B",
    "Filter.2.Value.1"   => "ba",
    "Filter.2.Value.2"   => "bb",
    "ParamA"             => "a",
    "ParamB.1"           => "b",
    "ParamB.2"           => "c",
    "ParamC.1.Something" => "d",
    "ParamC.2.Something" => "e"
  }

Returns:

  • (Hash)

    A hash of data in the format Amazon want to get.



304
305
306
# File 'lib/cloud/aws/sqs/manager.rb', line 304

def parametrize(*args) # :nodoc:
  Utils::AWS.parametrize(*args)
end