@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Request\Abstracts\AbstractRequest; |
6 | 6 | |
7 | -class POST extends AbstractRequest{ |
|
7 | +class POST extends AbstractRequest { |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * @inheritdoc |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * JSON Encode Body |
33 | 33 | * @inheritdoc |
34 | 34 | */ |
35 | - public function setBody($body) { |
|
35 | + public function setBody($body){ |
|
36 | 36 | return parent::setBody(json_encode($body)); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use SugarAPI\SDK\Response\Interfaces\ResponseInterface; |
6 | 6 | |
7 | -abstract class AbstractResponse implements ResponseInterface{ |
|
7 | +abstract class AbstractResponse implements ResponseInterface { |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Full Curl Response |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected $error; |
38 | 38 | |
39 | - public function __construct($curlResponse,$curlRequest){ |
|
39 | + public function __construct($curlResponse, $curlRequest){ |
|
40 | 40 | $this->CurlResponse = $curlResponse; |
41 | - if ($this->checkErrors($curlRequest)) { |
|
41 | + if ($this->checkErrors($curlRequest)){ |
|
42 | 42 | $this->extractResponse($curlRequest); |
43 | 43 | } |
44 | 44 | $this->setStatus($curlRequest); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param $curlRequest - Curl resource |
50 | 50 | */ |
51 | 51 | protected function setStatus($curlRequest){ |
52 | - $this->status = curl_getinfo($curlRequest,CURLINFO_HTTP_CODE); |
|
52 | + $this->status = curl_getinfo($curlRequest, CURLINFO_HTTP_CODE); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param $curlRequest |
58 | 58 | */ |
59 | 59 | protected function extractResponse($curlRequest){ |
60 | - $header_size = curl_getinfo($curlRequest,CURLINFO_HEADER_SIZE); |
|
60 | + $header_size = curl_getinfo($curlRequest, CURLINFO_HEADER_SIZE); |
|
61 | 61 | $this->headers = substr($this->CurlResponse, 0, $header_size); |
62 | 62 | $this->body = substr($this->CurlResponse, $header_size); |
63 | 63 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return bool |
69 | 69 | */ |
70 | 70 | protected function checkErrors($curlRequest){ |
71 | - if (curl_errno($curlRequest) !== CURLE_OK) { |
|
71 | + if (curl_errno($curlRequest)!==CURLE_OK){ |
|
72 | 72 | $this->error = curl_error($curlRequest); |
73 | 73 | return false; |
74 | 74 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | /** |
86 | 86 | * @inheritdoc |
87 | 87 | */ |
88 | - public function getBody() { |
|
88 | + public function getBody(){ |
|
89 | 89 | return $this->body; |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * @inheritdoc |
94 | 94 | */ |
95 | - public function getHeaders() { |
|
95 | + public function getHeaders(){ |
|
96 | 96 | return $this->headers; |
97 | 97 | } |
98 | 98 |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | */ |
19 | 19 | protected $destinationPath; |
20 | 20 | |
21 | - public function __construct($curlResponse, $curlRequest,$destination = null) { |
|
21 | + public function __construct($curlResponse, $curlRequest, $destination = null){ |
|
22 | 22 | parent::__construct($curlResponse, $curlRequest); |
23 | 23 | $this->extractFileName(); |
24 | - if (!empty($destination)) { |
|
24 | + if (!empty($destination)){ |
|
25 | 25 | $this->setupDestination($destination); |
26 | 26 | $this->writeFile(); |
27 | 27 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | if (empty($destination)){ |
36 | 36 | $destination = sys_get_temp_dir().'/SugarAPI'; |
37 | 37 | if (!file_exists($destination)){ |
38 | - mkdir($destination,0777); |
|
38 | + mkdir($destination, 0777); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | $this->destinationPath = $destination; |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | * Extract the filename from the Headers, and store it in filename property |
46 | 46 | */ |
47 | 47 | protected function extractFileName(){ |
48 | - foreach (explode("\r\n",$this->headers) as $header) |
|
48 | + foreach (explode("\r\n", $this->headers) as $header) |
|
49 | 49 | { |
50 | - if (strpos($header,'filename')!==FALSE){ |
|
51 | - $this->fileName = substr($header,(strpos($header,"\"")+1),-1); |
|
50 | + if (strpos($header, 'filename')!==FALSE){ |
|
51 | + $this->fileName = substr($header, (strpos($header, "\"")+1), -1); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * Write the downloaded file |
66 | 66 | */ |
67 | 67 | protected function writeFile(){ |
68 | - $fileHandle = fopen($this->file(),'w+'); |
|
69 | - fwrite($fileHandle,$this->body); |
|
68 | + $fileHandle = fopen($this->file(), 'w+'); |
|
69 | + fwrite($fileHandle, $this->body); |
|
70 | 70 | fclose($fileHandle); |
71 | 71 | } |
72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return string |
76 | 76 | */ |
77 | 77 | public function file(){ |
78 | - return rtrim($this->destinationPath,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$this->fileName; |
|
78 | + return rtrim($this->destinationPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$this->fileName; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | } |
82 | 82 | \ No newline at end of file |
@@ -1,13 +1,13 @@ 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 | $recordID = 'ac096703-67fd-8dd2-980a-57097932f07a'; |
6 | 6 | |
7 | 7 | try{ |
8 | - $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/',array('username' => 'admin','password'=>'asdf')); |
|
8 | + $SugarAPI = new \SugarAPI\SDK\SugarAPI('instances.this/Ent/7700/', array('username' => 'admin', 'password'=>'asdf')); |
|
9 | 9 | $SugarAPI->login(); |
10 | - $EP = $SugarAPI->getAttachment('Notes',$recordID,'filename')->downloadTo(__DIR__)->execute(); |
|
10 | + $EP = $SugarAPI->getAttachment('Notes', $recordID, 'filename')->downloadTo(__DIR__)->execute(); |
|
11 | 11 | $response = $EP->getResponse(); |
12 | 12 | if ($response->getStatus()=='200'){ |
13 | 13 | if (file_exists($response->file())){ |
@@ -20,6 +20,6 @@ discard block |
||
20 | 20 | print_r($response->getBody()); |
21 | 21 | } |
22 | 22 | |
23 | -}catch(\SugarAPI\SDK\Exception\SDKException $ex){ |
|
23 | +}catch (\SugarAPI\SDK\Exception\SDKException $ex){ |
|
24 | 24 | print $ex->getMessage(); |
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -17,8 +17,8 @@ |
||
17 | 17 | /** |
18 | 18 | * @inheritdoc |
19 | 19 | */ |
20 | - public function getBody($asArray = true) { |
|
21 | - return json_decode($this->body,$asArray); |
|
20 | + public function getBody($asArray = true){ |
|
21 | + return json_decode($this->body, $asArray); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | class EntryPointException extends SDKException { |
6 | 6 | |
7 | - public function __construct($message) { |
|
7 | + public function __construct($message){ |
|
8 | 8 | parent::__construct($message); |
9 | 9 | } |
10 | 10 |
@@ -8,8 +8,8 @@ |
||
8 | 8 | |
9 | 9 | protected $message = 'Authentication Exception [%s] occurred in SDK Client. Message: %s'; |
10 | 10 | |
11 | - public function __construct($message) { |
|
12 | - parent::__construct(sprintf($this->message,get_called_class(),$message)); |
|
11 | + public function __construct($message){ |
|
12 | + parent::__construct(sprintf($this->message, get_called_class(), $message)); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | } |
16 | 16 | \ No newline at end of file |
@@ -8,8 +8,8 @@ |
||
8 | 8 | |
9 | 9 | protected $message = 'EntryPoint Exception [%s] occurred on EntryPoint %s: %s'; |
10 | 10 | |
11 | - public function __construct($EntryPoint,$data) { |
|
12 | - parent::__construct(sprintf($this->message,get_called_class(),$EntryPoint,$data)); |
|
11 | + public function __construct($EntryPoint, $data){ |
|
12 | + parent::__construct(sprintf($this->message, get_called_class(), $EntryPoint, $data)); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | } |
16 | 16 | \ No newline at end of file |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | protected $accessToken; |
95 | 95 | |
96 | 96 | |
97 | - public function __construct($url,$options = array()){ |
|
97 | + public function __construct($url, $options = array()){ |
|
98 | 98 | $this->baseUrl = $url; |
99 | 99 | |
100 | - if (!empty($options)) { |
|
100 | + if (!empty($options)){ |
|
101 | 101 | $this->setOptions($options); |
102 | - }elseif(!$this->requiresOptions()){ |
|
102 | + }elseif (!$this->requiresOptions()){ |
|
103 | 103 | $this->configureURL(); |
104 | 104 | } |
105 | 105 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function setData($data){ |
123 | 123 | $this->Data = $data; |
124 | - if ($this->verifyData()) { |
|
124 | + if ($this->verifyData()){ |
|
125 | 125 | $this->Request->setBody($data); |
126 | 126 | } |
127 | 127 | return $this; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | /** |
131 | 131 | * @inheritdoc |
132 | 132 | */ |
133 | - public function setAuth($accessToken) { |
|
133 | + public function setAuth($accessToken){ |
|
134 | 134 | if ($this->authRequired()){ |
135 | 135 | $this->accessToken = $accessToken; |
136 | 136 | $this->Request->addHeader('OAuth-Token', $accessToken); |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @inheritdoc |
143 | 143 | * @throws InvalidURLException - When passed in URL contains $variables |
144 | 144 | */ |
145 | - public function setUrl($url) { |
|
145 | + public function setUrl($url){ |
|
146 | 146 | $this->Url = $url; |
147 | - if ($this->verifyUrl()) { |
|
147 | + if ($this->verifyUrl()){ |
|
148 | 148 | $this->Request->setURL($this->Url); |
149 | 149 | } |
150 | 150 | return $this; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * @inheritdoc |
155 | 155 | */ |
156 | - public function setRequest(RequestInterface $Request) { |
|
156 | + public function setRequest(RequestInterface $Request){ |
|
157 | 157 | $this->Request = $Request; |
158 | 158 | return $this; |
159 | 159 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | /** |
162 | 162 | * @inheritdoc |
163 | 163 | */ |
164 | - public function setResponse(ResponseInterface $Response) { |
|
164 | + public function setResponse(ResponseInterface $Response){ |
|
165 | 165 | $this->Response = $Response; |
166 | 166 | return $this; |
167 | 167 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | /** |
170 | 170 | * @inheritdoc |
171 | 171 | */ |
172 | - public function getModule() { |
|
172 | + public function getModule(){ |
|
173 | 173 | return $this->Module; |
174 | 174 | } |
175 | 175 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | /** |
216 | 216 | * @inheritdoc |
217 | 217 | */ |
218 | - public function authRequired() { |
|
218 | + public function authRequired(){ |
|
219 | 219 | return $this->_AUTH_REQUIRED; |
220 | 220 | } |
221 | 221 | |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * Override function for configuring Default Values on some EntryPoints to allow for short hand |
224 | 224 | */ |
225 | 225 | protected function configureData($data){ |
226 | - if (!empty($this->_REQUIRED_DATA)&&is_array($data)){ |
|
227 | - foreach($this->_REQUIRED_DATA as $property => $value){ |
|
226 | + if (!empty($this->_REQUIRED_DATA) && is_array($data)){ |
|
227 | + foreach ($this->_REQUIRED_DATA as $property => $value){ |
|
228 | 228 | if (!isset($data[$property])){ |
229 | 229 | $data[$property] = $value; |
230 | 230 | } |
@@ -240,18 +240,18 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function configureURL(){ |
242 | 242 | $url = $this->_URL; |
243 | - if ($this->requiresOptions()) { |
|
243 | + if ($this->requiresOptions()){ |
|
244 | 244 | $urlParts = explode("/", $this->_URL); |
245 | 245 | $o = 0; |
246 | - foreach ($urlParts as $key => $part) { |
|
247 | - if (strpos($part, "$") !== FALSE) { |
|
248 | - if (isset($this->Options[$o])) { |
|
246 | + foreach ($urlParts as $key => $part){ |
|
247 | + if (strpos($part, "$")!==FALSE){ |
|
248 | + if (isset($this->Options[$o])){ |
|
249 | 249 | $urlParts[$key] = $this->Options[$o]; |
250 | 250 | $o++; |
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
254 | - $url = implode($urlParts,"/"); |
|
254 | + $url = implode($urlParts, "/"); |
|
255 | 255 | } |
256 | 256 | $url = $this->baseUrl.$url; |
257 | 257 | $this->setUrl($url); |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | * @throws InvalidURLException |
264 | 264 | */ |
265 | 265 | protected function verifyUrl(){ |
266 | - $UrlArray = explode("?",$this->Url); |
|
267 | - if (strpos($UrlArray[0],"$") !== FALSE){ |
|
268 | - throw new InvalidURLException(get_called_class(),"Configured URL is ".$this->Url); |
|
266 | + $UrlArray = explode("?", $this->Url); |
|
267 | + if (strpos($UrlArray[0], "$")!==FALSE){ |
|
268 | + throw new InvalidURLException(get_called_class(), "Configured URL is ".$this->Url); |
|
269 | 269 | } |
270 | 270 | return true; |
271 | 271 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * @throws RequiredOptionsException |
277 | 277 | */ |
278 | 278 | protected function verifyOptions(){ |
279 | - $urlVarCount = substr_count($this->_URL,"$"); |
|
279 | + $urlVarCount = substr_count($this->_URL, "$"); |
|
280 | 280 | $optionCount = 0; |
281 | 281 | $optionCount += count($this->Options); |
282 | 282 | if ($urlVarCount!==$optionCount){ |
283 | - throw new RequiredOptionsException(get_called_class(),"URL requires $urlVarCount options."); |
|
283 | + throw new RequiredOptionsException(get_called_class(), "URL requires $urlVarCount options."); |
|
284 | 284 | } |
285 | 285 | return true; |
286 | 286 | } |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | * @throws RequiredDataException |
292 | 292 | */ |
293 | 293 | protected function verifyData(){ |
294 | - if (isset($this->_DATA_TYPE)||!empty($this->_DATA_TYPE)) { |
|
295 | - if (gettype($this->Data) !== $this->_DATA_TYPE) { |
|
296 | - throw new RequiredDataException(get_called_class(),"Valid DataType is {$this->_DATA_TYPE}"); |
|
294 | + if (isset($this->_DATA_TYPE) || !empty($this->_DATA_TYPE)){ |
|
295 | + if (gettype($this->Data)!==$this->_DATA_TYPE){ |
|
296 | + throw new RequiredDataException(get_called_class(), "Valid DataType is {$this->_DATA_TYPE}"); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | if (!empty($this->_REQUIRED_DATA)){ |
300 | 300 | $errors = array(); |
301 | - foreach($this->_REQUIRED_DATA as $property => $defaultValue){ |
|
301 | + foreach ($this->_REQUIRED_DATA as $property => $defaultValue){ |
|
302 | 302 | if (!isset($this->Data[$property])){ |
303 | 303 | $errors[] = $property; |
304 | 304 | } |
305 | 305 | } |
306 | 306 | if (count($errors)>0){ |
307 | - throw new RequiredDataException(get_called_class(),"Missing data for $errors"); |
|
307 | + throw new RequiredDataException(get_called_class(), "Missing data for $errors"); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | return true; |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @return bool |
316 | 316 | */ |
317 | 317 | protected function requiresOptions(){ |
318 | - return strpos($this->_URL,"$") !== FALSE?TRUE:FALSE; |
|
318 | + return strpos($this->_URL, "$")!==FALSE?TRUE:FALSE; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | } |
322 | 322 | \ No newline at end of file |