Skip to content

Instantly share code, notes, and snippets.

@njh
Created June 27, 2024 07:10
Show Gist options
  • Save njh/d01ebe484b01075ccb0c45fc01786af9 to your computer and use it in GitHub Desktop.
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
#!/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