@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param $value - Header Value |
24 | 24 | * @return SugarAPI\SDK\Request Object |
25 | 25 | */ |
26 | - public function addHeader($name,$value); |
|
26 | + public function addHeader($name, $value); |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Sets the Headers on the Curl Request object, called during Sending. Appends to Request Headers property |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param $value - Curl Option Value |
51 | 51 | * @return SugarAPI\SDK\Request Object |
52 | 52 | */ |
53 | - public function setOption($option,$value); |
|
53 | + public function setOption($option, $value); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Set the URL on the Request Object |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
4 | 4 | |
5 | -$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/',array('username' => 'admin','password'=>'asdf')); |
|
5 | +$SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7621/', array('username' => 'admin', 'password'=>'asdf')); |
|
6 | 6 | $SugarAPI->login(); |
7 | 7 | print_r($SugarAPI->getToken()); |
8 | 8 | \ No newline at end of file |
@@ -68,6 +68,9 @@ |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | + /** |
|
72 | + * @param string $className |
|
73 | + */ |
|
71 | 74 | public function registerEntryPoint($funcName,$className){ |
72 | 75 | if (isset($this->entryPoints[$funcName])){ |
73 | 76 | throw new SDKException('SDK method already defined. Method '.$funcName.' references Class '.$className); |
@@ -2,8 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace SugarAPI\SDK; |
4 | 4 | |
5 | -use SugarAPI\SDK\Exception\InitializationFailure; |
|
6 | -use SugarAPI\SDK\Exception\InvalidEntryPoint; |
|
7 | 5 | use SugarAPI\SDK\Exception\AuthenticationException; |
8 | 6 | use SugarAPI\SDK\Exception\SDKException; |
9 | 7 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | private $entryPoints = array(); |
30 | 30 | |
31 | - public function __construct($instance='',array $authOptions = array()){ |
|
31 | + public function __construct($instance = '', array $authOptions = array()){ |
|
32 | 32 | $this->loadDefaults(); |
33 | 33 | if (!empty($instance)){ |
34 | 34 | $this->setInstance($instance); |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | protected function loadDefaults(){ |
43 | - include __DIR__ .DIRECTORY_SEPARATOR.'defaults.php'; |
|
44 | - if (isset($defaults)) { |
|
43 | + include __DIR__.DIRECTORY_SEPARATOR.'defaults.php'; |
|
44 | + if (isset($defaults)){ |
|
45 | 45 | static::$_DEFAULTS = $defaults; |
46 | 46 | if (isset($defaults['instance'])){ |
47 | 47 | $this->setInstance($defaults['instance']); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | public function setAuthOptions(array $options){ |
56 | - foreach($this->authOptions as $key => $value){ |
|
56 | + foreach ($this->authOptions as $key => $value){ |
|
57 | 57 | if (isset($options[$key])){ |
58 | 58 | $this->authOptions[$key] = $options[$key]; |
59 | 59 | } |
@@ -61,27 +61,27 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | protected function registerSDKEntryPoints(){ |
64 | - require __DIR__ .DIRECTORY_SEPARATOR.'EntryPoint' .DIRECTORY_SEPARATOR.'registry.php'; |
|
65 | - foreach($entryPoints as $funcName => $className){ |
|
64 | + require __DIR__.DIRECTORY_SEPARATOR.'EntryPoint'.DIRECTORY_SEPARATOR.'registry.php'; |
|
65 | + foreach ($entryPoints as $funcName => $className){ |
|
66 | 66 | $className = "SugarAPI\\SDK\\EntryPoint\\".$className; |
67 | - $this->registerEntryPoint($funcName,$className); |
|
67 | + $this->registerEntryPoint($funcName, $className); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - public function registerEntryPoint($funcName,$className){ |
|
71 | + public function registerEntryPoint($funcName, $className){ |
|
72 | 72 | if (isset($this->entryPoints[$funcName])){ |
73 | 73 | throw new SDKException('SDK method already defined. Method '.$funcName.' references Class '.$className); |
74 | 74 | } |
75 | 75 | $this->entryPoints[$funcName] = $className; |
76 | 76 | } |
77 | 77 | |
78 | - public function __call($name,$params){ |
|
79 | - if (array_key_exists($name,$this->entryPoints)){ |
|
78 | + public function __call($name, $params){ |
|
79 | + if (array_key_exists($name, $this->entryPoints)){ |
|
80 | 80 | $Class = $this->entryPoints[$name]; |
81 | - $EntryPoint = new $Class($this->url,$params); |
|
81 | + $EntryPoint = new $Class($this->url, $params); |
|
82 | 82 | |
83 | 83 | if ($EntryPoint->authRequired()){ |
84 | - if (isset($this->authToken)) { |
|
84 | + if (isset($this->authToken)){ |
|
85 | 85 | $EntryPoint->configureAuth($this->authToken->access_token); |
86 | 86 | }else{ |
87 | 87 | throw new AuthenticationException('no_auth'); |
@@ -105,17 +105,17 @@ discard block |
||
105 | 105 | } |
106 | 106 | } |
107 | 107 | public function setInstance($instance){ |
108 | - if (strpos("https",$instance)!==FALSE){ |
|
108 | + if (strpos("https", $instance)!==FALSE){ |
|
109 | 109 | $this->secure = TRUE; |
110 | 110 | } |
111 | - if (strpos("http",$instance)===FALSE){ |
|
111 | + if (strpos("http", $instance)===FALSE){ |
|
112 | 112 | $instance = "http://".$instance; |
113 | 113 | } |
114 | - if (strpos("rest/v10",$instance)!==FALSE){ |
|
115 | - $instance = str_replace("rest/v10","",$instance); |
|
114 | + if (strpos("rest/v10", $instance)!==FALSE){ |
|
115 | + $instance = str_replace("rest/v10", "", $instance); |
|
116 | 116 | } |
117 | 117 | $this->instance = $instance; |
118 | - $this->url = rtrim($this->instance,"/").self::API_URL; |
|
118 | + $this->url = rtrim($this->instance, "/").self::API_URL; |
|
119 | 119 | } |
120 | 120 | public function getURL(){ |
121 | 121 | return $this->url; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | protected function loadDefaults(){ |
43 | 43 | include __DIR__ .DIRECTORY_SEPARATOR.'defaults.php'; |
44 | - if (isset($defaults)) { |
|
44 | + if (isset($defaults)){ |
|
45 | 45 | static::$_DEFAULTS = $defaults; |
46 | 46 | if (isset($defaults['instance'])){ |
47 | 47 | $this->setInstance($defaults['instance']); |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | $EntryPoint = new $Class($this->url,$params); |
82 | 82 | |
83 | 83 | if ($EntryPoint->authRequired()){ |
84 | - if (isset($this->authToken)) { |
|
84 | + if (isset($this->authToken)){ |
|
85 | 85 | $EntryPoint->configureAuth($this->authToken->access_token); |
86 | - }else{ |
|
86 | + } else{ |
|
87 | 87 | throw new AuthenticationException('no_auth'); |
88 | 88 | } |
89 | 89 | } |
90 | 90 | return $EntryPoint; |
91 | - }else{ |
|
91 | + } else{ |
|
92 | 92 | throw new SDKException('Method '.$name.', is not a registered method of the SugarAPI SDK'); |
93 | 93 | } |
94 | 94 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $response = $EP->data($this->authOptions)->execute()->getResponse(); |
101 | 101 | if ($response->getStatus()=='200'){ |
102 | 102 | $this->authToken = $response->getBody(); |
103 | - }else{ |
|
103 | + } else{ |
|
104 | 104 | throw new AuthenticationException($response->getBody()); |
105 | 105 | } |
106 | 106 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\EntryPoint\Abstracts\GET\FileEntryPoint as GETFileEntryPoint; |
6 | 6 | |
7 | -class RecordFileField extends GETFileEntryPoint{ |
|
7 | +class RecordFileField extends GETFileEntryPoint { |
|
8 | 8 | |
9 | 9 | protected $_URL = '$module/$record/file/$field'; |
10 | 10 |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\EntryPoint\Abstracts\GET\FileEntryPoint as GETFileEntryPoint; |
6 | 6 | |
7 | -class RecordFileField extends GETFileEntryPoint{ |
|
7 | +class RecordFileField extends GETFileEntryPoint { |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * @inheritdoc |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\EntryPoint\Abstracts\POST\JSONEntryPoint as POSTEntryPoint; |
6 | 6 | |
7 | -class CreateRecord extends POSTEntryPoint{ |
|
7 | +class CreateRecord extends POSTEntryPoint { |
|
8 | 8 | |
9 | 9 | protected $_URL = '$module'; |
10 | 10 |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\EntryPoint\Abstracts\POST\JSONEntryPoint as POSTEntryPoint; |
6 | 6 | |
7 | -class CreateRecord extends POSTEntryPoint{ |
|
7 | +class CreateRecord extends POSTEntryPoint { |
|
8 | 8 | |
9 | 9 | protected $_URL = '$module'; |
10 | 10 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | print_r($response); |
14 | 14 | |
15 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
15 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
16 | 16 | print $ex->getMessage(); |
17 | 17 | } |
18 | 18 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
4 | 4 | |
5 | 5 | $record_id = 'a887c75b-b89a-852e-8e67-56f1ccdee355'; |
6 | 6 | |
7 | 7 | try{ |
8 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77',array('username' => 'admin','password'=>'admin123')); |
|
8 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('localhost/ent77', array('username' => 'admin', 'password'=>'admin123')); |
|
9 | 9 | $SugarAPI->login(); |
10 | - $EP = $SugarAPI->favorite('Accounts',$record_id); |
|
10 | + $EP = $SugarAPI->favorite('Accounts', $record_id); |
|
11 | 11 | $response = $EP->execute()->getResponse()->getBody(); |
12 | 12 | |
13 | 13 | print_r($response); |
14 | 14 | |
15 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
15 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
16 | 16 | print $ex->getMessage(); |
17 | 17 | } |
18 | 18 |
@@ -21,18 +21,18 @@ |
||
21 | 21 | if ($response->getStatus()=='200'){ |
22 | 22 | $record = $response->getBody(); |
23 | 23 | print_r($response); |
24 | - }else{ |
|
24 | + } else{ |
|
25 | 25 | print_r($upload->getRequest()); |
26 | 26 | echo "Failed to Update Note with File<br>"; |
27 | 27 | echo "Response: ".$response->getStatus()."<br>"; |
28 | 28 | print_r($response->getBody()); |
29 | 29 | } |
30 | - }else{ |
|
30 | + } else{ |
|
31 | 31 | echo "Failed to create Note<br>"; |
32 | 32 | echo "Response: ".$response->getStatus()."<br>"; |
33 | 33 | print_r($response->getBody()); |
34 | 34 | } |
35 | 35 | |
36 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
36 | +} catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
37 | 37 | print $ex->getMessage(); |
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
4 | 4 | |
5 | 5 | try{ |
6 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/',array('username' => 'admin','password'=>'asdf')); |
|
6 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password'=>'asdf')); |
|
7 | 7 | $SugarAPI->login(); |
8 | 8 | $EP = $SugarAPI->createRecord('Notes')->data(array('name' => 'Test Note'))->execute(); |
9 | 9 | $response = $EP->getResponse(); |
10 | 10 | if ($response->getStatus()=='200'){ |
11 | 11 | $record = $response->getBody(); |
12 | 12 | |
13 | - $upload = $SugarAPI->attachFile('Notes',$record->id,'filename')->data(array( |
|
13 | + $upload = $SugarAPI->attachFile('Notes', $record->id, 'filename')->data(array( |
|
14 | 14 | 'filename' => __DIR__.'/testfile.txt;filename=testfile.txt' |
15 | 15 | ))->execute(); |
16 | 16 | $response = $upload->getResponse(); |
@@ -29,6 +29,6 @@ discard block |
||
29 | 29 | print_r($response->getBody()); |
30 | 30 | } |
31 | 31 | |
32 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
32 | +}catch (\SugarAPI\SDK\Exception\SDKException $ex){ |
|
33 | 33 | print $ex->getMessage(); |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -39,31 +39,31 @@ |
||
39 | 39 | $response = $deleteRecord->getResponse()->getBody(); |
40 | 40 | echo "Deleted Record <br>"; |
41 | 41 | print_r($response); |
42 | - }else{ |
|
42 | + } else{ |
|
43 | 43 | echo "Failed to Delete record<br>"; |
44 | 44 | echo "Response: ".$response->getStatus()."<br>"; |
45 | 45 | print_r($response->getBody()); |
46 | 46 | } |
47 | - }else{ |
|
47 | + } else{ |
|
48 | 48 | print_r($updateRecord->getRequest()); |
49 | 49 | echo "Failed to Update record<br>"; |
50 | 50 | echo "Response: ".$response->getStatus()."<br>"; |
51 | 51 | print_r($response->getBody()); |
52 | 52 | } |
53 | - }else{ |
|
53 | + } else{ |
|
54 | 54 | echo "Failed to retrieve record<br>"; |
55 | 55 | echo "Response: ".$response->getStatus()."<br>"; |
56 | 56 | print_r($response->getBody()); |
57 | 57 | } |
58 | - }else{ |
|
58 | + } else{ |
|
59 | 59 | echo "Response: ".$response->getStatus(); |
60 | 60 | print_r($response->getBody()); |
61 | 61 | } |
62 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
62 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
63 | 63 | echo "Auth Options:<pre>"; |
64 | 64 | print_r($SugarAPI->getAuthOptions()); |
65 | 65 | echo "</pre> Error Message: "; |
66 | 66 | print $ex->getMessage(); |
67 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
67 | +} catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
68 | 68 | echo $ex->__toString(); |
69 | 69 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | |
4 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
4 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
5 | 5 | |
6 | 6 | try{ |
7 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7700/',array('username' => 'admin','password'=>'asdf')); |
|
7 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7700/', array('username' => 'admin', 'password'=>'asdf')); |
|
8 | 8 | $SugarAPI->login(); |
9 | 9 | $EP = $SugarAPI->filterRecords('Accounts'); |
10 | 10 | $response = $EP->execute()->getResponse(); |
11 | 11 | if ($response->getStatus()=='200'){ |
12 | 12 | $recordList = $response->getBody(); |
13 | - $max=count($recordList->records); |
|
13 | + $max = count($recordList->records); |
|
14 | 14 | echo "Found $max records from Filter Records request. <br>"; |
15 | - $number = rand(0,$max); |
|
15 | + $number = rand(0, $max); |
|
16 | 16 | $randomRecord = $recordList->records[$number]; |
17 | 17 | echo "Choose random record #$number, with ID: ".$randomRecord->id." <br>"; |
18 | 18 | |
19 | - $getRecord = $SugarAPI->getRecord('Accounts',$randomRecord->id)->data(array( |
|
19 | + $getRecord = $SugarAPI->getRecord('Accounts', $randomRecord->id)->data(array( |
|
20 | 20 | 'fields' => 'name' |
21 | 21 | ))->execute(); |
22 | 22 | $response = $getRecord->getResponse(); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | echo "Retrieved Record <br>"; |
25 | 25 | $randomRecord = $getRecord->getResponse()->getBody(); |
26 | 26 | |
27 | - $updateRecord = $SugarAPI->updateRecord('Accounts',$randomRecord->id)->data(array( |
|
27 | + $updateRecord = $SugarAPI->updateRecord('Accounts', $randomRecord->id)->data(array( |
|
28 | 28 | 'name' => 'Updated Record Name' |
29 | 29 | ))->execute(); |
30 | 30 | $response = $updateRecord->getResponse(); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | echo "Updated Record <br>"; |
34 | 34 | print_r($randomRecord); |
35 | 35 | |
36 | - $deleteRecord = $SugarAPI->deleteRecord('Accounts',$randomRecord->id)->execute(); |
|
36 | + $deleteRecord = $SugarAPI->deleteRecord('Accounts', $randomRecord->id)->execute(); |
|
37 | 37 | $response = $deleteRecord->getResponse(); |
38 | 38 | if ($response->getStatus()=='200'){ |
39 | 39 | $response = $deleteRecord->getResponse()->getBody(); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | echo "Response: ".$response->getStatus(); |
60 | 60 | print_r($response->getBody()); |
61 | 61 | } |
62 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
62 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
63 | 63 | echo "Auth Options:<pre>"; |
64 | 64 | print_r($SugarAPI->getAuthOptions()); |
65 | 65 | echo "</pre> Error Message: "; |
66 | 66 | print $ex->getMessage(); |
67 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
67 | +}catch (\SugarAPI\SDK\Exception\SDKException $ex){ |
|
68 | 68 | echo $ex->__toString(); |
69 | 69 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | if ($response->getStatus()=='200'){ |
12 | 12 | $recordList = $response->getBody(); |
13 | 13 | $max=count($recordList->records); |
14 | - echo "Found $max records from Filter Records request. <br>"; |
|
14 | + echo "found $max records from Filter Records request. <br>"; |
|
15 | 15 | $number = rand(0,$max); |
16 | 16 | $randomRecord = $recordList->records[$number]; |
17 | 17 | echo "Choose random record #$number, with ID: ".$randomRecord->id." <br>"; |
@@ -19,6 +19,6 @@ |
||
19 | 19 | print_r($getResponse->getBody()); |
20 | 20 | } |
21 | 21 | |
22 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
22 | +} catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
23 | 23 | print $ex->getMessage(); |
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
3 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
4 | 4 | |
5 | 5 | try{ |
6 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/',array('username' => 'admin','password'=>'asdf')); |
|
6 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Pro/7621/', array('username' => 'admin', 'password'=>'asdf')); |
|
7 | 7 | $SugarAPI->login(); |
8 | 8 | $EP = $SugarAPI->createRecord('Accounts'); |
9 | 9 | $EP->data(array( |
@@ -13,12 +13,12 @@ discard block |
||
13 | 13 | $response = $EP->execute()->getResponse(); |
14 | 14 | if ($response->getStatus()=='200'){ |
15 | 15 | $record = $response->getBody(); |
16 | - $EP2 = $SugarAPI->getRecord('Accounts',$record->id)->data(array('fields' => 'name,email1')); |
|
16 | + $EP2 = $SugarAPI->getRecord('Accounts', $record->id)->data(array('fields' => 'name,email1')); |
|
17 | 17 | $getResponse = $EP2->execute()->getResponse(); |
18 | 18 | print $EP2->getUrl(); |
19 | 19 | print_r($getResponse->getBody()); |
20 | 20 | } |
21 | 21 | |
22 | -}catch(\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
22 | +}catch (\SugarAPI\SDK\Exception\AuthenticationException $ex){ |
|
23 | 23 | print $ex->getMessage(); |
24 | 24 | } |
25 | 25 | \ No newline at end of file |