Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group List implementation fixes #29 #30

Merged
merged 33 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
57f37f1
Group List implementation #29
Vitexus Aug 12, 2024
2061543
Process only correct response #29
Vitexus Aug 12, 2024
6301ee8
missing use added #29
Vitexus Aug 12, 2024
12ad4c5
Update tests/Client/GroupsClientTest.php
Vitexus Aug 12, 2024
1e4e28b
ListGroupResponse.php renamed to ListGroupsResponse.php
Vitexus Aug 12, 2024
0115681
php-cs-fixer fix src used
Vitexus Aug 12, 2024
6f9e012
Group and GroupTest fix
Vitexus Aug 12, 2024
0c32fd9
The api response parsing to array of groups test.
Vitexus Aug 12, 2024
9a601ce
cs fixer used
Vitexus Aug 12, 2024
959246b
returned class fix
Vitexus Aug 12, 2024
ba9e3c7
argument type fix
Vitexus Aug 12, 2024
92b74de
Merge branch 'master' into listgroups
Vitexus Aug 25, 2024
8ebf1f6
Update PHPDoc for Group.php
Vitexus Aug 26, 2024
df1719c
comments must be max 80 characters per line long
Vitexus Aug 26, 2024
ec4fb11
missing variable for $group added
Vitexus Aug 26, 2024
5da5336
ListGroupsResponseTest phpdoc fix
Vitexus Aug 26, 2024
bf1bea5
Merge branch 'master' into listgroups
Vitexus Aug 28, 2024
cb274ca
php-cs-fixer used
Vitexus Aug 28, 2024
1bee04e
Merge branch 'master' of github.com:Vitexus/pushover-php into listgroups
Vitexus Aug 28, 2024
9ed03b2
Update Example/GroupsExample.php
Vitexus Aug 28, 2024
2579c06
Update tests/Client/Response/ListGroupsResponseTest.php
Vitexus Aug 28, 2024
c7d8ba6
Update src/Client/GroupsClient.php
Vitexus Aug 28, 2024
dcfcf5b
Update tests/Client/Response/ListGroupsResponseTest.php
Vitexus Aug 28, 2024
3a2b4bd
Update tests/Client/Response/ListGroupsResponseTest.php
Vitexus Aug 28, 2024
a0f23ac
Update src/Client/Response/ListGroupsResponse.php
Vitexus Aug 28, 2024
8a03435
Update tests/Client/Response/ListGroupsResponseTest.php
Vitexus Aug 28, 2024
9429cce
Update src/Client/Response/ListGroupsResponse.php
Vitexus Aug 28, 2024
162e911
Update src/Client/Response/ListGroupsResponse.php
Vitexus Aug 28, 2024
cba4a05
Update src/Client/Response/ListGroupsResponse.php
Vitexus Aug 28, 2024
0e16a78
Update src/Client/GroupsClient.php
slunak Aug 28, 2024
2b65e6c
Merge branch 'master' of https://github.com/slunak/pushover-php into …
slunak Aug 28, 2024
f79c224
cs-fixer
slunak Aug 28, 2024
7cad5e4
Update src/Client/Response/Base/Response.php
slunak Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Example/GroupsExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function groupsExample()
$createGroupResponse = $group->create('Test');
$newGroupKey = $createGroupResponse->getGroupKey();

// Obtain list of all groups
$currentGroups = $group->list();
Vitexus marked this conversation as resolved.
Show resolved Hide resolved

// Retrieve information about the group from the API and populate the object with it.
/** @var RetrieveGroupResponse $retrieveGroupResponse */
$retrieveGroupResponse = $group->retrieveGroupInformation();
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Light, simple and fast, yet comprehensive wrapper for the [Pushover](https://pus
- Cancel emergency priority retry
- Groups API ([Example](Example/GroupsExample.php))
- Create a group
- List groups
- Retrieve information about the group
- Add / Remove users
- Enable / Disable users
Expand Down
18 changes: 18 additions & 0 deletions src/Api/Groups/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Serhiy\Pushover\Client\Request\Request;
use Serhiy\Pushover\Client\Response\AddUserToGroupResponse;
use Serhiy\Pushover\Client\Response\CreateGroupResponse;
use Serhiy\Pushover\Client\Response\ListGroupResponse;
use Serhiy\Pushover\Client\Response\DisableUserInGroupResponse;
use Serhiy\Pushover\Client\Response\EnableUserInGroupResponse;
use Serhiy\Pushover\Client\Response\RemoveUserFromGroupResponse;
Expand Down Expand Up @@ -145,6 +146,23 @@ public function create(string $name): CreateGroupResponse
return $response;
}

/**
* List the groups.
Vitexus marked this conversation as resolved.
Show resolved Hide resolved
*/
public function list(): ListGroupResponse
{
$client = new GroupsClient($this, GroupsClient::ACTION_LIST_GROUPS);
$request = new Request($client->buildApiUrl(), Request::GET);

$curlResponse = Curl::do($request);

$response = new ListGroupResponse($curlResponse);
$response->setRequest($request);

return $response;
}


/**
* Adds an existing Pushover user to your Delivery Group.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Client/GroupsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GroupsClient extends Client implements ClientInterface
public const ACTION_ENABLE_USER = "enable_user";
public const ACTION_RENAME_GROUP = "rename";
public const ACTION_CREATE_GROUP = "create";
public const ACTION_LIST_GROUPS = "list";

/**
* @var Group
Expand Down Expand Up @@ -58,6 +59,10 @@ public function buildApiUrl()
return Curl::API_BASE_URL."/".Curl::API_VERSION."/groups.json";
}

if ($this->action == self::ACTION_LIST_GROUPS) {
return Curl::API_BASE_URL."/".Curl::API_VERSION."/groups.json?token=".$this->group->getApplication()->getToken();
}

if ($this->action == self::ACTION_RETRIEVE_GROUP) {
return Curl::API_BASE_URL."/".Curl::API_VERSION."/groups/".$this->group->getKey().".json?token=".$this->group->getApplication()->getToken();
}
Expand Down
52 changes: 52 additions & 0 deletions src/Client/Response/ListGroupResponse.php
Vitexus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Pushover package.
*
* (c) Serhiy Lunak <https://github.com/slunak>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Serhiy\Pushover\Client\Response;

use Serhiy\Pushover\Client\Response\Base\Response;

/**
* @author Serhiy Lunak
Vitexus marked this conversation as resolved.
Show resolved Hide resolved
*/
class ListGroupResponse extends Response
{
/**
* @var array
*/
public $groups = [];

/**
* @param mixed $curlResponse
*/
public function __construct($curlResponse)
{
$this->processCurlResponse($curlResponse);
}

/**
* @param mixed $curlResponse
*/
private function processCurlResponse($curlResponse): void
{
$this->groups = [];
$decodedCurlResponse = $this->processInitialCurlResponse($curlResponse);
if (property_exists($decodedCurlResponse, 'groups')) {
foreach ($decodedCurlResponse->groups as $grp) {
$this->groups[$grp->name] = $grp->group;
}
}
}

public function getGroups(): array
Vitexus marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->groups;
}
}
15 changes: 15 additions & 0 deletions tests/Api/Groups/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Serhiy\Pushover\Application;
use Serhiy\Pushover\Client\Response\CreateGroupResponse;
use Serhiy\Pushover\Client\Response\RetrieveGroupResponse;
use Serhiy\Pushover\Client\Response\ListGroupResponse;

/**
* @author Serhiy Lunak
Expand Down Expand Up @@ -79,4 +80,18 @@ public function testCreate()

$this->assertInstanceOf(CreateGroupResponse::class, $response);
}

/**
* @group Integration
*/
public function testList()
{
$application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token
$group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application);

$response = $group->list();

$this->assertInstanceOf(ListGroupResponse::class, $response);
}

}
4 changes: 4 additions & 0 deletions tests/Client/GroupsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function testBuildApiUrl()

$client = new GroupsClient($group, GroupsClient::ACTION_ADD_USER);
$this->assertEquals("https://api.pushover.net/1/groups/eeee5555EEEE5555ffff6666FFFF66/add_user.json?token=cccc3333CCCC3333dddd4444DDDD44", $client->buildApiUrl());

$client = new GroupsClient($group, GroupsClient::ACTION_LIST_GROUPS);
$this->assertEquals("https://api.pushover.net/1/groups.json?token=cccc3333CCCC3333dddd4444DDDD44", $client->buildApiUrl());
Vitexus marked this conversation as resolved.
Show resolved Hide resolved

}

public function testBuildCurlPostFields()
Expand Down
Loading