Skip to content

Commit

Permalink
Merge pull request #41 from MichaelJ2324/master
Browse files Browse the repository at this point in the history
SUPP-1025 - Issue #37 - Allow for v11 minor versions in API
  • Loading branch information
crazytonyi authored Feb 6, 2019
2 parents 84a934e + 484c126 commit aecc3e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Client/Abstracts/AbstractSugarClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function setAPIUrl()
*/
public function setVersion($version)
{
$this->apiVersion = intval($version);
$this->apiVersion = $version;
$this->setAPIUrl();
return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Helpers
{
const API_VERSION = 10;
const API_URL = '/rest/v%d/';
const API_URL = '/rest/v%s/';

/**
* Given a sugarcrm server/instance generate the Rest/v10 API Url
Expand All @@ -19,8 +19,8 @@ class Helpers
public static function configureAPIURL($instance, $version = null)
{
$url = 0;
$version = ($version === null ? self::API_VERSION : intval($version));
$instance = preg_replace('/\/rest\/v\d+/', '', $instance);
$version = ($version === null ? self::API_VERSION : $version);
$instance = preg_replace('/\/rest\/v.+/', '', $instance);
$url = rtrim($instance,"/").sprintf(self::API_URL, $version);
if (preg_match('/^(http|https):\/\//i', $url) === 0) {
$url = "http://".$url;
Expand Down
3 changes: 3 additions & 0 deletions tests/Clients/AbstractSugarClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public function testSetVersion($Stub){
$Stub->setVersion(11);
$this->assertEquals("http://localhost/rest/v11/",$Stub->getAPIUrl());
$this->assertEquals(11,$Stub->getVersion());
$Stub->setVersion('11_4');
$this->assertEquals("http://localhost/rest/v11_4/",$Stub->getAPIUrl());
$this->assertEquals('11_4',$Stub->getVersion());
return $Stub;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Helpers/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function testConfigureAPIUrl()
$this->assertEquals('http://localhost/Sugar/Test/rest/v10/',Helpers::configureAPIURL('http://localhost/Sugar/Test/rest/v10/rest/v10/rest/v10','10'));
$this->assertEquals('http://localhost/SugarTest/rest/v10/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10',10));
$this->assertEquals('http://localhost/SugarTest/rest/v11/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10',11));
$this->assertEquals('http://localhost/SugarTest/rest/v11_1/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10','11_1'));

}

Expand Down

0 comments on commit aecc3e8

Please sign in to comment.