Started filling in Model and Record code

This commit is contained in:
Gregory Oschwald 2013-05-07 14:23:19 -07:00
parent 76a40bb2a1
commit 531e11f3e2
15 changed files with 67 additions and 14 deletions

5
composer.json Normal file
View File

@ -0,0 +1,5 @@
{
"require": {
"guzzle/guzzle": "~3.1.1"
}
}

View File

@ -2,11 +2,18 @@
namespace GeoIP2\Model;
class City
class City extends Country
{
//XXX use properties
public $city;
public $location;
public $postal;
public $subdivisions;
public function __construct($raw, $language)
{
parent::__construct($raw, $language);
}
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Model;
class CityISPOrg
class CityISPOrg extends City
{
}

View File

@ -4,5 +4,17 @@ namespace GeoIP2\Model;
class Country
{
// XXX - use __get__
public $continent;
public $country;
public $registered_country;
public $represented_country;
public $traits;
public $raw;
public function __construct($raw, $language) {
$this->country = new \GeoIP2\Record\Country($raw['country']);
$this->raw = $raw;
}
}

View File

@ -2,7 +2,10 @@
namespace GeoIP2\Model;
class Omni
class Omni extends CityISPOrg
{
public function __construct($raw, $language) {
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace GeoIP2\Record;
abstract class AbstractPlaceRecord extends AbstractRecord
{
}

View File

@ -0,0 +1,18 @@
<?php
namespace GeoIP2\Record;
abstract class AbstractRecord
{
private $record;
public function __construct($record) {
$this->record = $record;
}
public function __get($attr) {
if (isset($this->record[$attr])) return $this->record[$attr];
throw new RuntimeException("Unknown attribute: $attr");
}
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class City
class City extends AbstractPlaceRecord
{
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class Continent
class Continent extends AbstractPlaceRecord
{
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class Country
class Country extends AbstractPlaceRecord
{
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class Location
class Location extends AbstractRecord
{
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class RepresentedCountry
class RepresentedCountry extends Country
{
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class Subdivision
class Subdivision extends AbstractPlaceRecord
{
}

View File

@ -2,7 +2,7 @@
namespace GeoIP2\Record;
class Traits
class Traits extends AbstractRecord
{
}

View File

@ -19,7 +19,7 @@ class Client
private $language;
private $base_uri = 'https://geoip.maxmind.com/geoip/v2.0';
function __construct($user_id, $license_key, $language='en')
public function __construct($user_id, $license_key, $language='en')
{
$this->user_id = $user_id;
$this->license_key = $license_key;