Class: EventQ::Amazon::QueueClient

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_aws/aws_queue_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ QueueClient

Returns a new instance of QueueClient.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/eventq_aws/aws_queue_client.rb', line 8

def initialize(options = {})

  if options.has_key?(:aws_key)
    Aws.config[:credentials] = Aws::Credentials.new(options[:aws_key], options[:aws_secret])
  end

  if !options.has_key?(:aws_account_number)
    raise ':aws_account_number option must be specified.'.freeze
  end

  @aws_account = options[:aws_account_number]

  if options.has_key?(:aws_region)
    @aws_region = options[:aws_region]
    Aws.config[:region] = @aws_region
  else
    @aw_region = Aws.config[:region]
  end

  @sns = Aws::SNS::Client.new
  @sqs = Aws::SQS::Client.new

end

Instance Attribute Details

#snsObject (readonly)

Returns the value of attribute sns.



5
6
7
# File 'lib/eventq_aws/aws_queue_client.rb', line 5

def sns
  @sns
end

#sqsObject (readonly)

Returns the value of attribute sqs.



6
7
8
# File 'lib/eventq_aws/aws_queue_client.rb', line 6

def sqs
  @sqs
end

Instance Method Details

#aws_safe_name(name) ⇒ Object



53
54
55
# File 'lib/eventq_aws/aws_queue_client.rb', line 53

def aws_safe_name(name)
  return name.gsub(':', '')
end

#create_topic_arn(event_type) ⇒ Object



40
41
42
43
# File 'lib/eventq_aws/aws_queue_client.rb', line 40

def create_topic_arn(event_type)
  response = @sns.create_topic({ name: aws_safe_name(event_type) })
  return response.topic_arn
end

#get_queue_arn(queue) ⇒ Object



36
37
38
# File 'lib/eventq_aws/aws_queue_client.rb', line 36

def get_queue_arn(queue)
  return "arn:aws:sqs:#{@aws_region}:#{@aws_account}:#{aws_safe_name(queue.name)}"
end

#get_queue_url(queue) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/eventq_aws/aws_queue_client.rb', line 45

def get_queue_url(queue)
  response= @sqs.get_queue_url({
                                      queue_name: aws_safe_name(queue.name),
                                      queue_owner_aws_account_id: @aws_account,
                                  })
  return response.queue_url
end

#get_topic_arn(event_type) ⇒ Object



32
33
34
# File 'lib/eventq_aws/aws_queue_client.rb', line 32

def get_topic_arn(event_type)
  return "arn:aws:sns:#{@aws_region}:#{@aws_account}:#{aws_safe_name(event_type)}"
end