This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 72c9a36
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
$API_KEY = ""; | ||
|
||
?> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
|
||
?> |