1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,42 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace Phaxio; |
|
4 |
+ |
|
5 |
+class PhaxCode extends AbstractResource |
|
6 |
+{ |
|
7 |
+ public static function create($phaxio, $params) { |
|
8 |
+ $phax_code = new self($phaxio); |
|
9 |
+ return $phax_code->_create($params); |
|
10 |
+ } |
|
11 |
+ |
|
12 |
+ public static function init($phaxio, $identifier = null) { |
|
13 |
+ return new self($phaxio, array('identifier' => $identifier)); |
|
14 |
+ } |
|
15 |
+ |
|
16 |
+ private function _create($params) { |
|
17 |
+ if (isset($this->identifier)) throw new Exception("PhaxCode #{$this->identifier} already created"); |
|
18 |
+ |
|
19 |
+ $result = $this->phaxio->doRequest('POST', 'phax_codes', $params); |
|
20 |
+ $this->identifier = $result->getData()['identifier']; |
|
21 |
+ |
|
22 |
+ return $this; |
|
23 |
+ } |
|
24 |
+ |
|
25 |
+ public function retrieve($getMetadata = false) { |
|
26 |
+ $format = ($getMetadata ? ".json" : ".png"); |
|
27 |
+ |
|
28 |
+ if ($this->identifier === null) { |
|
29 |
+ $result = $this->phaxio->doRequest("GET", 'phax_code' . $format, array(), $getMetadata); |
|
30 |
+ } else { |
|
31 |
+ $result = $this->phaxio->doRequest("GET", 'phax_codes/' . urlencode($this->identifier) . $format, array(), $getMetadata); |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+ if ($getMetadata) { |
|
35 |
+ $this->exchangeArray(array_merge($this->getArrayCopy(), $result->getData())); |
|
36 |
+ } else { |
|
37 |
+ $this->exchangeArray(array_merge($this->getArrayCopy(), $result)); |
|
38 |
+ } |
|
39 |
+ |
|
40 |
+ return $this; |
|
41 |
+ } |
|
42 |
+} |