Skip to content

Commit 6f5432f

Browse files
committed
Also post to Discord
1 parent e974482 commit 6f5432f

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

app/jobs/assembling_machine/youtube_update_job.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ def perform
2222
end
2323
end
2424

25-
http_client = Faraday.new(url: TYPEFULLY_API_URL) do |faraday|
25+
typefully_api = Faraday.new(url: TYPEFULLY_API_URL) do |faraday|
2626
faraday.request :json
2727
faraday.response :logger, Logger.new(STDOUT), bodies: true # 👈 enables body logging
2828
faraday.adapter Faraday.default_adapter
2929
end
30+
31+
discord_webhook = Faraday.new(url: ENV.fetch("YOUTUBE_TRACKER_DISCORD_WEBHOOK_URL")) do |faraday|
32+
faraday.request :json
33+
faraday.response :logger, Logger.new(STDOUT), bodies: true # 👈 enables body logging
34+
faraday.adapter Faraday.default_adapter
35+
end
36+
3037
if videos.present?
3138
videos.each do |video|
32-
http_client.post do |request|
39+
typefully_api.post do |request|
3340
request.headers = {
3441
"Content-Type": "application/json",
3542
"X-API-KEY": "Bearer #{ENV.fetch("TYPEFULLY_API_KEY")}"
@@ -39,6 +46,13 @@ def perform
3946
threadify: true
4047
}
4148
end
49+
50+
discord_webhook.post do |request|
51+
request.headers = { "Content-Type": "application/json" }
52+
request.body = {
53+
content: "<@&#{ENV.fetch("YOUTUBE_TRACKER_DISCORD_ROLE_ID")}>\n#{video.link}"
54+
}.to_json
55+
end
4256
end
4357
end
4458
end

0 commit comments

Comments
 (0)