Module: SQS

Includes:
Utilities
Defined in:
lib/sqs_async/sqs_utilities.rb,
lib/sqs_async/sqs.rb,
lib/sqs_async/sqs_permission.rb

Overview

These mixins are lovingly taken from active support. License information is available online at rubyonrails.org

Defined Under Namespace

Modules: Permissions, Utilities

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#action_from_caller, #camelize, #underscore

Instance Attribute Details

#aws_keyObject

Returns the value of attribute aws_key.



21
22
23
# File 'lib/sqs_async/sqs.rb', line 21

def aws_key
  @aws_key
end

#aws_secretObject

Returns the value of attribute aws_secret.



21
22
23
# File 'lib/sqs_async/sqs.rb', line 21

def aws_secret
  @aws_secret
end

#default_parametersObject

Returns the value of attribute default_parameters.



21
22
23
# File 'lib/sqs_async/sqs.rb', line 21

def default_parameters
  @default_parameters
end

#post_options=(value) ⇒ Object

Sets the attribute post_options

Parameters:

  • value

    the value to set the attribute post_options to.



21
22
23
# File 'lib/sqs_async/sqs.rb', line 21

def post_options=(value)
  @post_options = value
end

#regions=(value) ⇒ Object

Sets the attribute regions

Parameters:

  • value

    the value to set the attribute regions to.



21
22
23
# File 'lib/sqs_async/sqs.rb', line 21

def regions=(value)
  @regions = value
end

Instance Method Details

#add_permission(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sqs_async/sqs.rb', line 51

def add_permission(options={})
  raise "no target queue specified" unless options[:queue]
  raise "no permissions objects specified" unless options[:permissions]

  [options[:permissions]].flatten.each_with_index do |perm, index|
    ordinal = index+1
    options.merge!(perm.to_params(ordinal)) # last label wins.
  end

  options.delete(:permissions)

  call_amazon(options)
end

#change_message_visibility(options = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/sqs_async/sqs.rb', line 23

def change_message_visibility(options={})
  raise "no Message specified" unless options[:message]
  raise "no new visibility_timeout specified" unless options[:visibility_timeout]
  options.merge!( :receipt_handle => options.delete(:message).receipt_handle,
                  :visibility_timeout => options.delete(:visibility_timeout).to_i)
  call_amazon(options)
end

#create_queue(options = {}) ⇒ Object



115
116
117
118
119
# File 'lib/sqs_async/sqs.rb', line 115

def create_queue(options={})
  raise "no queue name specified" unless options[:queue_name]
  options[:default_visibility_timeout] = 30 unless options[:default_visibility_timeout]
  call_amazon(options){ |req| SQSQueue.parse(req.response) }
end

#delete_message(options = {}) ⇒ Object



98
99
100
101
102
# File 'lib/sqs_async/sqs.rb', line 98

def delete_message(options={})
  raise "no Message specified" unless options[:message]
  options.merge!(:receipt_handle => options.delete(:message).receipt_handle)
  call_amazon(options)
end

#delete_queue(options = {}) ⇒ Object



110
111
112
113
# File 'lib/sqs_async/sqs.rb', line 110

def delete_queue(options={})
  raise "no target queue specified" unless options[:queue]
  call_amazon(options)
end

#get_queue_attributes(options = {}) ⇒ Object



104
105
106
107
108
# File 'lib/sqs_async/sqs.rb', line 104

def get_queue_attributes(options={})
  raise "no target queue specified" unless options[:queue]
  options = {:attribute_name => "All" }.merge(options)
  call_amazon(options){ |req| SQSAttributes.parse(req.response) }
end

#list_queues(options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/sqs_async/sqs.rb', line 79

def list_queues(options={})
  prefix = options.delete(:prefix)
  match = options.delete(:match)

  options.merge!( :queue_name_prefix => encode(prefix) ) if prefix

  call_amazon(options) do |req|
    queues = SQSQueue.parse(req.response)
    queues.select!{|q| q.queue_url.path.match(match) } if match
    queues
  end
end

#receive_message(options = {}) ⇒ Object



92
93
94
95
96
# File 'lib/sqs_async/sqs.rb', line 92

def receive_message(options={})
  raise "no target queue specified" unless options[:queue]
  options = { :max_number_of_messages => 10 }.merge(options)
  call_amazon(options){ |req| SQSMessage.parse(req.response) }
end

#remove_permission(options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sqs_async/sqs.rb', line 65

def remove_permission(options={})
  raise "no target queue specified" unless options[:queue]
  raise "no permissions objects specified" unless options[:permissions]

  [options[:permissions]].flatten.each_with_index do |perm, index|
    ordinal = index+1
    options.merge!(perm.to_params(ordinal)) # last label wins.
  end

  options.delete(:permissions)

  call_amazon(options)
end

#send_message(options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/sqs_async/sqs.rb', line 43

def send_message(options={})
  raise "no object(:message) or string(:message_body) specified" unless (options[:message] || options[:message_body])
  options.merge!( :message_body => options.delete(:message).body ) if options[:message]
  body = options[:message_body]

  call_amazon(options){ |req| SQSSendMessageResponse.parse(body, req.response) }
end

#set_queue_attributes(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sqs_async/sqs.rb', line 31

def set_queue_attributes(options={})
  raise "no target queue specified" unless options[:queue]
  %w[ :visibility_timeout :policy :maximum_message_size :message_retention_period ].each do |attr_type|
    if options[attr_type]
      val = options.delete(attr_type)
      options.merge! "Attribute.Name" => camelize(attr_type), "Attribute.Value" => val
    end
  end

  call_amazon(options)
end