1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace keika299\ConohaAPI\Image; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use keika299\ConohaAPI\Common\Network\Request; |
7
|
|
|
use keika299\ConohaAPI\Common\Service\AbstractService; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Service |
11
|
|
|
* |
12
|
|
|
* This class connect to ConoHa image service. |
13
|
|
|
* |
14
|
|
|
* @package keika299\ConohaAPI\Image |
15
|
|
|
*/ |
16
|
|
|
class Service extends AbstractService |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get image list. |
21
|
|
|
* |
22
|
|
|
* See https://www.conoha.jp/docs/image-get_images_list.html |
23
|
|
|
* |
24
|
|
|
* @param array $options |
25
|
|
|
* @return mixed |
26
|
|
|
*/ |
27
|
1 |
|
public function getImageList($options = array()) |
28
|
|
|
{ |
29
|
1 |
|
$request = (new Request()) |
30
|
1 |
|
->setMethod('GET') |
31
|
1 |
|
->setBaseURI($this->baseURI) |
32
|
1 |
|
->setURI('/v2/images') |
33
|
1 |
|
->setQuery($options) |
34
|
1 |
|
->setAccept('application/json') |
35
|
1 |
|
->setToken($this->token->getToken()); |
36
|
|
|
|
37
|
1 |
|
$response = $request->exec(); |
38
|
1 |
|
return $response->getJson(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get image information. |
43
|
|
|
* |
44
|
|
|
* See https://www.conoha.jp/docs/image-get_images_detail_specified.html |
45
|
|
|
* |
46
|
|
|
* @param string $imageId |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
1 |
|
public function getImageInfo($imageId) |
50
|
|
|
{ |
51
|
1 |
|
$request = (new Request()) |
52
|
1 |
|
->setMethod('GET') |
53
|
1 |
|
->setBaseURI($this->baseURI) |
54
|
1 |
|
->setURI('/v2/images/' . $imageId) |
55
|
1 |
|
->setAccept('application/json') |
56
|
1 |
|
->setToken($this->token->getToken()); |
57
|
|
|
|
58
|
1 |
|
$response = $request->exec(); |
59
|
1 |
|
return $response->getJson(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get images schema. |
64
|
|
|
* |
65
|
|
|
* See https://www.conoha.jp/docs/image-get_schemas_images_list.html |
66
|
|
|
* |
67
|
|
|
* Get Images schema |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
1 |
|
public function getImagesSchema() |
71
|
|
|
{ |
72
|
1 |
|
$request = (new Request()) |
73
|
1 |
|
->setMethod('GET') |
74
|
1 |
|
->setBaseURI($this->baseURI) |
75
|
1 |
|
->setURI('/v2/schemas/images') |
76
|
1 |
|
->setAccept('application/json') |
77
|
1 |
|
->setToken($this->token->getToken()); |
78
|
|
|
|
79
|
1 |
|
$response = $request->exec(); |
80
|
1 |
|
return $response->getJson(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get image schema |
85
|
|
|
* |
86
|
|
|
* See https://www.conoha.jp/docs/image-get_schemas_image_list.html |
87
|
|
|
* |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
1 |
|
public function getImageSchema() |
91
|
|
|
{ |
92
|
1 |
|
$request = (new Request()) |
93
|
1 |
|
->setMethod('GET') |
94
|
1 |
|
->setBaseURI($this->baseURI) |
95
|
1 |
|
->setURI('/v2/schemas/image') |
96
|
1 |
|
->setAccept('application/json') |
97
|
1 |
|
->setToken($this->token->getToken()); |
98
|
|
|
|
99
|
1 |
|
$response = $request->exec(); |
100
|
1 |
|
return $response->getJson(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get members schema. |
105
|
|
|
* |
106
|
|
|
* See https://www.conoha.jp/docs/image-get_schemas_members_list.html |
107
|
|
|
* |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
1 |
|
public function getMembersSchema() |
111
|
|
|
{ |
112
|
1 |
|
$request = (new Request()) |
113
|
1 |
|
->setMethod('GET') |
114
|
1 |
|
->setBaseURI($this->baseURI) |
115
|
1 |
|
->setURI('/v2/schemas/members') |
116
|
1 |
|
->setAccept('application/json') |
117
|
1 |
|
->setToken($this->token->getToken()); |
118
|
|
|
|
119
|
1 |
|
$response = $request->exec(); |
120
|
1 |
|
return $response->getJson(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get member schema. |
125
|
|
|
* |
126
|
|
|
* See https://www.conoha.jp/docs/image-get_schemas_member_list.html |
127
|
|
|
* |
128
|
|
|
* @return mixed |
129
|
|
|
*/ |
130
|
1 |
|
public function getMemberSchema() |
131
|
|
|
{ |
132
|
1 |
|
$request = (new Request()) |
133
|
1 |
|
->setMethod('GET') |
134
|
1 |
|
->setBaseURI($this->baseURI) |
135
|
1 |
|
->setURI('/v2/schemas/member') |
136
|
1 |
|
->setAccept('application/json') |
137
|
1 |
|
->setToken($this->token->getToken()); |
138
|
|
|
|
139
|
1 |
|
$response = $request->exec(); |
140
|
1 |
|
return $response->getJson(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get member list. |
145
|
|
|
* |
146
|
|
|
* See https://www.conoha.jp/docs/image-get_members_list.html |
147
|
|
|
* |
148
|
|
|
* @param string $imageId |
149
|
|
|
* @return mixed |
150
|
|
|
*/ |
151
|
1 |
|
public function getMemberList($imageId) |
152
|
|
|
{ |
153
|
1 |
|
$request = (new Request()) |
154
|
1 |
|
->setMethod('GET') |
155
|
1 |
|
->setBaseURI($this->baseURI) |
156
|
1 |
|
->setURI('/v2/images/' . $imageId . '/members') |
157
|
1 |
|
->setAccept('application/json') |
158
|
1 |
|
->setToken($this->token->getToken()); |
159
|
|
|
|
160
|
1 |
|
$response = $request->exec(); |
161
|
1 |
|
return $response->getJson(); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Delete image. |
166
|
|
|
* |
167
|
|
|
* See https://www.conoha.jp/docs/image-remove_image.html |
168
|
|
|
* |
169
|
|
|
* @param string $imageId |
170
|
|
|
* @return null |
171
|
|
|
*/ |
172
|
1 |
|
public function deleteImage($imageId) |
173
|
|
|
{ |
174
|
1 |
|
$request = (new Request()) |
175
|
1 |
|
->setMethod('DELETE') |
176
|
1 |
|
->setBaseURI($this->baseURI) |
177
|
1 |
|
->setURI('/v2/images/' . $imageId) |
178
|
1 |
|
->setAccept('application/json') |
179
|
1 |
|
->setToken($this->token->getToken()); |
180
|
|
|
|
181
|
1 |
|
$request->exec(); |
182
|
1 |
|
return null; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Change quota. |
187
|
|
|
* |
188
|
|
|
* Now, only can apply about tokyo region. |
189
|
|
|
* |
190
|
|
|
* See https://www.conoha.jp/docs/image-set_quota.html |
191
|
|
|
* |
192
|
|
|
* @param int $size |
193
|
|
|
* @return mixed |
194
|
|
|
*/ |
195
|
1 |
|
public function putQuota($size) |
196
|
|
|
{ |
197
|
|
|
$optionsArray = array( |
198
|
|
|
'quota' => [ |
199
|
|
|
'tyo1_image_size' => $size . 'GB' |
200
|
1 |
|
] |
201
|
1 |
|
); |
202
|
|
|
|
203
|
1 |
|
$request = (new Request()) |
204
|
1 |
|
->setMethod('PUT') |
205
|
1 |
|
->setBaseURI($this->baseURI) |
206
|
1 |
|
->setURI('/v2/quota') |
207
|
1 |
|
->setAccept('application/json') |
208
|
1 |
|
->setToken($this->token->getToken()) |
209
|
1 |
|
->setJson($optionsArray); |
210
|
|
|
|
211
|
1 |
|
$response = $request->exec(); |
212
|
1 |
|
return $response->getJson(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get quota |
217
|
|
|
* |
218
|
|
|
* See https://www.conoha.jp/docs/image-get_quota.html |
219
|
|
|
* |
220
|
|
|
* @return mixed |
221
|
|
|
*/ |
222
|
1 |
|
public function getQuota() |
223
|
|
|
{ |
224
|
1 |
|
$request = (new Request()) |
225
|
1 |
|
->setMethod('GET') |
226
|
1 |
|
->setBaseURI($this->baseURI) |
227
|
1 |
|
->setURI('/v2/quota') |
228
|
1 |
|
->setAccept('application/json') |
229
|
1 |
|
->setToken($this->token->getToken()); |
230
|
|
|
|
231
|
1 |
|
$response = $request->exec(); |
232
|
1 |
|
return $response->getJson(); |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|