forked from mablerf/php-openstates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurl.php
48 lines (41 loc) · 1.02 KB
/
Curl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* PHP Curl Class to interact with the Open State Project
* Author: Nikki Snow
* Version: 0.01
* http://nikkisnow.com/code/php-openstate
* License: http://opensource.org/licenses/gpl-3.0.html
*
* The Open State Project provides data on state legislative activities,
* including bill summaries, votes, sponsorships and state legislator
* information.
*
*/
class Curl
{
public function get( $url, $params=NULL ) {
if( $params ) {
$param = '';
foreach( $params as $key => $value ) {
$value = preg_replace( '/ /', '+', $value );
$param .= $key.'='.$value.'&';
}
$url = $url.'?'.substr($param, 0, -1);
}
$ch = $this->open();
curl_setopt($ch, CURLOPT_URL, $url );
$contents = curl_exec( $ch );
$this->close( $ch );
return $contents;
}
private function open() {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return $ch;
}
private function close( $ch ) {
return curl_close( $ch ) ? TRUE : FALSE;
}
}
?>