class AwsSnsKit::AwsClient

Attributes

client_wrapper[R]
instance[R]
notification[R]

Public Class Methods

new(instance, notification) click to toggle source
# File lib/aws_sns_kit/aws_client.rb, line 5
def initialize(instance, notification)
  @client_wrapper = AWS::SNS.new.client
  @instance = instance
  @notification = notification
end

Public Instance Methods

publish() click to toggle source
# File lib/aws_sns_kit/aws_client.rb, line 11
def publish
  client_wrapper.publish(target_arn: platform_endpoint, message: notification.message, message_structure: "json")
rescue AWS::SNS::Errors::EndpointDisabled
  retry if enable
end

Private Instance Methods

create_endpoint() click to toggle source
# File lib/aws_sns_kit/aws_client.rb, line 26
def create_endpoint
  arn = AwsSnsKit.configuration.end_point(instance.sns_platform)
  response = client_wrapper.create_platform_endpoint(
    platform_application_arn: arn, 
    token: instance.device_token
  )
  instance.platform_endpoint = response[:endpoint_arn]
  instance.save!
end
enable() click to toggle source
# File lib/aws_sns_kit/aws_client.rb, line 19
def enable
  client_wrapper.set_endpoint_attributes({
    attributes: { "Enabled" =>  "true", "CustomUserData" => instance.sns_custom_data}, 
    endpoint_arn: platform_endpoint
  })
end
platform_endpoint() click to toggle source
# File lib/aws_sns_kit/aws_client.rb, line 36
def platform_endpoint
  if publishable?
    instance.platform_endpoint
  else 
    if create_endpoint
      instance.platform_endpoint
    end
  end
end
publishable?() click to toggle source
# File lib/aws_sns_kit/aws_client.rb, line 46
def publishable?
  instance.platform_endpoint?
end