Skip to content

Commit 1ca0243

Browse files
author
Puneet Khushwani
committed
remove support for handling patch versions and impose hard checks on supported API versions.
1 parent 802be60 commit 1ca0243

2 files changed

Lines changed: 6 additions & 94 deletions

File tree

src/Lib/Request.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,6 @@ private function sanitizeApiBaseUrl($apiBaseUrl)
137137
$apiBaseUrl .= '/';
138138
}
139139

140-
$buffer = explode('/', $apiBaseUrl);
141-
142-
//if $apiBaseUrl had a patch version ex. 'v1.0.0', we would need to remove it to ex. 'v1.0'
143-
$versionStr = $buffer[sizeof($buffer)-2];
144-
$dotCount = substr_count($versionStr, '.');
145-
if ($dotCount == 2) {
146-
$pattern = '/^(.+)(\.\d{1,3})(\/{0,1})$/';
147-
$replacement = '${1}${3}';
148-
$apiBaseUrl = preg_replace($pattern, $replacement, $apiBaseUrl);
149-
}
150-
151140
return $apiBaseUrl;
152141

153142
}

src/OSTSdk.php

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -28,95 +28,18 @@ public function __construct(array $params)
2828
// Extract API version
2929
$apiEndpointVersion = explode('/', $params['apiBaseUrl'])[3];
3030

31-
$intApiVersion = $this->getIntApiVersion($apiEndpointVersion);
32-
3331
# Provide access to version specific API endpoints
34-
if ($intApiVersion >= $this->v1dot2IntApiVersion()) {
35-
throw new \Exception('Unsupported API Version (' . @$apiEndpointVersion . '). Please check for new versions of OSTSdk.');
36-
} elseif ($intApiVersion >= $this->v1dot1IntApiVersion()) {
37-
$this->services = new \OST\V1Dot1\Manifest($params);
38-
} elseif ($intApiVersion >= $this->v1IntApiVersion()) {
32+
if (is_null($apiEndpointVersion) || $apiEndpointVersion == '') {
33+
$this->services = new \OST\V0\Manifest($params);
34+
} elseif (strtolower($apiEndpointVersion) == 'v1') {
3935
$this->services = new \OST\V1\Manifest($params);
36+
} elseif (strtolower($apiEndpointVersion) == 'v1.1') {
37+
$this->services = new \OST\V1Dot1\Manifest($params);
4038
} else {
41-
$this->services = new \OST\V0\Manifest($params);
39+
throw new \Exception('Api endpoint is invalid');
4240
}
4341

4442
}
4543

46-
/**
47-
* from API Version string generate a integer
48-
*
49-
* @param string $apiEndpointVersion api version from the URL
50-
*
51-
* @throws \Exception
52-
*
53-
* @return int
54-
*/
55-
private function getIntApiVersion($apiEndpointVersion)
56-
{
57-
58-
if (empty($apiEndpointVersion)) {
59-
return $this->v0IntApiVersion();
60-
}
61-
62-
// apply regex match to check if version is in valid format
63-
preg_match('/^v(\d{1,3})\.?(\d{0,3})\.?(\*|\d{0,3})$/', $apiEndpointVersion, $matches, PREG_OFFSET_CAPTURE);
64-
65-
if (empty($matches)) {
66-
throw new \Exception('Api version ' . $apiEndpointVersion . ' is invalid');
67-
}
68-
69-
$intApiVersion = 0;
70-
71-
$intApiVersion += (int)$matches[1][0] * 1000000;
72-
73-
$intApiVersion += (empty($matches[2][0]) ? 0 : (int)$matches[2][0] * 1000);
74-
75-
$intApiVersion += (empty($matches[3][0]) ? 0 : (int)$matches[3][0]);
76-
77-
return $intApiVersion;
78-
79-
}
80-
81-
/**
82-
* Int API Version for V0
83-
*
84-
* @return int
85-
*/
86-
private function v0IntApiVersion()
87-
{
88-
return 0;
89-
}
90-
91-
/**
92-
* Int API Version for V1.0
93-
*
94-
* @return int
95-
*/
96-
private function v1IntApiVersion()
97-
{
98-
return 1000000;
99-
}
100-
101-
/**
102-
* Int API Version for V1.1
103-
*
104-
* @return int
105-
*/
106-
private function v1dot1IntApiVersion()
107-
{
108-
return 1001000;
109-
}
110-
111-
/**
112-
* Int API Version for V1.2
113-
*
114-
* @return int
115-
*/
116-
private function v1dot2IntApiVersion()
117-
{
118-
return 1002000;
119-
}
120-
12144

12245
}

0 commit comments

Comments
 (0)