Skip to content

Commit

Permalink
SUPP-1025 - Issue #37 - Allow for v11 minor versions in API
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJ2324 committed Feb 6, 2019
1 parent ac1cdeb commit 3282072
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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
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 3282072

Please sign in to comment.