Last active
January 22, 2016 14:47
-
-
Save elliotcm/68ad1bb7f05a5953c3ab to your computer and use it in GitHub Desktop.
Tool to set "autosend" flag for pagewatch in govdelivery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require_relative "../lib/travel_advice_pagewatch_adjuster" | |
TravelAdvicePagewatchAdjuster.set_pagewatch_autosend(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require_relative "../lib/travel_advice_pagewatch_adjuster" | |
TravelAdvicePagewatchAdjuster.set_pagewatch_autosend(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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