File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def initialize(params)
2222 fail 'missing API Key' if params [ :api_key ] . nil?
2323 fail 'missing API Secret' if params [ :api_secret ] . nil?
2424
25- params [ :api_base_url ] . gsub! ( / \/ $/ , '' ) # remove trailing slash
25+ params [ :api_base_url ] = sanitize_api_base_url ( params [ :api_base_url ] )
2626
2727 @http_helper = OSTSdk ::Util ::HTTPHelper . new ( params )
2828
@@ -51,6 +51,32 @@ def get_id!(params)
5151 id
5252 end
5353
54+ # Sanitize API Base URL
55+ #
56+ # Arguments:
57+ # params: (String)
58+ #
59+ # Returns:
60+ # api_base_url: (String)
61+ #
62+ def sanitize_api_base_url ( api_base_url )
63+
64+ api_base_url = api_base_url . gsub ( /\/ $/ , '' ) # remove trailing slash
65+
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+
76+ return api_base_url
77+
78+ end
79+
5480 end
5581
5682 end
You can’t perform that action at this time.
0 commit comments