Class: AwsSnsManager::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_sns_manager/client.rb

Overview

AwsSnsManager::Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/aws_sns_manager/client.rb', line 7

def initialize(options = {})
  super()

  @client = Aws::SNS::Client.new(options)
end

Instance Attribute Details

#arnObject

Returns the value of attribute arn.



5
6
7
# File 'lib/aws_sns_manager/client.rb', line 5

def arn
  @arn
end

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/aws_sns_manager/client.rb', line 4

def client
  @client
end

Instance Method Details

#message(text) ⇒ Object



27
28
29
30
31
# File 'lib/aws_sns_manager/client.rb', line 27

def message(text)
  {
    APNS: notification(text).to_json
  }
end

#notification(text) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/aws_sns_manager/client.rb', line 33

def notification(text)
  {
    aps: {
      alert: text,
      sound: 'default',
      badge: 1
    }
  }
end

#publish_rescue(message) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/aws_sns_manager/client.rb', line 19

def publish_rescue(message)
  client.publish(
    target_arn: arn,
    message: message,
    message_structure: 'json'
  )
end

#sendObject



13
14
15
16
17
# File 'lib/aws_sns_manager/client.rb', line 13

def send
  message = message('Hi').to_json
  response = publish_rescue(message)
  !response.nil?
end