module Smash
module CloudPowers
module Synapse
module Broadcast
include Smash::CloudPowers::Helper
include Smash::CloudPowers::AwsResources
include Smash::CloudPowers::Zenv
# A simple Struct to bind the name with the arn of the topic
Channel = Struct.new(:set_name, :set_arn, :set_endpoint) do
include Smash::CloudPowers::Zenv
# Prefers the given arn but it can make a best guess if none is given
#
# Returns
# arn +String+ - arn for this resource
def arn
set_arn || "arn:aws:sns:#{zfind(:region)}:#{zfind(:accound_number)}:#{set_name}"
end
# Prefers the given name but it can parse the arn to find one
#
# Returns
# name +String+ - name for this resource
def name
set_name || set_arn.split(':').last
end
end # end Channel
#################
# Creates a connection point for 1..N nodes to create a connection with the Broadcast
# Not Implimented
#
# Parameters
# * channel +String+
#
# Notes
# This method is not implemented yet (V 0.2.7)
def create_distributor(channel)
sns.create_application_platform()
end
# Creates a point to connect to for information about a given topic
#
# Parameters
# * name +String+ - the name of the Channel/Topic to be created
#
# Returns
# +Broadcast::Channel+ - representing the created channel
def create_channel!(name)
resp = sns.create_topic(name: name)
Channel.new(nil, resp.topic_arn)
end
# Deletes a topic from SNS-land
#
# Parameters
# * channel
def delete_channel!(channel)
sns.delete_topic(topic_arn: channel.arn)
end
# Creates a connection to the Broadcast so that new messages will be picked up
#
# Parameters channel
def listen_on(channel)
sns.subscribe(
topic_arn: channel.arn,
protocol: 'application',
endpoint: channel.endpoint
)
end
# Lists the created topics in SNS.
#
# Returns results