@@ -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 |
@@ -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; |
@@ -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\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 @@ 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 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | /** |
| 18 | 18 | * @inheritdoc |
| 19 | 19 | */ |
| 20 | - public function getBody() { |
|
| 20 | + public function getBody(){ |
|
| 21 | 21 | return json_decode($this->body); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -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 |