|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mozammil\Putio\Endpoints; |
|
4
|
|
|
|
|
5
|
|
|
use Mozammil\Putio\Http\Client; |
|
6
|
|
|
|
|
7
|
|
|
class Transfers |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The Http Client. |
|
11
|
|
|
* |
|
12
|
|
|
* @var \Mozammil\Putio\Http\Client |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $client; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(Client $client) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->client = $client; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Lists active transfers. |
|
23
|
|
|
* If transfer is completed, it is removed from the list. |
|
24
|
|
|
* |
|
25
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
26
|
|
|
* |
|
27
|
|
|
* @see https://api.put.io/v2/docs/transfers.html#get--transfers-list |
|
28
|
|
|
* |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
|
|
public function list() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->client->get('transfers/list'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Adds a new transfer. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $url |
|
40
|
|
|
* @param int $save_parent_id |
|
41
|
|
|
* @param string $callback_url |
|
42
|
|
|
* |
|
43
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
44
|
|
|
* |
|
45
|
|
|
* @see https://api.put.io/v2/docs/transfers.html#post--transfers-add |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function add(string $url, int $save_parent_id = 0, string $callback_url = '') |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->client->post('transfers/add', [ |
|
52
|
|
|
'form_params' => compact('url', 'save_parent_id', 'callback_url'), |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returns a transfer’s properties. |
|
58
|
|
|
* |
|
59
|
|
|
* @param int $id |
|
60
|
|
|
* |
|
61
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
62
|
|
|
* |
|
63
|
|
|
* @see https://api.put.io/v2/docs/transfers.html#get--transfers--id- |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function get(int $id) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->client->get(sprintf('transfers/%d', $id)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Retry previously failed transfer. |
|
74
|
|
|
* |
|
75
|
|
|
* @param int $id |
|
76
|
|
|
* |
|
77
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
78
|
|
|
* |
|
79
|
|
|
* @see https://api.put.io/v2/docs/transfers.html#retry |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function retry(int $id) |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->client->post('transfers/retry', [ |
|
86
|
|
|
'form_params' => compact('id'), |
|
87
|
|
|
]); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Deletes the given transfers. |
|
92
|
|
|
* |
|
93
|
|
|
* @param array $transfer_ids |
|
94
|
|
|
* |
|
95
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
96
|
|
|
* |
|
97
|
|
|
* @see https://api.put.io/v2/docs/transfers.html#cancel |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
|
|
public function cancel(array $transfer_ids = []) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->client->post('transfers/cancel', [ |
|
104
|
|
|
'form_params' => ['transfer_ids' => implode(',', $transfer_ids)], |
|
105
|
|
|
]); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Clean completed transfers from the list. |
|
110
|
|
|
* |
|
111
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
112
|
|
|
* |
|
113
|
|
|
* @see https://api.put.io/v2/docs/transfers.html#clean |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function clean() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->client->post('transfers/clean'); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|