|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Auth0\SDK\API\Management; |
| 4 | + |
| 5 | +use Auth0\SDK\Exception\EmptyOrInvalidParameterException; |
| 6 | + |
| 7 | +/** |
| 8 | + * Class LogStreams. |
| 9 | + * Access to the v2 Management API Log Streams endpoint. |
| 10 | + * |
| 11 | + * @package Auth0\SDK\API\Management |
| 12 | + */ |
| 13 | +class LogStreams extends GenericResource { |
| 14 | + |
| 15 | + private const LOG_STREAMS_PATH = 'log-streams'; |
| 16 | + |
| 17 | + /** |
| 18 | + * Get all Log Streams. |
| 19 | + * Required scope: "read:log_streams" |
| 20 | + * |
| 21 | + * @return mixed |
| 22 | + * |
| 23 | + * @throws \Exception Thrown by Guzzle for API errors. |
| 24 | + * |
| 25 | + * @link https://auth0.com/docs/api/management/v2#!/Log_Streams/get_log_streams |
| 26 | + */ |
| 27 | + public function getAll() |
| 28 | + { |
| 29 | + return $this->apiClient->method('get') |
| 30 | + ->addPath(self::LOG_STREAMS_PATH) |
| 31 | + ->call(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Get a single Log Stream. |
| 36 | + * Required scope: "read:log_streams" |
| 37 | + * |
| 38 | + * @param string $log_stream_id Log Stream ID to get. |
| 39 | + * |
| 40 | + * @return mixed |
| 41 | + * |
| 42 | + * @throws \Exception Thrown by Guzzle for API errors. |
| 43 | + * |
| 44 | + * @link https://auth0.com/docs/api/management/v2#!/Log_Streams/get_log_streams_by_id |
| 45 | + */ |
| 46 | + public function get($log_stream_id) |
| 47 | + { |
| 48 | + $this->checkEmptyOrInvalidString($log_stream_id, 'log_stream_id'); |
| 49 | + |
| 50 | + return $this->apiClient->method('get') |
| 51 | + ->addPath(self::LOG_STREAMS_PATH, $log_stream_id) |
| 52 | + ->call(); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Create a new Log Stream. |
| 57 | + * Required scope: "create:log_streams" |
| 58 | + * |
| 59 | + * @param array $data Log Stream data to create: |
| 60 | + * - "name" if not specified, a name of the Log Stream will be assigned by the Log Stream endpoint. |
| 61 | + * - "type" field is required. |
| 62 | + * - "sink" field is required. It's value and requirements depends upon the type of Log Stream to create; see the linked documentation below. |
| 63 | + * |
| 64 | + * @return mixed |
| 65 | + * |
| 66 | + * @throws EmptyOrInvalidParameterException Thrown if any required parameters are empty or invalid. |
| 67 | + * @throws \Exception Thrown by the HTTP client when there is a problem with the API call. |
| 68 | + * |
| 69 | + * @link https://auth0.com/docs/api/management/v2#!/Log_Streams/post_log_streams |
| 70 | + */ |
| 71 | + public function create(array $data) |
| 72 | + { |
| 73 | + if (empty($data)) { |
| 74 | + throw new EmptyOrInvalidParameterException('Missing required "data" parameter.'); |
| 75 | + } |
| 76 | + |
| 77 | + if (empty($data['type'])) { |
| 78 | + throw new EmptyOrInvalidParameterException('Missing required "type" field.'); |
| 79 | + } |
| 80 | + |
| 81 | + if (empty($data['sink'])) { |
| 82 | + throw new EmptyOrInvalidParameterException('Missing required "sink" field.'); |
| 83 | + } |
| 84 | + |
| 85 | + return $this->apiClient->method('post') |
| 86 | + ->addPath(self::LOG_STREAMS_PATH) |
| 87 | + ->withBody(json_encode($data)) |
| 88 | + ->call(); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Updates an existing Log Stream. |
| 93 | + * Required scope: "update:log_streams" |
| 94 | + * |
| 95 | + * @param string $log_stream_id the ID of the Log Stream to update. |
| 96 | + * @param array $data Log Stream data to update. Only certain fields are update-able; see the documentation linked below. |
| 97 | + * |
| 98 | + * @return mixed |
| 99 | + * |
| 100 | + * @throws EmptyOrInvalidParameterException Thrown if the log_stream_id parameter is empty. |
| 101 | + * @throws \Exception Thrown by the HTTP client when there is a problem with the API call. |
| 102 | + * |
| 103 | + * @link https://auth0.com/docs/api/management/v2#!/Log_Streams/patch_log_streams_by_id |
| 104 | + */ |
| 105 | + public function update($log_stream_id, array $data) |
| 106 | + { |
| 107 | + if (empty($log_stream_id)) { |
| 108 | + throw new EmptyOrInvalidParameterException('Missing required "log_stream_id" field'); |
| 109 | + } |
| 110 | + |
| 111 | + return $this->apiClient->method('patch') |
| 112 | + ->addPath(self::LOG_STREAMS_PATH, $log_stream_id) |
| 113 | + ->withBody(json_encode($data)) |
| 114 | + ->call(); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Deletes a Log Stream. |
| 119 | + * Required scope: "delete:log_streams" |
| 120 | + * |
| 121 | + * @param string $log_stream_id the ID of the Log Stream to delete. |
| 122 | + * |
| 123 | + * @return mixed |
| 124 | + * |
| 125 | + * @throws EmptyOrInvalidParameterException Thrown if the log_stream_id parameter is empty. |
| 126 | + * @throws \Exception Thrown by the HTTP client when there is a problem with the API call. |
| 127 | + * |
| 128 | + * @link https://auth0.com/docs/api/management/v2#!/Log_Streams/delete_log_streams_by_id |
| 129 | + */ |
| 130 | + public function delete($log_stream_id) |
| 131 | + { |
| 132 | + if (empty($log_stream_id)) { |
| 133 | + throw new EmptyOrInvalidParameterException('Missing required "log_stream_id" field'); |
| 134 | + } |
| 135 | + |
| 136 | + return $this->apiClient->method('delete') |
| 137 | + ->addPath(self::LOG_STREAMS_PATH, $log_stream_id) |
| 138 | + ->call(); |
| 139 | + } |
| 140 | + |
| 141 | +} |
0 commit comments