Skip to content

Instantly share code, notes, and snippets.

@anthonysterling
Created August 11, 2012 17:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonysterling/3325848 to your computer and use it in GitHub Desktop.
Save anthonysterling/3325848 to your computer and use it in GitHub Desktop.
PHP Class to lookup Virgin Media services status
<?php
class VirginMediaStatus
{
const
SERVICE_ALL = 1,
SERVICE_BROADBAND = 2,
SERVICE_TV = 4,
SERVICE_PHONE = 8;
protected
$uri = 'https://my.virginmedia.com/faults/service-status',
$pattern = '~(?<=<span class=")(no-)?issues-found">([^<]+)(?=<)~';
public function __construct()
{
if( ! extension_loaded('curl'))
{
throw new Exception('no curl');
}
}
public function check($postcode)
{
$html = $this->request($this->uri, array('postCode' => $postcode));
$data = $this->parse($html);
$results = array(
self::SERVICE_BROADBAND => null,
self::SERVICE_TV => null,
self::SERVICE_PHONE => null
);
if($data)
{
$results[self::SERVICE_BROADBAND] = $data[0];
$results[self::SERVICE_TV] = $data[1];
$results[self::SERVICE_PHONE] = $data[2];
}
return $results;
}
protected function request($uri, array $data = array())
{
$handle = curl_init($uri);
curl_setopt_array($handle, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data)
));
return curl_exec($handle);
}
protected function parse($html)
{
$matches = array();
preg_match_all($this->pattern, $html, $matches);
return isset($matches[2]) ? $matches[2] : false ;
}
}
$virgin = new VirginMediaStatus;
$status = $virgin->check('NE270QF');
echo 'Broadband Status: ' . $status[VirginMediaStatus::SERVICE_BROADBAND] . PHP_EOL;
echo 'TV Status: ' . $status[VirginMediaStatus::SERVICE_TV] . PHP_EOL;
echo 'Phone Status: ' . $status[VirginMediaStatus::SERVICE_PHONE] . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment