Skip to content

Commit f9ce359

Browse files
author
Dave Newman
committed
Push to youtube if selected
1 parent 6738d8e commit f9ce359

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

app/controllers/quickstream_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ class QuickstreamController < ApplicationController
33

44
def webhook
55
@user = User.find_by!(stream_key: params[:token])
6-
head(200)
7-
end
8-
9-
# private
10-
11-
def process_unsubscribe(data)
12-
User.where(email: data['email']).update_all(marketing_list: nil)
6+
render nothing: true, status: :ok
137
end
148
end

app/controllers/streams_controller.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ class StreamsController < ApplicationController
55

66
def new
77
@stream = current_user.active_stream || Stream.new(user: current_user)
8+
if @stream.new_record?
9+
if old_stream = current_user.streams.order(created_at: :desc).first
10+
@stream.title = old_stream.title
11+
@stream.body = old_stream.body
12+
@stream.tags = old_stream.tags
13+
end
14+
end
815
if current_user.stream_key.blank?
916
current_user.generate_stream_key
1017
current_user.save!
@@ -81,12 +88,16 @@ def stream_params
8188
def save_and_redirect
8289
@stream.published_at ||= Time.now if params[:publish_stream]
8390
@stream.archived_at ||= Time.now if params[:end_stream]
91+
current_user.streams.where(archived_at: nil).update_all(archived_at: Time.now)
8492
if @stream.save
8593
case
8694
when @stream.archived?
95+
end_youtube_stream
8796
flash[:notice] = "Your stream has been archived"
8897
redirect_to live_streams_path
8998
when @stream.published?
99+
Rails.logger.info("pushing to youtube")
100+
stream_to_youtube if @stream.save_recording
90101
redirect_to profile_stream_path(current_user.username)
91102
else
92103
redirect_to new_stream_path
@@ -95,4 +106,27 @@ def save_and_redirect
95106
render 'new'
96107
end
97108
end
109+
110+
def stream_to_youtube
111+
url = "#{ENV['QUICKSTREAM_URL']}/streams/#{@stream.user.username}/youtube"
112+
Excon.put(url,
113+
headers: {
114+
"Accept" => "application/json",
115+
"Content-Type" => "application/json" },
116+
body: {title: @stream.title, description: @stream.body}.to_json,
117+
idempotent: true,
118+
tcp_nodelay: true,
119+
)
120+
end
121+
122+
def end_youtube_stream
123+
url = "#{ENV['QUICKSTREAM_URL']}/streams/#{@stream.user.username}/youtube"
124+
Excon.delete(url,
125+
headers: {
126+
"Accept" => "application/json",
127+
"Content-Type" => "application/json" },
128+
idempotent: true,
129+
tcp_nodelay: true,
130+
)
131+
end
98132
end

0 commit comments

Comments
 (0)