Created
June 27, 2024 07:10
-
-
Save njh/d01ebe484b01075ccb0c45fc01786af9 to your computer and use it in GitHub Desktop.
Ruby script that checks if FTTP is available at an address using the AAISP CHAOS API
This file contains hidden or 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 'net/http' | |
require 'json' | |
require 'uri' | |
options = { | |
new_account: true, | |
new_line: true, | |
api: 'fttp-checker', | |
pre_order: true, | |
customer_type: 'H', | |
postcode: 'W1A 1AA', # Change this | |
nad: 'WEA00065881466' # Change this | |
} | |
def hash_to_query(hash) | |
return hash.map{|k,v| "#{k}=#{v.to_s.sub(' ', '+')}"}.join('&') | |
end | |
uri = URI.parse('https://chaos2.aa.net.uk/broadband2/availability') | |
uri.query = hash_to_query(options) | |
res = Net::HTTP.get_response(uri) | |
if res.code != '200' | |
raise "Chaos 2 request failed: #{res.code} #{res.message}" | |
end | |
data = JSON.parse(res.body, symbolize_names: true) | |
available_services = [] | |
data[:availability].each do |availability| | |
availability[:service].each do |service| | |
available_services << service[:type] | |
end | |
end | |
if available_services.include?('FTTP') | |
puts "FTTP is available at #{options[:postcode]}!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment