├── .gitignore
├── composer.json
├── README.md
├── classes
├── Notification.php
├── Upload.php
├── Image.php
├── Album.php
├── Connect.php
├── Comment.php
├── Authorize.php
├── Message.php
├── Account.php
└── Gallery.php
├── Imgur.php
└── examples.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | /vendor/
3 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bndr/imgur-php-wrapper",
3 | "description": "Imgur API php client for easy usage",
4 | "version": "1.0.0",
5 | "license": "Apache-2.0",
6 | "authors": [
7 | {
8 | "name": "Vadim Kravcenko",
9 | "email": "vadim.kravcenko@gmail.com"
10 | }
11 | ],
12 |
13 | "autoload": {
14 | "psr-4": {
15 | "": "classes/"
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Imgur API PHP Wrapper 0.1
2 | =========================
3 | Easy to use php wrapper for imgur API. You can see example usages in examples.php
4 |
5 | Feel free to fork and contribute to the project.
6 |
7 | Setup
8 | =====
9 | ```
10 | composer require bndr/imgur-php-wrapper
11 | ```
12 |
13 | Notes
14 | =====
15 | This is a work in progress. There might be bugs.
16 |
17 | Changelog
18 | =========
19 | 0.1 Initial release
20 |
--------------------------------------------------------------------------------
/classes/Notification.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
24 | $this->endpoint = $endpoint;
25 | }
26 |
27 | /**
28 | * Get all notifications. Either new or all notifications.
29 | * @param boolean $new
30 | * @return mixed
31 | */
32 | function all($new)
33 | {
34 | $uri = $this->endpoint . "/notification?new=" . ($new == true) ? "true" : "false";
35 | return $this->conn->request($uri);
36 | }
37 |
38 | /**
39 | * Get single notification data
40 | * @param string $id
41 | * @return mixed
42 | */
43 | function single($id)
44 | {
45 | $uri = $this->endpoint . "/notification/" . $id;
46 | return $this->conn->request($uri);
47 | }
48 |
49 | /**
50 | * Mark notification as read by id
51 | * @param string $id
52 | * @return mixed
53 | */
54 | function mark_as_read($id)
55 | {
56 | $uri = $this->endpoint . "/notification/" . $id;
57 | return $this->conn->request($uri, array("mark_as_read" => true), "PUT");
58 | }
59 |
60 |
61 | }
--------------------------------------------------------------------------------
/classes/Upload.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
31 | $this->endpoint = $endpoint;
32 | }
33 |
34 |
35 | /**
36 | * Upload a file
37 | * @param $filep
38 | * @param array $options
39 | */
40 | function file($filep, $options = array())
41 | {
42 | $uri = $this->endpoint . "/upload";
43 | $options['image'] = (function_exists('curl_file_create')) ? curl_file_create($filep) : '@'.$filep;
44 | return $this->conn->request($uri, $options, "POST");
45 | }
46 |
47 | /**
48 | * Upload a base64 encoded string
49 | * @param $base64
50 | * @param array $options
51 | */
52 | function string($base64, $options = array())
53 | {
54 | $uri = $this->endpoint . "/upload";
55 | $options['image'] = $base64;
56 | return $this->conn->request($uri, $options, "POST");
57 | }
58 |
59 | /**
60 | * Upload file from url
61 | * @param $url
62 | * @param array $options
63 | */
64 | function url($url, $options = array())
65 | {
66 | $uri = $this->endpoint . "/upload";
67 | $options['image'] = $url;
68 | return $this->conn->request($uri, $options, "POST");
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/classes/Image.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
34 | $this->endpoint = $endpoint;
35 | $this->id = $id;
36 | }
37 |
38 | /**
39 | * Get message by id
40 | * @return mixed
41 | */
42 | function get()
43 | {
44 |
45 | $uri = $this->endpoint . "/image/" . $this->id;
46 | return $this->conn->request($uri);
47 |
48 | }
49 |
50 | /**
51 | * Update message by id
52 | * @param $options
53 | * @return mixed
54 | */
55 | function update($options)
56 | {
57 | $uri = $this->endpoint . "/image/" . $this->id;
58 | return $this->conn->request($uri, $options, "PUT");
59 | }
60 |
61 | /**
62 | * Delete message by id
63 | * @return mixed
64 | */
65 | function delete()
66 | {
67 | $uri = $this->endpoint . "/image/" . $this->id;
68 | return $this->conn->request($uri, array("delete" => true), "DELETE");
69 | }
70 |
71 | /**
72 | * Favorite message by id
73 | * @return mixed
74 | */
75 | function favorite()
76 | {
77 | $uri = $this->endpoint . "/image/" . $this->id . "/favorite";
78 | return $this->conn->request($uri, array('favorite' => true), "POST");
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/classes/Album.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
30 | $this->endpoint = $endpoint;
31 | $this->id = $id;
32 | }
33 |
34 | /**
35 | * Get Album by id
36 | * @return mixed
37 | */
38 | function get()
39 | {
40 | $uri = $this->endpoint . "/album/" . $this->id;
41 | return $this->conn->request($uri);
42 | }
43 |
44 | /**
45 | * Get images from album
46 | * @return mixed
47 | */
48 | function images()
49 | {
50 | $uri = $this->endpoint . "/album/" . $this->id . "/images";
51 | return $this->conn->request($uri);
52 | }
53 |
54 | /**
55 | * Create Album
56 | * @param $options
57 | * @return mixed
58 | */
59 | function create($options)
60 | {
61 | $uri = $this->endpoint . "/album/" . $this->id;
62 | return $this->conn->request($uri, $options, "POST");
63 | }
64 |
65 | /**
66 | * Delete album
67 | * @return mixed
68 | */
69 | function delete()
70 | {
71 | $uri = $this->endpoint . "/album/" . $this->id;
72 | return $this->conn->request($uri, array("delete" => true), "DELETE");
73 | }
74 |
75 | /**
76 | * Update album information
77 | * @param $options
78 | * @return mixed
79 | */
80 | function update($options)
81 | {
82 | $uri = $this->endpoint . "/album/" . $this->id;
83 | return $this->conn->request($uri, $options, "PUT");
84 | }
85 |
86 | /**
87 | * Favorite an album
88 | * @return mixed
89 | */
90 | function favorite()
91 | {
92 | $uri = $this->endpoint . "/album/" . $this->id . "/favorite";
93 | return $this->conn->request($uri, array("favorite" => true), "POST");
94 | }
95 |
96 | /**
97 | * Add images to album
98 | * @param $ids_array
99 | * @return mixed
100 | */
101 | function add_images($ids_array)
102 | {
103 | $uri = $this->endpoint . "/album/" . $this->id;
104 | return $this->conn->request($uri, $ids_array, "POST");
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/classes/Connect.php:
--------------------------------------------------------------------------------
1 | api_key = $api_key;
51 | $this->api_secret = $api_secret;
52 | }
53 |
54 | /**
55 | * Set Access Data. Used for authorization
56 | * @param $accessToken
57 | * @param $refreshToken
58 | */
59 | function setAccessData($accessToken, $refreshToken)
60 | {
61 | $this->access_token = $accessToken;
62 | $this->refresh_token = $refreshToken;
63 | }
64 |
65 | /**
66 | * Make request to Imgur API endpoint
67 | * @param $endpoint
68 | * @param mixed $options
69 | * @param string $type
70 | * @return mixed
71 | * @throws Exception
72 | */
73 | function request($endpoint, $options = FALSE, $type = "GET")
74 | {
75 | $headers = (!$this->access_token) ? array('Authorization: CLIENT-ID ' . $this->api_key) : array("Authorization: Bearer " . $this->access_token);
76 |
77 | $ch = curl_init();
78 | curl_setopt($ch, CURLOPT_URL, $endpoint);
79 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
80 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
81 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
82 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
83 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
84 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
85 | if ($options) {
86 | curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
87 | }
88 | if (($data = curl_exec($ch)) === FALSE) {
89 | throw new Exception(curl_error($ch));
90 | }
91 |
92 | curl_close($ch);
93 | return json_decode($data, true);
94 |
95 | }
96 |
97 | }
98 |
99 |
100 |
--------------------------------------------------------------------------------
/classes/Comment.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
30 | $this->endpoint = $endpoint;
31 | $this->id = ($id) ? $id : "";
32 | }
33 |
34 | /**
35 | * Get comment by id
36 | * @return mixed
37 | */
38 | function get()
39 | {
40 | $uri = $this->endpoint . "/comment/" . $this->id;
41 | return $this->conn->request($uri);
42 | }
43 |
44 | /**
45 | * Create new comment
46 | * @param $options
47 | * @return mixed
48 | */
49 | function create($options)
50 | {
51 | $uri = $this->endpoint . "/comment/" . $this->id;
52 | return $this->conn->request($uri, $options, "POST");
53 |
54 | }
55 |
56 | /**
57 | * Delete comment
58 | * @return mixed
59 | */
60 | function delete()
61 | {
62 |
63 | $uri = $this->endpoint . "/comment/" . $this->id;
64 | return $this->conn->request($uri, array("delete" => true), "DELETE");
65 |
66 | }
67 |
68 | /**
69 | * Get all replies to comment with id
70 | * @return mixed
71 | */
72 | function replies()
73 | {
74 | $uri = $this->endpoint . "/comment/" . $this->id . "/replies";
75 | return $this->conn->request($uri);
76 |
77 | }
78 |
79 | /**
80 | * Vote on comment. Up or Down
81 | * @param $type
82 | * @return mixed
83 | */
84 | function vote($type)
85 | {
86 | $uri = $this->endpoint . "/comment/" . $this->id . "/vote/" . $type;
87 | return $this->conn->request($uri, array('vote' => true), "POST");
88 | }
89 |
90 | /**
91 | * Report comment
92 | * @return mixed
93 | */
94 | function report()
95 | {
96 | $uri = $this->endpoint . "/comment/" . $this->id . "/report/";
97 | return $this->conn->request($uri, array('report' => true), "POST");
98 | }
99 |
100 | /**
101 | * Create a reply to a comment
102 | * @param $options
103 | * @return mixed
104 | */
105 | function reply_create($options)
106 | {
107 | $uri = $this->endpoint . "/comment/" . $this->id;
108 | return $this->conn->request($uri, $options, "POST");
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/classes/Authorize.php:
--------------------------------------------------------------------------------
1 | api_key = $key;
45 | $this->api_secret = $secret;
46 | $this->conn = $conn;
47 | }
48 |
49 | /**
50 | * Set Access data for future uses.
51 | * @param $accessToken
52 | * @param $refreshToken
53 | */
54 | function setAccessData($accessToken, $refreshToken)
55 | {
56 | $this->access_token = $accessToken;
57 | $this->refresh_token = $refreshToken;
58 | }
59 |
60 | /**
61 | * Exchange authorization code for an access token
62 | * @param string $code
63 | * @return Array $response
64 | */
65 | function getAccessToken($code)
66 | {
67 | $uri = $this->oauth . "/token/";
68 | $options = array(
69 | 'client_id' => $this->api_key,
70 | 'client_secret' => $this->api_secret,
71 | 'grant_type' => 'authorization_code',
72 | 'code' => $code
73 | );
74 | $response = ($code) ? $this->conn->request($uri, $options, "POST") : null;
75 |
76 | return $response;
77 | }
78 |
79 | /**
80 | * Exchange the refresh token for access token
81 | * @param string $refresh_token
82 | * @return Array $response
83 | */
84 | function refreshAccessToken($refresh_token)
85 | {
86 |
87 | $uri = $this->oauth . "/token/";
88 | $options = array(
89 | 'client_id' => $this->api_key,
90 | 'client_secret' => $this->api_secret,
91 | 'grant_type' => 'refresh_token',
92 | 'refresh_token' => $refresh_token
93 | );
94 |
95 | $response = ($refresh_token) ? $this->conn->request($uri, $options, "POST") : null;
96 |
97 | return $response;
98 | }
99 |
100 | /**
101 | * Show the authorization page to the user
102 | */
103 | function getAuthorizationCode()
104 | {
105 | $uri = $this->oauth . "/authorize/" . "?client_id=" . $this->api_key . "&response_type=code&state=initializing";
106 |
107 | echo "
108 | Click this link to authorize the application to access your Imgur data
109 | ";
110 |
111 | exit;
112 |
113 | }
114 |
115 | }
116 |
117 |
--------------------------------------------------------------------------------
/classes/Message.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
27 | $this->endpoint = $endpoint;
28 | }
29 |
30 |
31 | /**
32 | * Get first messages from ALL conversations
33 | * @return mixed
34 | */
35 | function messages()
36 | {
37 | $uri = $this->endpoint . "/messages/";
38 | return $this->conn->request($uri);
39 | }
40 |
41 | /**
42 | * Get single message by id
43 | * @param string $id
44 | * @return mixed
45 | */
46 | function single($id)
47 | {
48 | $uri = $this->endpoint . "/message/" . $id;
49 | return $this->conn->request($uri);
50 | }
51 |
52 | /**
53 | * Get messages IDs
54 | * @param int $page
55 | * @return mixed
56 | */
57 | function messages_ids($page = 0)
58 | {
59 | $uri = $this->endpoint . "/messages/ids/" . $page;
60 | return $this->conn->request($uri);
61 | }
62 |
63 | /**
64 | * Get messages count
65 | * @return mixed
66 | */
67 | function message_count()
68 | {
69 | $uri = $this->endpoint . "/messages/count";
70 | return $this->conn->request($uri);
71 |
72 | }
73 |
74 | /**
75 | * Get a conversation thread
76 | * @param string $id
77 | * @return mixed
78 | */
79 | function get_thread($id)
80 | {
81 | $uri = $this->endpoint . "/message/" . $id . "/thread";
82 | return $this->conn->request($uri);
83 |
84 | }
85 |
86 | /**
87 | * Create a new mesage
88 | * @param array $options
89 | * @return mixed
90 | */
91 | function create($options)
92 | {
93 | $uri = $this->endpoint . "/message/";
94 | return $this->conn->request($uri, $options, "POST");
95 | }
96 |
97 | /**
98 | * Delete a message
99 | * @param string $id
100 | * @return mixed
101 | */
102 | function delete($id)
103 | {
104 | $uri = $this->endpoint . "/message/" . $id;
105 | return $this->conn->request($uri, array("delete" => true), "DELETE");
106 | }
107 |
108 | /**
109 | * Report the sender
110 | * @param string $username
111 | * @return mixed
112 | */
113 | function report_sender($username)
114 | {
115 | $uri = $this->endpoint . "/message/report/" . $username;
116 | return $this->conn->request($uri, array("report" => true), "POST");
117 | }
118 |
119 | /**
120 | * Block sender
121 | * @param string $username
122 | * @return mixed
123 | */
124 | function block_sender($username)
125 | {
126 | $uri = $this->endpoint . "/message/block/" . $username;
127 | return $this->conn->request($uri, array("block" => true), "POST");
128 | }
129 |
130 |
131 | }
--------------------------------------------------------------------------------
/Imgur.php:
--------------------------------------------------------------------------------
1 | api_key = $api_key;
47 | $this->api_secret = $api_secret;
48 | $this->conn = new Connect($this->api_key, $this->api_secret);
49 | }
50 |
51 | /**
52 | * oAuth2 authorization. If the acess_token needs to be refreshed pass $refresh_token as first parameter,
53 | * if this is the first time getting access_token from user, then set the first parameter to false, pass the auth code
54 | * in the second.
55 | * @param bool $refresh_token
56 | * @param bool $auth_code
57 | * @return array $tokens
58 | */
59 | function authorize($refresh_token = FALSE, $auth_code = FALSE)
60 | {
61 | $auth = new Authorize($this->conn, $this->api_key, $this->api_secret);
62 | $tokens = ($refresh_token) ? $auth->refreshAccessToken($refresh_token) : $auth->getAccessToken($auth_code);
63 | (!$tokens) ? $auth->getAuthorizationCode() : $this->conn->setAccessData($tokens['access_token'], $tokens['refresh_token']);
64 |
65 | return $tokens;
66 |
67 | }
68 |
69 | /**
70 | * Upload an image from url, bas64 string or file.
71 | * @return mixed
72 | */
73 | function upload()
74 | {
75 | $upload = new Upload($this->conn, $this->api_endpoint);
76 | return $upload;
77 | }
78 |
79 | /**
80 | * Image Wrapper for all image functions
81 | * @param string $id
82 | * @return Image
83 | */
84 | function image($id = null)
85 | {
86 | $image = new Image($id, $this->conn, $this->api_endpoint);
87 | return $image;
88 | }
89 |
90 | /**
91 | * Album wrapper for all album functions.
92 | * @param string $id
93 | * @return Album
94 | */
95 | function album($id = null)
96 | {
97 | $album = new Album($id, $this->conn, $this->api_endpoint);
98 | return $album;
99 | }
100 |
101 | /**
102 | * Account wrapper for all account functions
103 | * @param string $username
104 | * @return Account
105 | */
106 | function account($username)
107 | {
108 | $acc = new Account($username, $this->conn, $this->api_endpoint);
109 | return $acc;
110 | }
111 |
112 | /**
113 | * Gallery wrapper for all functions regarding gallery
114 | * @return Gallery
115 | */
116 | function gallery()
117 | {
118 | $gallery = new Gallery($this->conn, $this->api_endpoint);
119 | return $gallery;
120 | }
121 |
122 | /**
123 | * Comment wrapper for all commenting functions
124 | * @param string $id
125 | * @return Comment
126 | */
127 | function comment($id)
128 | {
129 | $comment = new Comment($id, $this->conn, $this->api_endpoint);
130 | return $comment;
131 | }
132 |
133 | /**
134 | * Messages wrapper
135 | * @return Message
136 | */
137 | function message()
138 | {
139 | $msg = new Message($this->conn, $this->api_endpoint);
140 | return $msg;
141 | }
142 |
143 | /**
144 | * Notifications wrapper
145 | * @return mixed
146 | */
147 | function notification()
148 | {
149 | $notification = new Notification($this->conn, $this->api_endpoint);
150 | return $notification;
151 | }
152 |
153 | }
154 |
--------------------------------------------------------------------------------
/examples.php:
--------------------------------------------------------------------------------
1 | authorize(false, $_GET['code']); //First parameter is for refresh_tokens
26 | //The user is authorized. You can save the $tokens['refresh_token'] and $tokens['access_token'] for future use;
27 | } else {
28 | // GET parameter doesn't exist, so we will have to ask user to allow access for our application
29 | $imgur->authorize();
30 | }
31 | /*-----------------------------------------------------------------------------------*/
32 | /* Account
33 | /*-----------------------------------------------------------------------------------*/
34 |
35 | $imgur->account("username")->basic();
36 | $imgur->account("username")->albums($page = 0);
37 | $imgur->account("username")->images($page = 0);
38 | $imgur->account("new_username")->create($options); //$options will be used as post fields. For more info go to Imgur API Docs.
39 | //....
40 |
41 | /*-----------------------------------------------------------------------------------*/
42 | /* Images
43 | /*-----------------------------------------------------------------------------------*/
44 |
45 | $imgur->image("image_id")->get();
46 | $imgur->image("image_id")->delete();
47 | $imgur->image('image_id')->update($options);
48 | $imgur->image("image_id")->favorite();
49 | //....
50 |
51 | /*-----------------------------------------------------------------------------------*/
52 | /* Comments
53 | /*-----------------------------------------------------------------------------------*/
54 |
55 | $imgur->comment("comment_id")->get();
56 | $imgur->comment("comment_id")->delete();
57 | $imgur->comment("comment_id")->report();
58 | $imgur->comment("comment_id")->vote($type); // "up" or "down";
59 | $imgur->comment("comment_id")->replies();
60 | $imgur->comment("comment_id")->reply_create($options);
61 | //....
62 |
63 | /*-----------------------------------------------------------------------------------*/
64 | /* Messages (User must be logged in);
65 | /*-----------------------------------------------------------------------------------*/
66 |
67 | $imgur->message()->messages();
68 | $imgur->message()->single($id);
69 | $imgur->message()->create($options);
70 | $imgur->message()->delete($id);
71 | $imgur->message()->message_count();
72 | $imgur->message()->get_thread($id);
73 | //...
74 |
75 | /*-----------------------------------------------------------------------------------*/
76 | /* Gallery
77 | /*-----------------------------------------------------------------------------------*/
78 |
79 | $imgur->gallery()->get($section, $sort, $page); //More on the parameters at Imgur API docs
80 | $imgur->gallery()->comments($id, $type); //$type = "image" | "album";
81 | $imgur->gallery()->search($str);
82 | $imgur->gallery()->remove($id);
83 | $imgur->gallery()->submit($id, $options, $type);
84 | $imgur->gallery()->votes($id, $type);
85 | $imgur->gallery()->vote($id, $type, $vote);
86 | //...
87 |
88 | /*-----------------------------------------------------------------------------------*/
89 | /* Uploading
90 | /*-----------------------------------------------------------------------------------*/
91 |
92 | $imgur->upload()->file("/path/to/file", $postfields); //Postfields look in http://api.imgur.com/endpoints/image#image-upload
93 | $imgur->upload()->string("base64encodedstring,$postfields");
94 | $imgur->upload()->url("http://urlofimage.com", $postfields);
95 |
96 |
97 | /*-----------------------------------------------------------------------------------*/
98 | /* Notifications
99 | /*-----------------------------------------------------------------------------------*/
100 |
101 | $imgur->notification()->all();
102 | $imgur->notification()->single($id);
103 | $imgur->notification()->mark_as_read($id);
104 |
--------------------------------------------------------------------------------
/classes/Account.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
27 | $this->endpoint = $endpoint;
28 | $this->username = $username;
29 | }
30 |
31 | /**
32 | * Get basic information about the user
33 | * @return mixed
34 | */
35 | function basic()
36 | {
37 | $uri = $this->endpoint . "/account/" . $this->username;
38 | return $this->conn->request($uri);
39 | }
40 |
41 | /**
42 | * Create user. $options are used as post_fields
43 | * @param array $options
44 | * @return array mixed
45 | */
46 | function create($options)
47 | {
48 | $uri = $this->endpoint . "/account/" . $this->username;
49 | return $this->conn->request($uri, $options, "POST");
50 | }
51 |
52 | /**
53 | * @return mixed
54 | */
55 | function delete()
56 | {
57 | $uri = $this->endpoint . "/account/" . $this->username;
58 | return $this->conn->request($uri, array("delete" => true), "DELETE");
59 | }
60 |
61 | /**
62 | * @param $type
63 | * @return mixed
64 | */
65 | function favorites($type)
66 | {
67 | $uri = $this->endpoint . "/account/" . $this->username . ($type == 'gallery' ? "/gallery_favorites" : "/favorites");
68 | return $this->conn->request($uri);
69 | }
70 |
71 | /**
72 | * @param int $page
73 | * @return mixed
74 | */
75 | function submissions($page = 0)
76 | {
77 | $uri = $this->endpoint . "/account/" . $this->username . "/submissions/" . $page;
78 | return $this->conn->request($uri);
79 | }
80 |
81 | /**
82 | * @param bool $options
83 | * @return mixed
84 | */
85 | function settings($options = FALSE)
86 | {
87 | $uri = $this->endpoint . "/account/" . $this->username . "/settings";
88 | return $this->conn->request($uri, $options, ($options == FALSE) ? "GET" : "POST");
89 | }
90 |
91 | /**
92 | * @return mixed
93 | */
94 | function stats()
95 | {
96 | $uri = $this->endpoint . "/account/" . $this->username . "/stats";
97 | return $this->conn->request($uri);
98 | }
99 |
100 | /**
101 | * @param int $page
102 | * @return mixed
103 | */
104 | function albums($page = 0)
105 | {
106 | $uri = $this->endpoint . "/account/" . $this->username . "/albums/" . $page;
107 | return $this->conn->request($uri);
108 | }
109 |
110 | /**
111 | * @param int $page
112 | * @return mixed
113 | */
114 | function images($page = 0)
115 | {
116 | $uri = $this->endpoint . "/account/" . $this->username . "/images/" . $page;
117 | return $this->conn->request($uri);
118 | }
119 |
120 | /**
121 | * @param $new
122 | * @return mixed
123 | */
124 | function notifications($new)
125 | {
126 | $uri = $this->endpoint . "/account/" . $this->username . "/notifications?new=" . ($new == true) ? "true" : "false";
127 | return $this->conn->request($uri);
128 | }
129 |
130 | /**
131 | * @param $new
132 | * @return mixed
133 | */
134 | function messages($new)
135 | {
136 | $uri = $this->endpoint . "/account/" . $this->username . "/notifications/messages?new=" . ($new == true) ? "true" : "false";
137 | return $this->conn->request($uri);
138 | }
139 |
140 | /**
141 | * @param $options
142 | * @return mixed
143 | */
144 | function send_message($options)
145 | {
146 | $uri = $this->endpoint . "/account/" . $this->username . "/message";
147 | return $this->conn->request($uri, $options, "POST");
148 | }
149 |
150 | /**
151 | * @param $new
152 | * @return mixed
153 | */
154 | function replies($new)
155 | {
156 | $uri = $this->endpoint . "/account/" . $this->username . "/notifications/replies?new=" . ($new == true) ? "true" : "false";
157 | return $this->conn->request($uri);
158 | }
159 |
160 |
161 | }
162 |
163 |
--------------------------------------------------------------------------------
/classes/Gallery.php:
--------------------------------------------------------------------------------
1 | conn = $connection;
26 | $this->endpoint = $endpoint;
27 | }
28 |
29 | /**
30 | * Get data from gallery
31 | *
32 | * @param string $section hot | top | user - defaults to hot
33 | * @param string $sort viral | time - defaults to viral
34 | * @param int $page integer - the data paging number
35 | * @return mixed
36 | */
37 | function get($section, $sort, $page)
38 | {
39 | $uri = $this->endpoint . "/gallery/" . $section . "/" . $sort . "/" . $page;
40 | return $this->conn->request($uri);
41 | }
42 |
43 | /**
44 | * Get subreddit gallery
45 | * @param $subreddit
46 | * @param $sort
47 | * @param $page
48 | * @param bool $window
49 | * @return mixed
50 | */
51 | function subreddit_gallery($subreddit, $sort, $page, $window = false)
52 | {
53 | $uri = $this->endpoint . "/gallery/r/" . $subreddit . "/" . $sort . ($window !== false ? "/" . $window : "") . "/" . $page;
54 | return $this->conn->request($uri);
55 | }
56 |
57 | /**
58 | * Get subreddit image
59 | * @param $subreddit
60 | * @param $id
61 | * @return mixed
62 | */
63 | function subreddit_image($subreddit, $id)
64 | {
65 | $uri = $this->endpoint . "/gallery/r/" . $subreddit . "/" . $id;
66 | return $this->conn->request($uri);
67 | }
68 |
69 | /**
70 | * Search for a string in gallery
71 | * @param string $str
72 | * @return mixed
73 | */
74 | function search($str)
75 | {
76 | $uri = $this->endpoint . "/gallery/search?q=" . $str;
77 | return $this->conn->request($uri);
78 | }
79 |
80 | /**
81 | * Get random images from gallery. Pagination is available
82 | * @param int $page
83 | * @return mixed
84 | */
85 | function random($page = 0)
86 | {
87 | $uri = $this->endpoint . "/gallery/random/random/" . $page;
88 | return $this->conn->request($uri);
89 | }
90 |
91 | /**
92 | * Submit Image | Album to gallery
93 | * @param string $id
94 | * @param $options
95 | * @param string $type
96 | * @return mixed
97 | */
98 | function submit($id, $options, $type = "image")
99 | {
100 | $uri = $this->endpoint . "/gallery/" . $type . "/" . $id;
101 | return $this->conn->request($uri, $options, "POST");
102 | }
103 |
104 | /**
105 | * Remove image from gallery
106 | * @param string $id
107 | * @return mixed
108 | */
109 | function remove($id)
110 | {
111 | $uri = $this->endpoint . "/gallery/" . $id;
112 | return $this->conn->request($uri, array("remove" => true), "DELETE");
113 | }
114 |
115 | /**
116 | * Get album information in gallery
117 | * @param string $id
118 | * @return mixed
119 | */
120 | function album_info($id)
121 | {
122 | $uri = $this->endpoint . "/gallery/album/" . $id;
123 | return $this->conn->request($uri);
124 | }
125 |
126 | /**
127 | * Get Image information in gallery
128 | * @param string $id
129 | * @return mixed
130 | */
131 | function image_info($id)
132 | {
133 | $uri = $this->endpoint . "/gallery/image/" . $id;
134 | return $this->conn->request($uri);
135 | }
136 |
137 | /**
138 | * Report Image | Album
139 | * @param string $id
140 | * @param string $type
141 | * @return mixed
142 | */
143 | function report($id, $type = "image")
144 | {
145 | $uri = $this->endpoint . "/gallery/" . $type . "/" . $id . "/report";
146 | return $this->conn->request($uri, array("report" => true), "POST");
147 |
148 | }
149 |
150 | /**
151 | * Get votes for Image | Album
152 | * @param string $id
153 | * @param string $type
154 | * @return mixed
155 | */
156 | function votes($id, $type = "image")
157 | {
158 | $uri = $this->endpoint . "/gallery/" . $type . "/" . $id . "/votes";
159 | return $this->conn->request($uri);
160 | }
161 |
162 |
163 | /**
164 | * Vote on Image | ALbum. Votes can be either up or down.
165 | * @param string $id
166 | * @param string $type
167 | * @param string $vote
168 | * @return mixed
169 | */
170 | function vote($id, $type = "image", $vote = "up")
171 | {
172 | $uri = $this->endpoint . "/gallery/" . $type . "/" . $id . "/vote/" . $vote;
173 | return $this->conn->request($uri, array("vote" => true), "POST");
174 | }
175 |
176 | /**
177 | * Get comments for Image | Album
178 | * @param string $id
179 | * @param string $type
180 | * @return mixed
181 | */
182 | function comments($id, $type)
183 | {
184 | $uri = $this->endpoint . "/gallery/" . $type . "/" . $id . "/comments";
185 | return $this->conn->request($uri);
186 | }
187 |
188 | /**
189 | * Get a comment to an image in gallery
190 | * @param $image_id
191 | * @param $type
192 | * @param $comment_id
193 | * @return mixed
194 | */
195 | function comment($image_id, $type, $comment_id)
196 | {
197 | $uri = $this->endpoint . "/gallery/" . $type . "/" . $image_id . "/comment/" . $comment_id;
198 | return $this->conn->request($uri);
199 | }
200 | }
201 |
202 |
--------------------------------------------------------------------------------