Skip to content

Commit 2ef74fc

Browse files
committed
1.2.1
1 parent fd6bd25 commit 2ef74fc

File tree

11 files changed

+86
-24
lines changed

11 files changed

+86
-24
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "addressix/addressixapi-client-php",
33
"type": "library",
4-
"version": "1.1.1",
4+
"version": "1.2.1",
55
"description": "Client library for Addressix API",
66
"keywords": ["addressix","api","php"],
77
"homepage": "https://github.com/addressix/addressixapi-client-php",

src/App/Auth/User.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
namespace AddressixAPI\App\Auth;
33

4-
class User extends \AddressixAPI\App\Resource
4+
use AddressixAPI\App\Resource
5+
6+
class User extends Resource
57
{
68
protected $resource_uri = '/users';
79

src/App/Files.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace AddressixAPI\App;
33

4+
use AddressixAPI\App\Files\Appdata;
5+
46
class Files extends \AddressixAPI\App
57
{
68
protected $app_base = '/aixfs/v1';
@@ -9,4 +11,10 @@ public function __construct(\AddressixAPI\Client $client)
911
{
1012
parent::__construct($client);
1113
}
14+
15+
public function getAppdata()
16+
{
17+
$appdata = new Appdata($this);
18+
return $appdata;
19+
}
1220
}

src/App/Files/Appdata.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public function __construct($app)
1717

1818
function get() {
1919
$this->request('get');
20-
parent::set($this->data);
20+
$this->set($this->data);
21+
}
22+
23+
function getByPath($path) {
24+
if (!$this->id) {
25+
$this->get();
26+
}
27+
return parent::getByPath($path);
2128
}
2229
}

src/App/Files/File.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public function __construct($app)
3939
array(
4040
'method' => 'POST',
4141
'uri' => '/files/:id/acls'
42-
);
42+
);
43+
$this->functions['download'] =
44+
array(
45+
'method' => 'GET',
46+
'uri' => '/files/:id/content'
47+
);
4348
}
4449

4550
function set($data) {
@@ -74,6 +79,12 @@ function create($parentid, $filename, $content, $params = array()) {
7479
return $this->get($this->data->itemid);
7580
}
7681

82+
function getContent()
83+
{
84+
$this->request('download', array('id' => $this->id));
85+
return $this->data;
86+
}
87+
7788
function addPermission($addressixid,$organisationid,$role,$type='user', array $params = array())
7889
{
7990
$params['id'] = $this->id;

src/App/Resource.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
namespace AddressixAPI\App;
33

4+
use AddressixAPI\Exception\Exception AS APIException;
5+
use AddressixAPI\Exception\AuthException;
6+
use AddressixAPI\Exception\NotFoundException;
7+
48
class Resource
59
{
610
protected $app;
@@ -25,7 +29,7 @@ public function __construct($app)
2529
public function request($name, $params = array(), $headers = array(), $form_type = 1)
2630
{
2731
if (!isset($this->functions[$name])) {
28-
throw new \AddressixAPI\Exception('Function '.$name.' is not defined for this resource');
32+
throw new APIException('Function '.$name.' is not defined for this resource');
2933
}
3034

3135
// prepare url with params
@@ -51,10 +55,13 @@ public function request($name, $params = array(), $headers = array(), $form_type
5155
$this->data = $response->body;
5256
} else {
5357
if ($response->code==401) {
54-
throw new \AddressixAPI\AuthException('Authorization failed: ' . $response->code . '. URI was: ' . $this->app->getBaseURI(). $req_url);
58+
throw new AuthException('Authorization failed: ' . $response->code . '. URI was: ' . $this->app->getBaseURI(). $req_url);
59+
}
60+
else if ($response->code==404) {
61+
throw new NotFoundException('Resource not found: ' . $response->code . '. URI was: ' . $this->app->getBaseURI(). $req_url);
5562
}
5663
else {
57-
throw new \AddressixAPI\Exception('Request to resource failed: ' . $response->code . '. URI was: ' . $this->app->getBaseURI(). $req_url, $response->code);
64+
throw new APIException('Request to resource failed: ' . $response->code . '. URI was: ' . $this->app->getBaseURI(). $req_url, $response->code);
5865
}
5966
}
6067
}

src/Auth/OAuth2.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
namespace AddressixAPI\Auth;
33

4+
use AddressixAPI\Exception\Exception AS APIException;
5+
use AddressixAPI\Exception\AuthException;
6+
use AddressixAPI\Exception\NotFoundException;
7+
48
class OAuth2
59
{
610
const OAUTH2_REVOKE_URI = 'https://www.addressix.com/oauth2/v1/revoke';
@@ -93,10 +97,25 @@ public function fetchAccessToken($grant_type, array $parameters, array $extra_he
9397
}
9498

9599
if (!isset($parameters['delegation'])) {
96-
return $this->client->getRequest()->request(self::OAUTH2_TOKEN_URI, 'POST', $parameters, $http_headers, 1);
100+
$response = $this->client->getRequest()->request(self::OAUTH2_TOKEN_URI, 'POST', $parameters, $http_headers, 1);
101+
} else {
102+
$response = $this->client->getRequest()->request(self::OAUTH2_DELEGATED_TOKEN_URI, 'POST', $parameters, $http_headers, 1);
103+
}
104+
105+
if ($response->code==200) {
106+
$accesstoken = $response->body;
97107
} else {
98-
return $this->client->getRequest()->request(self::OAUTH2_DELEGATED_TOKEN_URI, 'POST', $parameters, $http_headers, 1);
108+
if ($response->code==401) {
109+
throw new AuthException('Authorization failed: ' . $response->code . '.', 401);
110+
}
111+
else if ($response->code==404) {
112+
throw new NotFoundException('User not found: ' . $response->code . '.', 404);
113+
}
114+
else {
115+
throw new APIException('Request to resource failed: ' . $response->code . '.', $response->code);
116+
}
99117
}
118+
return $accesstoken;
100119
}
101120

102121
public function setAccessToken($token)
@@ -130,7 +149,7 @@ public function authenticate($code)
130149
return $this->access_token;
131150
}
132151
else {
133-
throw new \AddressixAPI\Exception('Authentication failed: ' .$response->code);
152+
throw new APIException('Authentication failed: ' .$response->code);
134153
}
135154
}
136155
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace AddressixAPI;
2+
namespace AddressixAPI\Exception;
33

44
class AuthException extends Exception
55
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace AddressixAPI;
2+
namespace AddressixAPI\Exception;
33

44
class Exception extends \Exception
55
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace AddressixAPI\Exception;
3+
4+
class NotFoundException extends Exception
5+
{
6+
7+
}

0 commit comments

Comments
 (0)