Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
vendor/
77 changes: 47 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
php-votesmart
=======================
A PHP library for use with the Vote Smart API(http://votesmart.org/share/api).
A PHP library for use with the Vote Smart API (http://votesmart.org/share/api).

------------
Requirements
Expand All @@ -11,43 +11,60 @@ The PHP libraries require PHP 5 with the SimpleXML extension and ``allow_url_fop
------------
Usage
------------
Using the libraries is fairly simple. You initialize the object with the name one of the methods and any arguments needed in an array. Then a call go ``getXmlObj()`` can be made to retrieve a SimpleXML object to work with. Let's say you wanted to get information on a bill...::
First, you need your API token. Once you get that from VoteSmart.org, store the API token in a file which is loaded
by your application. It should be defined as::

// Initialize the VoteSmart object
$obj = new VoteSmart(
'CandidateBio.getBio',
Array(
'candidateId' => 9026
));
$_ENV['VOTESMART_API_KEY']

// Get the SimpleXML object
Using the libraries is fairly simple. You initialize the object, and call ``query()`` to make the call parse the
response from VoteSmart. If there is no response, or the request fails, the output is boolean ``false``::

// Initialize the VoteSmart object. The default output type is XML.
$obj = new VoteSmart();

// You can also pass in optional to change the expected output type, and the location where the API token is located
// inside the $_ENV global variable. In this case, your VoteSmart API key would be stored in $_ENV['SOME_KEY'].
$obj = new VoteSmart('JSON', 'SOME_KEY');

// Make the query with required parameters, with the name of one of the methods, and any required or optional
// arguments in an array. Let's say you wanted to get information on a bill. For example:
$x = $obj->query(
'CandidateBio.getBio',
Array(
'candidateId' => 9026
)
);

// Once a query has been made, you can also get the stored decoded response.
// If your output type was XML, you could access the SimpleXMLElement object via
$x = $obj->getXmlObj();

// If your output type was JSON, you could access the array via
$x = $obj->getJsonObj();

Now ``$xml_object`` is a SimpleXML object representative of the XML structure. Here's a small cut from the XML itself.::

<?xml version="1.0" encoding="UTF-8"?>
<bio>
<generalInfo>
<title>Project Vote Smart - Bio - Rep. Stephen Scalise</title>
<linkBack>http://votesmart.org/bio.php?can_id=9026</linkBack>
</generalInfo>
<candidate>
<candidateId>9026</candidateId>

<fecId></fecId>
<photo>http://votesmart.org/canphoto/9026.JPG</photo>
<firstName>Stephen</firstName>
<nickName>Steve</nickName>
<middleName>J.</middleName>
<lastName>Scalise</lastName>

<suffix></suffix>
<birthDate>10/06/1965</birthDate>
<birthPlace></birthPlace>
<pronunciation></pronunciation>
<gender>Male</gender>
[...]
</candidate>
<generalInfo>
<title>Project Vote Smart - Bio - Rep. Stephen Scalise</title>
<linkBack>http://votesmart.org/bio.php?can_id=9026</linkBack>
</generalInfo>
<candidate>
<candidateId>9026</candidateId>
<fecId></fecId>
<photo>http://votesmart.org/canphoto/9026.JPG</photo>
<firstName>Stephen</firstName>
<nickName>Steve</nickName>
<middleName>J.</middleName>
<lastName>Scalise</lastName>
<suffix></suffix>
<birthDate>10/06/1965</birthDate>
<birthPlace></birthPlace>
<pronunciation></pronunciation>
<gender>Male</gender>
[...]
</candidate>
</bio>

Let's say you wanted to get the candidateId of the candidate. You could simply access it like this::
Expand Down
124 changes: 0 additions & 124 deletions VoteSmart.php

This file was deleted.

12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ozzyogkush/php-votesmart",
"description": "A PHP library for accessing VoteSmart.org via their API.",
"keywords": ["votesmart", "php", "api"],
"license": "BSD",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {"VoteSmart\\" : "src/"}
}
}
19 changes: 19 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions config.php

This file was deleted.

Loading