require 'cloud_powers/synapse/broadcast/channel'
module Smash
module CloudPowers
module Synapse
module Broadcast
include Smash::CloudPowers::Helpers
include Smash::CloudPowers::AwsResources
include Smash::CloudPowers::Zenv
# This method can be used to parse a queue name from its address.
# It can be handy if you need the name of a queue but you don't want
# the overhead of creating a QueueResource object.
#
# Parameters
# * url +String+
#
# Returns
# +String+
#
# Example
# board_name('https://sqs.us-west-53.amazonaws.com/001101010010/fooBar')
# => foo_bar_board
def channel_name(arg)
base_name = to_snake(arg.to_s.split('/').last)
%r{_channel$} =~ base_name ? base_name : "#{base_name}_channel"
end
# 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, **config)
channel_resource =
Smash::CloudPowers::Synapse::Broadcast::Channel.create!(
name: name, client: sns, **config
)
self.attr_map(channel_resource.call_name => channel_resource) do |attribute, resource|
instance_attr_accessor attribute
resource
end
channel_resource
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