Skip to content

Instantly share code, notes, and snippets.

@elliotcm
Last active January 22, 2016 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotcm/68ad1bb7f05a5953c3ab to your computer and use it in GitHub Desktop.
Save elliotcm/68ad1bb7f05a5953c3ab to your computer and use it in GitHub Desktop.
Tool to set "autosend" flag for pagewatch in govdelivery.
#!/usr/bin/env ruby
require_relative "../lib/travel_advice_pagewatch_adjuster"
TravelAdvicePagewatchAdjuster.set_pagewatch_autosend(false)
#!/usr/bin/env ruby
require_relative "../lib/travel_advice_pagewatch_adjuster"
TravelAdvicePagewatchAdjuster.set_pagewatch_autosend(true)
require "open-uri"
require "nokogiri"
class TravelAdvicePagewatchAdjuster
BASE_URL = "https://username:password@api.govdelivery.com"
TRAVEL_ADVICE_TOPICS_PATH = "/api/account/UKGOVUK/categories/UKGOVUK_C6/topics.xml"
def self.set_pagewatch_autosend(boolean)
ta_topics = Nokogiri::Slop(`curl -s #{BASE_URL + TRAVEL_ADVICE_TOPICS_PATH}`)
ta_topics.topics.topic.each do |topic|
topic_name = topic.send(:'short-name').text
if boolean
puts "Enabling pagewatch autosend on topic #{topic_name}"
else
puts "Disabling pagewatch autosend on topic #{topic_name}"
end
topic_path = topic.send(:'topic-uri').text
topic_data = `curl -s #{BASE_URL + topic_path}`
if boolean
topic_data.gsub!(
'<pagewatch-autosend type="boolean">false</pagewatch-autosend>',
'<pagewatch-autosend type="boolean">true</pagewatch-autosend>'
)
else
topic_data.gsub!(
'<pagewatch-autosend type="boolean">true</pagewatch-autosend>',
'<pagewatch-autosend type="boolean">false</pagewatch-autosend>'
)
end
topic_data.gsub!(/\n/, '')
system "curl -s -X PUT --data '#{topic_data}' -H 'Content-Type: application/xml; charset: utf-8' #{BASE_URL + topic_path}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment