Class: Simnos::ClientWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Filterable
Defined in:
lib/simnos/client_wrapper.rb

Instance Method Summary collapse

Methods included from Filterable

#target?

Constructor Details

#initialize(options) ⇒ ClientWrapper

Returns a new instance of ClientWrapper.



12
13
14
15
16
17
18
19
# File 'lib/simnos/client_wrapper.rb', line 12

def initialize(options)
  @options = options
  if options[:region]
    @client = Aws::SNS::Client.new(region: @options[:region])
  else
    @client = Aws::SNS::Client.new
  end
end

Instance Method Details

#regionObject



54
55
56
# File 'lib/simnos/client_wrapper.rb', line 54

def region
  @client.config.region
end

#subscriptions_by_topic(topic_arn:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/simnos/client_wrapper.rb', line 43

def subscriptions_by_topic(topic_arn: )
  results = []
  next_token = nil
  begin
    resp = @client.list_subscriptions_by_topic(topic_arn: topic_arn, next_token: next_token)
    results.concat(resp.subscriptions)
    next_token = resp.next_token
  end while next_token
  results
end

#topic_attrs(topic_arn:) ⇒ Object



21
22
23
# File 'lib/simnos/client_wrapper.rb', line 21

def topic_attrs(topic_arn: )
  @client.get_topic_attributes(topic_arn: topic_arn)
end

#topicsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/simnos/client_wrapper.rb', line 25

def topics
  results = {}
  next_token = nil
  begin
    resp = @client.list_topics(next_token: next_token)
    resp.topics.each do |t|
      name = t.topic_arn.split(':').last
      next unless target?(name)
      results[name] = {
        topic: t,
        attrs: topic_attrs(topic_arn: t.topic_arn),
      }
    end
    next_token = resp.next_token
  end while next_token
  results
end