Skip to content

Commit ae61299

Browse files
committed
Implemented core methods
1 parent 930ebe2 commit ae61299

File tree

3 files changed

+111
-4
lines changed

3 files changed

+111
-4
lines changed

Api.php

+56-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function doCall(
8383
$parameters['method'] = (string) $method;
8484
$parameters['format'] = 'json';
8585

86-
// when we need authentication we need to add some extra parameters
86+
// when we need authentication we need to add some extra parameters
8787
if ($authenticate) {
8888
$parameters['email'] = $this->getEmail();
8989
$parameters['nonce'] = md5(microtime(true) + rand(0, time()));
@@ -272,4 +272,59 @@ protected function setUrl($url)
272272

273273
$this->url = (string) $url;
274274
}
275+
276+
/**
277+
* Get the API key for a user
278+
*
279+
* @param string $email
280+
* @param string $password
281+
* @return array
282+
*/
283+
public function coreGetAPIKey($email, $password)
284+
{
285+
// build parameters
286+
$parameters['email'] = (string) $email;
287+
$parameters['password'] = (string) $password;
288+
289+
// make the call
290+
return $this->doCall('core.getAPIKey', $parameters, 'GET', false);
291+
}
292+
293+
/**
294+
* Get info about the site.
295+
*
296+
* @return array
297+
*/
298+
public function coreGetInfo()
299+
{
300+
return $this->doCall('core.getInfo', null, 'GET');
301+
}
302+
303+
/**
304+
* Add a Apple device token to a user
305+
*
306+
* @param string $token
307+
*/
308+
public function coreAppleAddDevice($token)
309+
{
310+
// build parameters
311+
$parameters['token'] = (string) $token;
312+
313+
// make the call
314+
$this->doCall('core.apple.addDevice', $parameters, 'POST');
315+
}
316+
317+
/**
318+
* Remove a Apple device token from a user
319+
*
320+
* @param string $token
321+
*/
322+
public function coreAppleRemoveDevice($token)
323+
{
324+
// build parameters
325+
$parameters['token'] = (string) $token;
326+
327+
// make the call
328+
$this->doCall('core.apple.removeDevice', $parameters, 'POST');
329+
}
275330
}

tests/ApiTest.php

+44-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function setUp()
2525
parent::setUp();
2626

2727
// create instance
28-
$this->api = new Api();
28+
$this->api = new Api(URL, EMAIL, APIKEY);
2929
}
3030

3131
/**
@@ -60,4 +60,47 @@ public function testGetUserAgent()
6060
$this->api->getUserAgent()
6161
);
6262
}
63+
64+
/**
65+
* Tests Api->coreGetAPIKey()
66+
*/
67+
public function testCoreGetAPIKey()
68+
{
69+
$var = $this->api->coreGetAPIKey(EMAIL, PASSWORD);
70+
$this->assertArrayHasKey('api_key', $var);
71+
}
72+
73+
/**
74+
* Tests Api->coreGetInfo()
75+
*/
76+
public function testCoreGetInfo()
77+
{
78+
$var = $this->api->coreGetInfo();
79+
$this->assertArrayHasKey('languages', $var);
80+
foreach ($var['languages'] as $row) {
81+
$this->assertArrayHasKey('language', $row);
82+
$this->assertArrayHasKey('title', $row['language']);
83+
$this->assertArrayHasKey('url', $row['language']);
84+
$this->assertArrayHasKey('@attributes', $row['language']);
85+
$this->assertArrayHasKey('language', $row['language']['@attributes']);
86+
}
87+
}
88+
89+
/**
90+
* Tests Api->coreAppleAddDevice()
91+
*/
92+
public function testCoreAppleAddDevice()
93+
{
94+
$var = $this->api->coreAppleAddDevice(APPLE_DEVICE_TOKEN);
95+
$this->assertNull($var);
96+
}
97+
98+
/**
99+
* Tests Api->coreAppleRemoveDevice()
100+
*/
101+
public function testCoreAppleRemoveDevice()
102+
{
103+
$var = $this->api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN);
104+
$this->assertNull($var);
105+
}
63106
}

tests/index.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
use \ForkCms\Api\Api;
88

99
// create instance
10-
$api = new Api();
10+
$api = new Api(URL, EMAIL, APIKEY);
1111

12-
//output
12+
try {
13+
// $response = $api->coreGetAPIKey(EMAIL, PASSWORD);
14+
// $response = $api->coreGetInfo();
15+
// $response = $api->coreAppleAddDevice(APPLE_DEVICE_TOKEN);
16+
// $response = $api->coreAppleRemoveDevice(APPLE_DEVICE_TOKEN);
17+
} catch (Exception $e) {
18+
var_dump($e);
19+
}
20+
21+
// output
1322
var_dump($response);

0 commit comments

Comments
 (0)