Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/notifier.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'http'
require 'json'
require 'date'
require 'uri'

require_relative './page'
require_relative './notification/expired'
Expand Down Expand Up @@ -37,7 +38,10 @@ def run
end

def pages
JSON.parse(HTTP.get(@pages_url)).map { |data| Page.new(data) }
JSON.parse(HTTP.get(@pages_url)).map { |data|
data['url'] = get_absolute_url(data['url'])
Page.new(data)
}
end

def pages_per_channel
Expand Down Expand Up @@ -85,4 +89,26 @@ def message_payloads(grouped_pages)
def post_to_slack?
@live
end

private

def get_absolute_url url
target_uri = URI(url)
target_path = Pathname.new(target_uri.path)
source_uri = URI(@pages_url)

if target_path.relative?
resulting_path = URI::join(source_uri, target_uri.path).path
else
resulting_path = target_uri.path
end

if source_uri.scheme == 'https'
URI::HTTPS.build(scheme: source_uri.scheme, port: source_uri.port, host: source_uri.host, path: resulting_path).to_s
else
URI::HTTP.build(scheme: source_uri.scheme, port: source_uri.port, host: source_uri.host, path: resulting_path).to_s
end
end
end