Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
paultag committed Dec 21, 2011
0 parents commit 72c9a36
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conf/openstates.php
@@ -0,0 +1,5 @@
<?php

$API_KEY = "";

?>
10 changes: 10 additions & 0 deletions index.php
@@ -0,0 +1,10 @@
<?php

include( "openstates/openstates.php" );
include( "conf/openstates.php" );

$x = new openstates( $API_KEY );

print_r($x->legislators("state=ma"));

?>
Binary file added openstates/.openstates.php.swp
Binary file not shown.
39 changes: 39 additions & 0 deletions openstates/openstates.php
@@ -0,0 +1,39 @@
<?php

class openstates {

private $api_key;
private $urlbase;

private function queryService( $fn, $args ) {
$query_url = $this->urlbase . "$fn/?apikey=" . $this->api_key;
foreach ( $args as $key ) {
$query_url .= "&" . $key;
}
return $this->getJSON( $query_url );
}

private function getJSON( $URL ) {
$contents = file_get_contents($URL);
$contents = json_decode($contents);
return $contents;
}

public function __construct($api_key,
$urlbase = "http://openstates.org/api/v1/"
) {
$this->api_key = $api_key;
$this->urlbase = $urlbase;
}

public function __call($method, $args) {
if (isset($this->$method) === true) {
$func = $this->$method;
return $func();
} else {
return $this->queryService($method, $args);
}
}
}

?>

0 comments on commit 72c9a36

Please sign in to comment.