Skip to content

Commit

Permalink
Merge e13e1ba into 55fa26b
Browse files Browse the repository at this point in the history
  • Loading branch information
dawlib committed May 26, 2021
2 parents 55fa26b + e13e1ba commit ea4c376
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ Whenever something unexpected happens, an exception is thrown to indicate what w

## Running test suite
Execute `vendor/bin/phpunit test` to run the full test suite

## Documentation

[Official Castle docs](https://castle.io/docs)
42 changes: 42 additions & 0 deletions lib/Castle/Castle.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,46 @@ public static function track(Array $attributes)
$request = new Castle_Request();
$request->send('post', '/track', $attributes);
}


/**
* Filter an action
* @param String $attributes 'request_token', 'event', 'context' are required, 'user' with 'id' and 'properties' are optional
* @return Castle_Log
*/
public static function filter(Array $attributes)
{
$request = new Castle_Request();
list($response, $request) = $request->send('post', '/filter', $attributes);
if ($request->rStatus == 204) {
$response = array();
}
return $response;
}

/**
* Log events
* @param String $attributes 'request_token', 'event', 'status' and 'user' object with 'id' are required
* @return Castle_Log
*/
public static function log(Array $attributes)
{
$request = new Castle_Request();
$request->send('post', '/log', $attributes);
}

/**
* Risk
* @param String $attributes 'request_token', 'event', 'context', 'user' with 'id' are required, 'status', 'properties' are optional
* @return Castle_Risk
*/
public static function risk(Array $attributes)
{
$request = new Castle_Request();
list($response, $request) = $request->send('post', '/risk', $attributes);
if ($request->rStatus == 204) {
$response = array();
}
return $response;
}
}
35 changes: 35 additions & 0 deletions test/CastleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ public function testTrack()
$this->assertRequest('post', '/track');
}

public function testFilter()
{
Castle_RequestTransport::setResponse(204, '');
Castle::filter(Array(
'request_token' => '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
'name' => '$registration',
'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')
));
$this->assertRequest('post', '/filter');
}

public function testLog()
{
Castle_RequestTransport::setResponse(204, '');
Castle::log(Array(
'request_token' => '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
'name' => '$login',
'status' => '$failed',
'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')
));
$this->assertRequest('post', '/log');
}

public function testRisk()
{
Castle_RequestTransport::setResponse(204, '');
Castle::risk(Array(
'request_token' => '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302',
'name' => '$login',
'status' => '$succeeded',
'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')
));
$this->assertRequest('post', '/risk');
}

public function testAuthenticate()
{
Castle_RequestTransport::setResponse(201, '{ "status": "approve" }');
Expand Down

0 comments on commit ea4c376

Please sign in to comment.