| @@ 9-66 (lines=58) @@ | ||
| 6 | use Digitonic\IexCloudSdk\Exceptions\WrongData; |
|
| 7 | use Digitonic\IexCloudSdk\Requests\BaseRequest; |
|
| 8 | ||
| 9 | class KeyStats extends BaseRequest |
|
| 10 | { |
|
| 11 | const ENDPOINT = 'stock/{symbol}/stats'; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * IEX Cloud Documentation provides for the optional field to be added to |
|
| 15 | * the end of the endpoint uri in order to retrieve a specific field. |
|
| 16 | * This property allows that functionality to be used in this SDK. |
|
| 17 | */ |
|
| 18 | public $field; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Create constructor. |
|
| 22 | * |
|
| 23 | * @param IEXCloud $api |
|
| 24 | */ |
|
| 25 | public function __construct(IEXCloud $api) |
|
| 26 | { |
|
| 27 | parent::__construct($api); |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * If the field property is set, add it to the end of the endpoint string. |
|
| 32 | * |
|
| 33 | * @return string |
|
| 34 | */ |
|
| 35 | protected function getFullEndpoint(): string |
|
| 36 | { |
|
| 37 | $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT); |
|
| 38 | ||
| 39 | return $this->field ? "$endpoint/$this->field" : $endpoint; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @return bool|void |
|
| 44 | * @throws WrongData |
|
| 45 | */ |
|
| 46 | protected function validateParams(): void |
|
| 47 | { |
|
| 48 | if (empty($this->symbol)) { |
|
| 49 | throw WrongData::invalidValuesProvided('Please provide a symbol to query!'); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Setter for field property |
|
| 55 | * |
|
| 56 | * @param string $field |
|
| 57 | * |
|
| 58 | * @return KeyStats |
|
| 59 | */ |
|
| 60 | public function only(string $field): self |
|
| 61 | { |
|
| 62 | $this->field = $field; |
|
| 63 | ||
| 64 | return $this; |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 9-66 (lines=58) @@ | ||
| 6 | use Digitonic\IexCloudSdk\Exceptions\WrongData; |
|
| 7 | use Digitonic\IexCloudSdk\Requests\BaseRequest; |
|
| 8 | ||
| 9 | class Quote extends BaseRequest |
|
| 10 | { |
|
| 11 | const ENDPOINT = 'stock/{symbol}/quote'; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * IEX Cloud Documentation provides for the optional field to be added to |
|
| 15 | * the end of the endpoint uri in order to retrieve a specific field. |
|
| 16 | * This property allows that functionality to be used in this SDK. |
|
| 17 | */ |
|
| 18 | public $field; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * Create constructor. |
|
| 22 | * |
|
| 23 | * @param IEXCloud $api |
|
| 24 | */ |
|
| 25 | public function __construct(IEXCloud $api) |
|
| 26 | { |
|
| 27 | parent::__construct($api); |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * If the field property is set, add it to the end of the endpoint string. |
|
| 32 | * |
|
| 33 | * @return string |
|
| 34 | */ |
|
| 35 | protected function getFullEndpoint(): string |
|
| 36 | { |
|
| 37 | $endpoint = str_replace('{symbol}', $this->symbol, self::ENDPOINT); |
|
| 38 | ||
| 39 | return $this->field ? "$endpoint/$this->field" : $endpoint; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @return bool|void |
|
| 44 | * @throws WrongData |
|
| 45 | */ |
|
| 46 | protected function validateParams(): void |
|
| 47 | { |
|
| 48 | if (empty($this->symbol)) { |
|
| 49 | throw WrongData::invalidValuesProvided('Please provide a symbol to query!'); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Setter for field property |
|
| 55 | * |
|
| 56 | * @param string $field |
|
| 57 | * |
|
| 58 | * @return Quote |
|
| 59 | */ |
|
| 60 | public function only(string $field): self |
|
| 61 | { |
|
| 62 | $this->field = $field; |
|
| 63 | ||
| 64 | return $this; |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||