Skip to content

Commit

Permalink
Merge pull request #12 from tk26/events-api
Browse files Browse the repository at this point in the history
Events api
  • Loading branch information
DannyDouglass committed Jan 14, 2021
2 parents 2ed4b65 + 7800e5f commit 151c201
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ For a full description of request and response payloads and properties, please s
* ```replaceBrand(string $brand_id, string $name, object $settings, object $snippets = NULL): object``` [[?]](https://docs.courier.com/reference/brands-api#replacebrand)
* ```deleteBrand(string $brand_id): object``` [[?]](https://docs.courier.com/reference/brands-api#deletebrand)

### Events API
* ```getEvents(): object``` [[?]](https://docs.courier.com/reference/events-api#getevents)
* ```getEvent(string $event_id): object``` [[?]](https://docs.courier.com/reference/events-api#geteventbyid)
* ```putEvent(string $event_id, string $id, string $type): object``` [[?]](https://docs.courier.com/reference/events-api#replaceeventbyid)
### Profiles API
* ```getProfile(string $recipient_id): object``` [[?]](https://docs.trycourier.com/reference#get-preferencesrecipient_id)
Expand Down
49 changes: 48 additions & 1 deletion src/Courier.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function doRequest(RequestInterface $request): object
* @return RequestInterface|Request
*/
private function buildRequest(string $method, string $path, array $params = []): RequestInterface
{
{
return new Request(
$method,
$this->base_url . $path,
Expand Down Expand Up @@ -582,6 +582,53 @@ public function deleteBrand(string $brand_id): object
);
}

/**
* Fetch the list of events
* @return object
* @throws CourierRequestException
*/
public function getEvents(): object
{
return $this->doRequest(
$this->buildRequest("get", "events")
);
}

/**
* Fetch a specific event by event ID.
*
* @param string $event_id
* @return object
* @throws CourierRequestException
*/
public function getEvent(string $event_id): object
{
return $this->doRequest(
$this->buildRequest("get", "events/" . $event_id)
);
}

/**
* Replace an existing event with the supplied values or create a new event if one does not already exist.
*
* @param string $event_id
* @param string $id
* @param string $type
* @return object
* @throws CourierRequestException
*/
public function putEvent(string $event_id, string $id, string $type): object
{
$params = array(
'id' => $id,
'type' => $type
);

return $this->doRequest(
$this->buildRequest("put", "events/" . $event_id, $params)
);
}

/**
* Get the profile stored under the specified recipient ID.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,31 @@ public function test_delete_brand()
$this->assertEquals("application/json", $response->content);
$this->assertEquals("/brands/brand001", $response->path);
}

public function test_get_events()
{
$response = $this->getCourierClient()->getEvents();

$this->assertEquals("GET", $response->method);
$this->assertEquals("application/json", $response->content);
$this->assertEquals("/events", $response->path);
}

public function test_get_event()
{
$response = $this->getCourierClient()->getEvent("event001");

$this->assertEquals("GET", $response->method);
$this->assertEquals("application/json", $response->content);
$this->assertEquals("/events/event001", $response->path);
}

public function test_put_event()
{
$response = $this->getCourierClient()->putEvent("event001", "notification001", "notification");

$this->assertEquals("PUT", $response->method);
$this->assertEquals("application/json", $response->content);
$this->assertEquals("/events/event001", $response->path);
}
}

0 comments on commit 151c201

Please sign in to comment.