| @@ 15-86 (lines=72) @@ | ||
| 12 | /** |
|
| 13 | * Class FieldService |
|
| 14 | */ |
|
| 15 | class FieldService extends AbstractService implements ServiceInterface |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * @param FieldListMessage $message |
|
| 19 | * |
|
| 20 | * @return Field[] |
|
| 21 | */ |
|
| 22 | public function getFields(FieldListMessage $message): array |
|
| 23 | { |
|
| 24 | $path = sprintf('sites/%d/fields', $message->getSiteId()); |
|
| 25 | ||
| 26 | $response = $this->getClient()->sendRequest('GET', $path); |
|
| 27 | ||
| 28 | /** @var Field[] $models */ |
|
| 29 | $models = $this->getModelFactory()->createMany(Field::class, $response); |
|
| 30 | ||
| 31 | return $models; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @param FieldPostMessage $message |
|
| 36 | * |
|
| 37 | * @return Field |
|
| 38 | */ |
|
| 39 | public function postField(FieldPostMessage $message): Field |
|
| 40 | { |
|
| 41 | $path = sprintf('sites/%d/fields', $message->getSiteId()); |
|
| 42 | $data = ['api_field' => $message->build()]; |
|
| 43 | ||
| 44 | $response = $this->getClient()->sendRequest('POST', $path, $data); |
|
| 45 | ||
| 46 | /** @var Field $model */ |
|
| 47 | $model = $this->getModelFactory()->create(Field::class, $response); |
|
| 48 | ||
| 49 | return $model; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param FieldPatchMessage $message |
|
| 54 | * |
|
| 55 | * @return Field |
|
| 56 | */ |
|
| 57 | public function patchField(FieldPatchMessage $message): Field |
|
| 58 | { |
|
| 59 | $path = sprintf('sites/%d/fields/%d', $message->getSiteId(), $message->getId()); |
|
| 60 | $data = ['api_field' => $message->build()]; |
|
| 61 | ||
| 62 | $response = $this->getClient()->sendRequest('PATCH', $path, $data); |
|
| 63 | ||
| 64 | /** @var Field $model */ |
|
| 65 | $model = $this->getModelFactory()->create(Field::class, $response); |
|
| 66 | ||
| 67 | return $model; |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @param FieldOverrideMessage $message |
|
| 72 | * |
|
| 73 | * @return Field |
|
| 74 | */ |
|
| 75 | public function overrideField(FieldOverrideMessage $message): Field |
|
| 76 | { |
|
| 77 | $path = sprintf('sites/%d/fields/%d/override', $message->getSiteId(), $message->getId()); |
|
| 78 | ||
| 79 | $response = $this->getClient()->sendRequest('GET', $path); |
|
| 80 | ||
| 81 | /** @var Field $model */ |
|
| 82 | $model = $this->getModelFactory()->create(Field::class, $response); |
|
| 83 | ||
| 84 | return $model; |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||
| @@ 15-86 (lines=72) @@ | ||
| 12 | /** |
|
| 13 | * Class LocationService |
|
| 14 | */ |
|
| 15 | class LocationService extends AbstractService implements ServiceInterface |
|
| 16 | { |
|
| 17 | /** |
|
| 18 | * @param LocationListMessage $message |
|
| 19 | * |
|
| 20 | * @return Location[] |
|
| 21 | */ |
|
| 22 | public function getLocations(LocationListMessage $message): array |
|
| 23 | { |
|
| 24 | $path = sprintf('sites/%d/locations', $message->getSiteId()); |
|
| 25 | ||
| 26 | $response = $this->getClient()->sendRequest('GET', $path); |
|
| 27 | ||
| 28 | /** @var Location[] $models */ |
|
| 29 | $models = $this->getModelFactory()->createMany(Location::class, $response); |
|
| 30 | ||
| 31 | return $models; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @param LocationPostMessage $message |
|
| 36 | * |
|
| 37 | * @return Location |
|
| 38 | */ |
|
| 39 | public function postLocation(LocationPostMessage $message): Location |
|
| 40 | { |
|
| 41 | $path = sprintf('sites/%d/locations', $message->getSiteId()); |
|
| 42 | $data = ['api_location' => $message->build()]; |
|
| 43 | ||
| 44 | $response = $this->getClient()->sendRequest('POST', $path, $data); |
|
| 45 | ||
| 46 | /** @var Location $model */ |
|
| 47 | $model = $this->getModelFactory()->create(Location::class, $response); |
|
| 48 | ||
| 49 | return $model; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param LocationPatchMessage $message |
|
| 54 | * |
|
| 55 | * @return Location |
|
| 56 | */ |
|
| 57 | public function patchLocation(LocationPatchMessage $message): Location |
|
| 58 | { |
|
| 59 | $path = sprintf('sites/%d/locations/%d', $message->getSiteId(), $message->getId()); |
|
| 60 | $data = ['api_location' => $message->build()]; |
|
| 61 | ||
| 62 | $response = $this->getClient()->sendRequest('PATCH', $path, $data); |
|
| 63 | ||
| 64 | /** @var Location $model */ |
|
| 65 | $model = $this->getModelFactory()->create(Location::class, $response); |
|
| 66 | ||
| 67 | return $model; |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @param LocationOverrideMessage $message |
|
| 72 | * |
|
| 73 | * @return Location |
|
| 74 | */ |
|
| 75 | public function overrideLocation(LocationOverrideMessage $message): Location |
|
| 76 | { |
|
| 77 | $path = sprintf('sites/%d/locations/%d/override', $message->getSiteId(), $message->getId()); |
|
| 78 | ||
| 79 | $response = $this->getClient()->sendRequest('GET', $path); |
|
| 80 | ||
| 81 | /** @var Location $model */ |
|
| 82 | $model = $this->getModelFactory()->create(Location::class, $response); |
|
| 83 | ||
| 84 | return $model; |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||