1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,55 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace Phaxio; |
|
4 |
+ |
|
5 |
+class Fax extends AbstractResource |
|
6 |
+{ |
|
7 |
+ public static function create($phaxio, $params) { |
|
8 |
+ $fax = new self($phaxio); |
|
9 |
+ return $fax->_create($params); |
|
10 |
+ } |
|
11 |
+ |
|
12 |
+ public static function init($phaxio, $id) { |
|
13 |
+ return new self($phaxio, array('id' => $id)); |
|
14 |
+ } |
|
15 |
+ |
|
16 |
+ private function _create($params) { |
|
17 |
+ if (isset($this->id)) throw new Exception("Fax #{$this->id} already created"); |
|
18 |
+ |
|
19 |
+ $result = $this->phaxio->doRequest('POST', 'faxes', $params); |
|
20 |
+ $this->id = $result->getData()['id']; |
|
21 |
+ |
|
22 |
+ return $this; |
|
23 |
+ } |
|
24 |
+ |
|
25 |
+ public function retrieve() { |
|
26 |
+ if (!isset($this->id)) throw new Exception("Must set ID before getting fax"); |
|
27 |
+ |
|
28 |
+ $result = $this->phaxio->doRequest("GET", 'faxes/' . urlencode($this->id)); |
|
29 |
+ $this->exchangeArray($result->getData()); |
|
30 |
+ |
|
31 |
+ return $this; |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+ public function cancel() { |
|
35 |
+ $result = $this->phaxio->doRequest("POST", 'faxes/' . urlencode($this->id) . "/cancel"); |
|
36 |
+ |
|
37 |
+ return true; |
|
38 |
+ } |
|
39 |
+ |
|
40 |
+ public function resend($params = array()) { |
|
41 |
+ $result = $this->phaxio->doRequest("POST", 'faxes/' . urlencode($this->id) . "/resend", $params); |
|
42 |
+ |
|
43 |
+ return self::init($this->phaxio, $result->getData()['id']); |
|
44 |
+ } |
|
45 |
+ |
|
46 |
+ public function delete() { |
|
47 |
+ $result = $this->phaxio->doRequest("DELETE", 'faxes/' . urlencode($this->id)); |
|
48 |
+ |
|
49 |
+ return true; |
|
50 |
+ } |
|
51 |
+ |
|
52 |
+ public function getFile($params = array()) { |
|
53 |
+ return new Fax\File($this->phaxio, $this->id, $params); |
|
54 |
+ } |
|
55 |
+} |