Skip to content

Commit 24f47b1

Browse files
author
Puneet Khushwani
committed
removed support for patch API versions and added hard checks on API versions
1 parent 4362da7 commit 24f47b1

File tree

2 files changed

+11
-51
lines changed

2 files changed

+11
-51
lines changed

lib/ost-sdk-ruby/saas/base.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ def sanitize_api_base_url(api_base_url)
6363

6464
api_base_url = api_base_url.gsub(/\/$/, '') # remove trailing slash
6565

66-
version_str = api_base_url.split('/')[-1]
67-
68-
return api_base_url unless version_str.include?('v')
69-
70-
buffer = version_str.split('.')
71-
if buffer.length == 3 # dot count in version == 2 ie. version had a patch version ex. v1.0.0
72-
regex_match_rsp = /^(.+)(\.\d{1,3})(\/{0,1})$/.match(api_base_url)
73-
api_base_url = regex_match_rsp[1]
74-
end
75-
7666
return api_base_url
7767

7868
end

lib/ost-sdk-ruby/saas/services.rb

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,59 +31,29 @@ def initialize(params)
3131

3232
def set_manifest(params)
3333

34-
int_api_version = extract_integer_api_version(params[:api_base_url])
34+
api_version = extract_api_version(params[:api_base_url])
3535

3636
# Provide access to version specific API endpoints
37-
if int_api_version >= v1dot2_int_api_version
38-
fail 'Unsupported API Version. Please check for new versions of SDK.'
39-
elsif int_api_version >= v1dot1_int_api_version
40-
@services = OSTSdk::Saas::V1Dot1::Services.new(params)
41-
elsif int_api_version >= v1_int_api_version
42-
@services = OSTSdk::Saas::V1::Services.new(params)
43-
else
37+
if api_version == ''
4438
# puts("You are using an deprecated version of OST API. Please update to the latest version.")
4539
@services = OSTSdk::Saas::V0::Services.new(params)
40+
elsif api_version == 'v1'
41+
@services = OSTSdk::Saas::V1::Services.new(params)
42+
elsif api_version == 'v1.1'
43+
@services = OSTSdk::Saas::V1Dot1::Services.new(params)
44+
else
45+
fail 'Api endpoint is invalid'
4646
end
4747

4848
end
4949

50-
def extract_integer_api_version(api_base_url)
50+
def extract_api_version(api_base_url)
5151

5252
api_version = ((api_base_url || '').split("/")[3] || '').downcase
53-
return v0_int_api_version if api_version == ''
54-
55-
regex_match_rsp = /^v(\d{1,3})\.?(\d{0,3})\.?(\*|\d{0,3})$/.match(api_version)
56-
fail "invalid version string #{api_version}" if regex_match_rsp.nil?
57-
58-
int_api_version = 0
59-
60-
# add API major version
61-
int_api_version += regex_match_rsp[1].to_i * 1000000
62-
63-
# add API minor version
64-
int_api_version += (regex_match_rsp[2] == '' ? 0 : regex_match_rsp[2].to_i * 1000)
53+
api_major_version = (api_version.split('.')[0] || '')
6554

66-
# add API Patch Version
67-
int_api_version += (regex_match_rsp[3] == '' ? 0 : regex_match_rsp[3].to_i)
68-
69-
return int_api_version
70-
71-
end
72-
73-
def v0_int_api_version
74-
0
75-
end
76-
77-
def v1_int_api_version
78-
1000000
79-
end
80-
81-
def v1dot1_int_api_version
82-
1001000
83-
end
55+
return api_major_version
8456

85-
def v1dot2_int_api_version
86-
1002000
8757
end
8858

8959
end

0 commit comments

Comments
 (0)