Skip to content

Instantly share code, notes, and snippets.

@randika
Last active May 4, 2017 05:39
Show Gist options
  • Save randika/e42f7b719c58704e12c34d2b1121982b to your computer and use it in GitHub Desktop.
Save randika/e42f7b719c58704e12c34d2b1121982b to your computer and use it in GitHub Desktop.
def sns_transcode_completed
amz_message_type = request.headers['x-amz-sns-message-type']
amz_sns_topic = request.headers['x-amz-sns-topic-arn']
if !amz_sns_topic.nil? &&
amz_sns_topic.to_s.downcase == Settings.aws.transcode.sns_topic_arn
request_body = JSON.parse(request.body.read, {:symbolize_names => true})
notification = Hashie::Mash.new(request_body)
puts request_body.inspect
if amz_message_type.to_s.downcase == 'subscriptionconfirmation'
subscribe_url = request_body['SubscribeURL']
if !subscribe_url.to_s.empty? && !subscribe_url.nil?
subscribe_confirm = HTTParty.get subscribe_url
puts subscribe_confirm
puts subscribe_url
end
end
if amz_message_type.to_s.downcase == 'notification'
puts "--------------------------"
puts notification.inspect
puts "--------------------------"
puts notification.MessageId
puts "--------------------------"
puts notification.Message
puts "--------------------------"
puts "Result is #{notification.Message}"
puts "--------------------------"
parsed_message = JSON.parse(notification.Message, {:symbolize_names => true})
puts parsed_message.inspect
puts "--------------------------"
message = Message.where(transcode_job_id: parsed_message[:jobId]).first
if message.present?
# SET THE MESSAGE TO PUBLISHED STATE & TRIGGER SENDOUTS
# BETTER CHECK THE THE AWS TRANSCODER JOB STATUS TOO
message.update_attributes(state: Message::STATE_PUBLISHED)
message.sendouts.update_all(state: Sendout::STATE_PUBLISHED)
message.send_push_notifications
end
end
end
render :nothing => true, :status => 200, :content_type => 'text/html'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment