|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NStack\Clients; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use NStack\Exceptions\FailedToParseException; |
|
7
|
|
|
use NStack\Models\File; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class FilesClient |
|
11
|
|
|
* |
|
12
|
|
|
* @package NStack\Clients |
|
13
|
|
|
* @author Tiago Araujo <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class FilesClient extends NStackClient |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
protected $path = 'content/files'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* store |
|
22
|
|
|
* |
|
23
|
|
|
* @param String $name |
|
24
|
|
|
* @param array $tagsArray |
|
25
|
|
|
* @param DateTime $goneAt |
|
26
|
|
|
* @param String $privacy |
|
27
|
|
|
* @param String $imagePath |
|
28
|
|
|
* @return File |
|
29
|
|
|
* @throws FailedToParseException |
|
30
|
|
|
*/ |
|
31
|
1 |
|
public function store(String $name, String $privacy, String $imagePath, array $tagsArray = null, DateTime $goneAt = null) |
|
32
|
|
|
{ |
|
33
|
1 |
|
$response = $this->client->post($this->buildPath($this->path), [ |
|
34
|
|
|
'form_params' => [ |
|
35
|
1 |
|
'name' => $name, |
|
36
|
1 |
|
'tags' => is_null($tagsArray) ? null : implode(",", $tagsArray), |
|
37
|
1 |
|
'gone_at' => $goneAt, |
|
38
|
1 |
|
'privacy' => $privacy, |
|
39
|
1 |
|
'file' => fopen($imagePath, 'r'), |
|
40
|
|
|
] |
|
41
|
|
|
]); |
|
42
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
43
|
1 |
|
$data = json_decode($contents, true); |
|
44
|
|
|
|
|
45
|
1 |
|
return new File($data['data']); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* storeWithPath |
|
50
|
|
|
* |
|
51
|
|
|
* @param String $name |
|
52
|
|
|
* @param String $privacy |
|
53
|
|
|
* @param String $path |
|
54
|
|
|
* @param String $mime |
|
55
|
|
|
* @param int $size |
|
56
|
|
|
* @param array|null $tagsArray |
|
57
|
|
|
* @param DateTime|null $goneAt |
|
58
|
|
|
* @return File |
|
59
|
|
|
* @throws FailedToParseException |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function storeWithPath( |
|
62
|
|
|
String $name, |
|
63
|
|
|
String $privacy, |
|
64
|
|
|
String $path, |
|
65
|
|
|
String $mime, |
|
66
|
|
|
int $size, |
|
67
|
|
|
array $tagsArray = null, |
|
68
|
|
|
DateTime $goneAt = null |
|
69
|
|
|
) |
|
70
|
|
|
{ |
|
71
|
1 |
|
$response = $this->client->post($this->buildPath($this->path . '/path'), [ |
|
72
|
|
|
'form_params' => [ |
|
73
|
1 |
|
'name' => $name, |
|
74
|
1 |
|
'tags' => is_null($tagsArray) ? null : implode(",", $tagsArray), |
|
75
|
1 |
|
'gone_at' => $goneAt, |
|
76
|
1 |
|
'privacy' => $privacy, |
|
77
|
1 |
|
'path' => $path, |
|
78
|
1 |
|
'mime' => $mime, |
|
79
|
1 |
|
'size' => $size, |
|
80
|
|
|
] |
|
81
|
|
|
]); |
|
82
|
1 |
|
$contents = $response->getBody()->getContents(); |
|
83
|
1 |
|
$data = json_decode($contents, true); |
|
84
|
|
|
|
|
85
|
1 |
|
return new File($data['data']); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |