also looking at this
Media model
#6
7 files
+1700
-76
| @@ -0,0 +1,87 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | namespace Meema\MeemaApi\Response; | |
| 4 | ||
| 5 | use Illuminate\Support\Arr; | |
| 6 | use Meema\MeemaApi\Traits\ForwardsCalls; | |
| 7 | ||
| 8 | class Response | |
| 9 | { | |
| 10 | use ForwardsCalls; | |
| 11 | ||
| 12 | /** | |
| 13 | * @var \Meema\MeemaApi\Client | |
| 14 | */ | |
| 15 | protected $api; | |
| 16 | ||
| 17 | /** | |
| 18 | * @var array | |
| 19 | */ | |
| 20 | protected $content; | |
| 21 | ||
| 22 | public function __construct($api, $content) | |
| 23 | { | |
| 24 | $this->api = $api; | |
| 25 | $this->content = $content; | |
| 26 | } | |
| 27 | ||
| 28 | /** | |
| 29 | * Dynamically handle calls into the query instance. | |
| 30 | * | |
| 31 | * @param string $method | |
| 32 | * @param array $parameters | |
| 33 | * | |
| 34 | * @return mixed | |
| 35 | */ | |
| 36 | public function __call($method, $parameters) | |
| 37 | { | |
| 38 | return $this->forwardCallTo($this->api, $method, array_merge( | |
| 39 | Arr::wrap($this->getKey()), $parameters | |
| 40 | )); | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Get the primary key for the model. | |
| 45 | * | |
| 46 | * @return string | |
| 47 | */ | |
| 48 | public function getKeyName() | |
| 49 | { | |
| 50 | return 'id'; | |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Get the value of the response primary key. | |
| 55 | * | |
| 56 | * @return mixed | |
| 57 | */ | |
| 58 | public function getKey() | |
| 59 | { | |
| 60 | return $this->getData($this->getKeyName()); | |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Get data. | |
| 65 | * | |
| 66 | * @return array | |
| 67 | */ | |
| 68 | public function getData($key) | |
| 69 | { | |
| 70 | return $this->getContent('data'.($key ? '.'.$key : '')); | |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Get response content. | |
| 75 | * | |
| 76 | * @param mixed $key | |
| 77 | * @return array | |
| 78 | */ | |
| 79 | public function getContent($key = null) | |
| 80 | { | |
| 81 | if ($key) { | |
| 82 | return Arr::get($this->content, $key); | |
| 83 | } | |
| 84 | ||
| 85 | return $this->content; | |
| 86 | } | |
| 87 | } | |