Commit 230ab802 authored by Jamie Tanna's avatar Jamie Tanna

Add Rake task for creating all the links

It's a pain to have to manually set these up, so instead, having
creation in a loop for each `utm_medium`, for enhanced tracking.
parent 04587dfe
Pipeline #36648949 passed with stages
in 9 minutes and 27 seconds
#!/usr/bin/env ruby
require 'json'
require 'kwalify'
require 'yaml'
......@@ -194,6 +195,32 @@ task :images_changed? do
fail "Images are not all minified: #{images_to_minify}" unless
desc 'Create short URLs for a given article URL'
task :bitly_urls, [:url] do |_, args|
raise ' personal access token not provided in ENV[BITLY_TOKEN]' if ENV.fetch('BITLY_TOKEN')
%w[ slack.c1 pulse twitter linkedin].each do |medium|
body = {
group_guid: 'Bb31fK0maG9',
domain: '',
long_url: args[:url] + "?utm_medium=#{medium}"
uri = URI.parse('')
https =, uri.port)
https.use_ssl = true
req =, initheader = {'Content-Type' =>'application/json'})
req['Authorization'] = 'Bearer ' + ENV['BITLY_TOKEN']
req.body = body.to_json
res = https.request(req)
if res.is_a?(Net::HTTPSuccess)
res_body = JSON.parse(res.body)
puts "#{medium}: #{res_body['link']}"
raise "Unsuccessful: Response #{res.code} #{res.message}: #{res.body}"
task validate: ['validate:posts', 'validate:projects', 'validate:talks']
task default: ['validate', 'test']
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment