From d3c9ccb4ea6a08417be73807aefdc570941bdf87 Mon Sep 17 00:00:00 2001 From: Massab Date: Fri, 16 Feb 2024 15:57:27 +0500 Subject: [PATCH] Added Guage::Needle Functionalities (Show, Update) --- README.md | 1 + docs/needles.md | 24 ++++++++++++++++++++++++ docs/projects.md | 1 + src/Models/Needle.php | 35 +++++++++++++++++++++++++++++++++++ src/Models/Project.php | 10 ++++++++++ src/Sections/Needles.php | 28 ++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 docs/needles.md create mode 100644 src/Models/Needle.php create mode 100644 src/Sections/Needles.php diff --git a/README.md b/README.md index d30f578..57d467e 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ $projects = Basecamp::projects()->index($nextPage); - [Documents](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/documents.md) - [Events](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/events.md) - [Forwards](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/forwards.md) +- [Needles](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/needles.md) - [Inboxes](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/inboxes.md) - [Message Boards](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/message_boards.md) - [Message types](https://github.com/coopbelvedere/laravel-basecamp-api/blob/master/docs/message_types.md) diff --git a/docs/needles.md b/docs/needles.md new file mode 100644 index 0000000..bf22f41 --- /dev/null +++ b/docs/needles.md @@ -0,0 +1,24 @@ +# Needles + + +# Get the needle state + +```php +$needle = Basecamp::needles()->show($project_id); +``` + +## Update the needle state + +```php + +$data = [ + "gauge_needle[position]" => 50 + "gauge_needle[color]" => "green" + "gauge_needle[description]" => "Hello World" +]; + +$needle->update($data); + +// Or update the state with Project ID. +Basecamp::needles()->update($project_id, $data); +``` diff --git a/docs/projects.md b/docs/projects.md index 69a4ad2..e526629 100644 --- a/docs/projects.md +++ b/docs/projects.md @@ -26,6 +26,7 @@ $project->schedule(); $project->questionnaire(); $project->vault(); $project->inbox(); +$project->needle(); // Client items $project->clientApprovals(); diff --git a/src/Models/Needle.php b/src/Models/Needle.php new file mode 100644 index 0000000..b6d594f --- /dev/null +++ b/src/Models/Needle.php @@ -0,0 +1,35 @@ +show($this->project_id); + } + + /** + * Update the Needle State. + * + * @param array $data + * @return \Illuminate\Http\Collection + */ + public function update(array $data) + { + $needle = Basecamp::needles()->update($this->project_id, $data); + + $this->setAttributes($needle); + + return $needle; + } + +} \ No newline at end of file diff --git a/src/Models/Project.php b/src/Models/Project.php index ad3fbb6..fde028f 100644 --- a/src/Models/Project.php +++ b/src/Models/Project.php @@ -132,6 +132,16 @@ public function clientCorrespondences() return Basecamp::clientCorrespondences($this->id); } + /** + * Get the project's client needle state. + * + * @return \Illuminate\Http\Collection + */ + public function needle() + { + return Basecamp::needles($this->id); + } + /** * Update the project. * diff --git a/src/Sections/Needles.php b/src/Sections/Needles.php new file mode 100644 index 0000000..e2803e5 --- /dev/null +++ b/src/Sections/Needles.php @@ -0,0 +1,28 @@ +client->get(sprintf('projects/%d/gauge/needles.json', $id))); + } + + public function update($id, array $data) + { + $needle = $this->client->post(sprintf('projects/%d/gauge/needles.json', $id), [ + 'json' => $data, + ]); + + return new Needle($this->response($needle)); + } +}