-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path500px.php
executable file
·80 lines (62 loc) · 1.7 KB
/
500px.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* 500px the easy way
*
* @requires php_curl
* @see https://github.com/500px/api-documentation
*
* @author Hugo Osorio @hugovom <https://github.com/hugovom>
* @based on https://github.com/GobiernoFacil/bbva/blob/master/BBVA.php
*
*/
class PICS {
/*
* config data
* -------------------------------------------------------------
*/
// ENDPOINTS
const PHOTO_ENDPOINT = "https://api.500px.com/v1/photos";
// CREDENTIALS
public $app_id;
public $key;
// MORE STUFF
public $ch;
/*
* constructor
* -------------------------------------------------------------
*/
function __construct($consumer_key, $consumer_secret){
$this->consumer_key = $consumer_key;
$this->consumer_secret = $consumer_secret;
}
/**
* base functions
* -------------------------------------------------------------
*/
public function get_user(){
// Params for the Photo
$apiParams = array (
'feature' => 'user',
'username' => 'your_user_name',
'rpp' => 60,
'consumer_key' => $this->consumer_key
);
return $this->make_conn(self::PHOTO_ENDPOINT, $apiParams);
}
/*
* helpers
* -------------------------------------------------------------
*/
private function make_conn($url, $params){
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// set the params, if avaliable
$url = empty($params) ? $url : $url . '?' . http_build_query($params);
curl_setopt($this->ch, CURLOPT_URL, $url);
// finish the thing
$response = curl_exec($this->ch);
curl_close($this->ch);
return $response;
}
}