class Moromi::Aws::Sns::Client

Public Class Methods

new(region, credentials: nil) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 7
def initialize(region, credentials: nil)
  @credentials = credentials
  @region = region
end

Public Instance Methods

get_endpoint_attributes(endpoint_arn) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 79
def get_endpoint_attributes(endpoint_arn)
  params = {
    endpoint_arn: endpoint_arn
  }
  results = client.get_endpoint_attributes(params)
  results.attributes
end
inactive(arn) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 49
def inactive(arn)
  params = {
    endpoint_arn: arn,
    attributes: {'Enabled' => 'false'}
  }
  client.set_endpoint_attributes(params)
end
publish(arn, parameter) click to toggle source

@param [String] arn @param [Moromi::Aws::Sns::Message::Parameter] parameter

# File lib/moromi/aws/sns/client.rb, line 59
def publish(arn, parameter)
  options = {
    target_arn: arn,
    message: parameter.to_json,
    message_structure: 'json'
  }
  call_publish(options)
end
publish_to_topic(topic_arn, parameter) click to toggle source

@param [String] topic_arn @param [Moromi::Aws::Sns::Message::Parameter] parameter

# File lib/moromi/aws/sns/client.rb, line 70
def publish_to_topic(topic_arn, parameter)
  options = {
    topic_arn: topic_arn,
    message: parameter.to_json,
    message_structure: 'json'
  }
  call_publish(options)
end
register(platform_application_arn, token, force_enable: true) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 12
def register(platform_application_arn, token, force_enable: true)
  params = {
    platform_application_arn: platform_application_arn,
    token: token
  }

  response = client.create_platform_endpoint(params)
  arn = response.endpoint_arn

  if force_enable
    params = {
      endpoint_arn: arn,
      attributes: {'Enabled' => 'true'}
    }
    client.set_endpoint_attributes(params)
  end

  arn
end
subscribe(topic_arn, endpoint_arn) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 32
def subscribe(topic_arn, endpoint_arn)
  params = {
    topic_arn: topic_arn,
    protocol: 'application',
    endpoint: endpoint_arn
  }
  response = client.subscribe(params)
  response.subscription_arn
end
unsubscribe(subscription_arn) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 42
def unsubscribe(subscription_arn)
  params = {
    subscription_arn: subscription_arn
  }
  client.unsubscribe(params)
end

Private Instance Methods

call_publish(options) click to toggle source
# File lib/moromi/aws/sns/client.rb, line 99
def call_publish(options)
  response = client.publish(options)
  response.message_id
end
client() click to toggle source
# File lib/moromi/aws/sns/client.rb, line 89
def client
  @client ||= begin
                if @credentials
                  ::Aws::SNS::Client.new(region: @region, credentials: @credentials)
                else
                  ::Aws::SNS::Client.new(region: @region)
                end
              end
end