-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathImage.php
103 lines (93 loc) · 2.92 KB
/
Image.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Imgur\Api;
use Imgur\Exception\InvalidArgumentException;
use Imgur\Exception\MissingArgumentException;
/**
* CRUD for Images.
*
* @see https://api.imgur.com/endpoints/image
*
* @author Adrian Ghiuta <adrian.ghiuta@gmail.com>
*/
class Image extends AbstractApi
{
/**
* Get information about an image.
*
* @param string $imageId
*
* @see https://api.imgur.com/endpoints/image#image
*
* @return array (@see https://api.imgur.com/models/image)
*/
public function image($imageId)
{
return $this->get('image/' . $imageId);
}
/**
* Upload a new image.
*
* @param array $data
*
* @see https://api.imgur.com/endpoints/image#image-upload
*
* @return array (@see https://api.imgur.com/models/basic)
*/
public function upload($data)
{
if (!isset($data['image'])) {
throw new MissingArgumentException(['image']);
}
$typeValues = ['file', 'base64', 'url'];
if (isset($data['type']) && !\in_array(strtolower($data['type']), $typeValues, true)) {
throw new InvalidArgumentException('Type parameter "' . $data['type'] . '" is wrong. Possible values are: ' . implode(', ', $typeValues));
}
if ('file' === $data['type']) {
$data['image'] = fopen($data['image'], 'r');
}
return $this->post('image', $data);
}
/**
* Deletes an image. For an anonymous image, $imageIdOrDeleteHash must be the image's deletehash.
* If the image belongs to your account then passing the ID of the image is sufficient.
*
* @param string $imageIdOrDeleteHash
*
* @see https://api.imgur.com/endpoints/image#image-delete
*
* @return array (@see https://api.imgur.com/models/basic)
*/
public function deleteImage($imageIdOrDeleteHash)
{
return $this->delete('image/' . $imageIdOrDeleteHash);
}
/**
* Updates the title or description of an image.
* You can only update an image you own and is associated with your account.
* For an anonymous image, {id} must be the image's deletehash.
*
* @param string $imageIdOrDeleteHash
* @param array $data
*
* @see https://api.imgur.com/endpoints/image#image-update
*
* @return array (@see https://api.imgur.com/models/basic)
*/
public function update($imageIdOrDeleteHash, $data)
{
return $this->post('image/' . $imageIdOrDeleteHash, $data);
}
/**
* Favorite an image with the given ID. The user is required to be logged in to favorite the image.
*
* @param string $imageIdOrDeleteHash
*
* @see https://api.imgur.com/endpoints/image#image-favorite
*
* @return array (@see https://api.imgur.com/models/basic)
*/
public function favorite($imageIdOrDeleteHash)
{
return $this->post('image/' . $imageIdOrDeleteHash . '/favorite');
}
}