Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit 6dbd829

Browse files
authored
Merge pull request #33 from MichaelJ2324/2.0
ME Endpoint Fix
2 parents 78594e0 + 19f2275 commit 6dbd829

28 files changed

+386
-77
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
vendor/
44
composer.lock
55
coverage/
6+
docs/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"michaelj2324/php-rest-client": ">=1.3.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "~4.0|~5.0"
26+
"phpunit/phpunit": "~4.0|~5.0",
27+
"phpdocumentor/phpdocumentor": "2.*"
2728
},
2829
"autoload": {
2930
"psr-4": {

src/Auth/SugarOAuthController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
use MRussell\REST\Auth\Abstracts\AbstractOAuth2Controller;
99
use MRussell\REST\Endpoint\Interfaces\EndpointInterface;
1010

11+
/**
12+
* The Authentication Controller for the Sugar 7 REST Client
13+
* - Manages authenticating to API
14+
* - Manages refreshing API token for continuous access
15+
* - Manages logout
16+
* - Configures Endpoints that require auth, so that Requests are properly formatted
17+
* @package Sugarcrm\REST\Auth
18+
*/
1119
class SugarOAuthController extends AbstractOAuth2Controller
1220
{
1321
const ACTION_SUGAR_SUDO = 'sudo';
@@ -60,7 +68,6 @@ public function setCredentials(array $credentials)
6068
if (!empty($this->credentials)){
6169
$token = $this->getStoredToken($this->credentials);
6270
if ($token !== NULL){
63-
$token = json_decode($token,TRUE);
6471
if (is_array($token)){
6572
$this->setToken($token);
6673
}

src/Client/Sugar7API.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,23 @@
66
namespace Sugarcrm\REST\Client;
77

88
use MRussell\REST\Client\AbstractClient;
9-
use MRussell\REST\Endpoint\Interfaces\EndpointInterface;
109
use Sugarcrm\REST\Helpers\Helper;
1110
use Sugarcrm\REST\Auth\SugarOAuthController;
1211
use Sugarcrm\REST\Endpoint\Provider\SugarEndpointProvider;
13-
use Sugarcrm\REST\Endpoint\Module;
14-
use Sugarcrm\REST\Endpoint\ModuleFilter;
15-
use Sugarcrm\REST\Endpoint\Search;
16-
use Sugarcrm\REST\Endpoint\Metadata;
17-
use Sugarcrm\REST\Endpoint\Me;
18-
use Sugarcrm\REST\Endpoint\Enum;
1912
use Sugarcrm\REST\Storage\SugarStaticStorage;
2013

2114
/**
22-
* The Abstract Client implementation for Sugar
15+
* The default Sugar 7 REST v10 API implementation
2316
* @package Sugarcrm\REST\Client\Abstracts\AbstractClient
24-
* @method EndpointInterface ping()
25-
* @method Module module(string $module = '',string $record_id = '')
26-
* @method ModuleFilter list(string $module = '')
27-
* @method Search search()
28-
* @method Metadata metadata(string $module = '')
29-
* @method Me user(string $user_id)
30-
* @method Enum enum(string $module,string $field)
31-
*/
17+
* @method \Sugarcrm\REST\Endpoint\Ping ping()
18+
* @method \Sugarcrm\REST\Endpoint\Module module(string $module = '',string $record_id = '')
19+
* @method \Sugarcrm\REST\Endpoint\ModuleFilter list(string $module = '')
20+
* @method \Sugarcrm\REST\Endpoint\Search search()
21+
* @method \Sugarcrm\REST\Endpoint\Metadata metadata(string $module = '')
22+
* @method \Sugarcrm\REST\Endpoint\Me me()
23+
* @method \Sugarcrm\REST\Endpoint\Enum enum(string $module = '',string $field = '')
24+
* @method \Sugarcrm\REST\Endpoint\Bulk bulk()
25+
*/
3226
class Sugar7API extends AbstractClient
3327
{
3428
/**

src/Endpoint/Abstracts/AbstractSmartSugarEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Sugarcrm\REST\Endpoint\SugarEndpointInterface;
1010

1111
/**
12-
* Class AbstractSmartSugarEndpoint
12+
* Provide a smarter interface for Endpoints, to better manage passed in data
1313
* @package Sugarcrm\REST\Endpoint\Abstracts
1414
*/
1515
class AbstractSmartSugarEndpoint extends SmartEndpoint implements SugarEndpointInterface

src/Endpoint/Abstracts/AbstractSugarBeanCollectionEndpoint.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
namespace Sugarcrm\REST\Endpoint\Abstracts;
77

88
/**
9-
* Class AbstractSugarBeanCollectionEndpoint
9+
* Abstract implementation of SugarBean Collections for Sugar 7 REST Api
10+
* - Works with a single module
11+
* - Built in fields tracking
12+
* - Built in order by tracking
1013
* @package Sugarcrm\REST\Endpoint\Abstracts
1114
*/
1215
abstract class AbstractSugarBeanCollectionEndpoint extends AbstractSugarCollectionEndpoint

src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,27 @@
88
use MRussell\Http\Request\JSON;
99
use MRussell\Http\Request\RequestInterface;
1010
use MRussell\Http\Response\ResponseInterface;
11+
use MRussell\REST\Endpoint\Data\EndpointData;
1112
use MRussell\REST\Endpoint\JSON\ModelEndpoint;
1213
use Sugarcrm\REST\Endpoint\Data\FilterData;
1314
use Sugarcrm\REST\Endpoint\SugarEndpointInterface;
1415

16+
/**
17+
* SugarBean Endpoint acts as a base for any given Module API
18+
* - Provides action based interface for accessing stock and custom actions
19+
* @package Sugarcrm\REST\Endpoint\Abstracts
20+
* @method $this filterLink(string $link_name = '',string $count = '')
21+
* @method $this massLink(string $link_name)
22+
* @method $this createLink(string $link_name)
23+
* @method $this unlink(string $link_name,string $record_id)
24+
* @method $this favorite()
25+
* @method $this unfavorite()
26+
* @method $this subscribe()
27+
* @method $this unsubscribe()
28+
* @method $this audit()
29+
* @method $this file()
30+
* @method $this downloadFile(string $field)
31+
*/
1532
abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarEndpointInterface
1633
{
1734
const MODEL_ACTION_VAR = 'action';
@@ -56,10 +73,10 @@ abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarE
5673
* @inheritdoc
5774
*/
5875
protected static $_DEFAULT_PROPERTIES = array(
59-
'auth' => TRUE,
60-
'data' => array(
61-
'required' => array(),
62-
'defaults' => array()
76+
self::PROPERTY_AUTH => TRUE,
77+
self::PROPERTY_DATA => array(
78+
EndpointData::DATA_PROPERTY_REQUIRED => array(),
79+
EndpointData::DATA_PROPERTY_DEFAULTS => array()
6380
)
6481
);
6582

@@ -81,7 +98,7 @@ abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarE
8198
self::BEAN_ACTION_UNLINK => JSON::HTTP_DELETE,
8299
self::BEAN_ACTION_CREATE_RELATED => JSON::HTTP_POST,
83100
self::BEAN_ACTION_FOLLOW => JSON::HTTP_POST,
84-
self::BEAN_ACTION_UNFOLLOW => JSON::HTTP_PUT,
101+
self::BEAN_ACTION_UNFOLLOW => JSON::HTTP_DELETE,
85102
self::BEAN_ACTION_AUDIT => JSON::HTTP_GET,
86103
self::BEAN_ACTION_FILE => JSON::HTTP_GET,
87104
self::BEAN_ACTION_DOWNLOAD_FILE => JSON::HTTP_GET,
@@ -305,6 +322,24 @@ protected function updateModel()
305322
}
306323
}
307324

325+
/**
326+
* System friendly name for subscribing to a record
327+
* @return self
328+
*/
329+
public function follow()
330+
{
331+
return $this->subscribe();
332+
}
333+
334+
/**
335+
* System friendly name for unsubscribing to a record
336+
* @return self
337+
*/
338+
public function unfollow()
339+
{
340+
return $this->unsubscribe();
341+
}
342+
308343
/**
309344
* Human friendly method name for Link action
310345
* @param string $linkName - Relationship Link Name
@@ -398,6 +433,7 @@ public function attachFile($fileField,$filePath,$deleteOnFail = false,$mimeType
398433
}
399434

400435
/**
436+
* Overloading tempFile dynamic method to provide more functionality
401437
* @param $fileField
402438
* @param $filePath
403439
* @param bool $deleteOnFail

src/Endpoint/Abstracts/AbstractSugarCollectionEndpoint.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55

66
namespace Sugarcrm\REST\Endpoint\Abstracts;
77

8+
use MRussell\REST\Endpoint\Data\EndpointData;
89
use MRussell\REST\Endpoint\JSON\CollectionEndpoint;
910
use Sugarcrm\REST\Endpoint\SugarEndpointInterface;
1011

12+
/**
13+
* Provides access to a multi-bean collection retrieved from Sugar 7 REST Api
14+
* - Built in pagination functionality
15+
* @package Sugarcrm\REST\Endpoint\Abstracts
16+
*/
1117
abstract class AbstractSugarCollectionEndpoint extends CollectionEndpoint implements SugarEndpointInterface
1218
{
1319
const SUGAR_OFFSET_PROPERTY = 'offset';
@@ -22,10 +28,10 @@ abstract class AbstractSugarCollectionEndpoint extends CollectionEndpoint implem
2228
* @inehritdoc
2329
*/
2430
protected static $_DEFAULT_PROPERTIES = array(
25-
'auth' => TRUE,
26-
'data' => array(
27-
'required' => array(),
28-
'defaults' => array()
31+
self::PROPERTY_AUTH => TRUE,
32+
self::PROPERTY_DATA => array(
33+
EndpointData::DATA_PROPERTY_REQUIRED => array(),
34+
EndpointData::DATA_PROPERTY_DEFAULTS => array()
2935
)
3036
);
3137

src/Endpoint/Abstracts/AbstractSugarEndpoint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
use MRussell\REST\Endpoint\JSON\Endpoint;
99
use Sugarcrm\REST\Endpoint\SugarEndpointInterface;
1010

11+
/**
12+
* Base Sugar API Endpoint for the simplest of REST functionality
13+
* @package Sugarcrm\REST\Endpoint\Abstracts
14+
*/
1115
abstract class AbstractSugarEndpoint extends Endpoint implements SugarEndpointInterface
1216
{
1317
/**

src/Endpoint/Bulk.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
namespace Sugarcrm\REST\Endpoint;
77

88
use MRussell\Http\Request\JSON;
9+
use MRussell\REST\Endpoint\Data\EndpointData;
910
use Sugarcrm\REST\Endpoint\Abstracts\AbstractSmartSugarEndpoint;
1011

1112
/**
12-
* Class Bulk
13+
* Bulk Endpoint allows for submitting multiple REST Requests in a single request
14+
* - Consumes other Endpoint Objects for ease of use
1315
* @package Sugarcrm\REST\Endpoint
1416
*/
1517
class Bulk extends AbstractSmartSugarEndpoint
@@ -28,13 +30,13 @@ class Bulk extends AbstractSmartSugarEndpoint
2830
* @var array
2931
*/
3032
protected static $_DEFAULT_PROPERTIES = array(
31-
'auth' => TRUE,
32-
'httpMethod' => JSON::HTTP_POST,
33-
'data' => array(
34-
'required' => array(
33+
self::PROPERTY_AUTH => TRUE,
34+
self::PROPERTY_HTTP_METHOD => JSON::HTTP_POST,
35+
self::PROPERTY_DATA => array(
36+
EndpointData::DATA_PROPERTY_REQUIRED => array(
3537
'requests' => 'array'
3638
),
37-
'defaults' => array()
39+
EndpointData::DATA_PROPERTY_DEFAULTS => array()
3840
)
3941
);
4042

0 commit comments

Comments
 (0)