Skip to content

Commit f0465f7

Browse files
committed
issue-21: Add version check function and update initializer to run checkVersion at the beginning
1 parent 3789819 commit f0465f7

File tree

3 files changed

+82
-13
lines changed

3 files changed

+82
-13
lines changed

onc/+util/checkVersion.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function isLatestVersion = checkVersion()
2+
url = 'https://github.com/OceanNetworksCanada/api-matlab-client/releases/latest';
3+
isLatestVersion = 0;
4+
try
5+
% get latest version
6+
releaseInfo = webread(url);
7+
versionPattern = '<title>Release (\d+\.\d+\.\d+)';
8+
version = regexp(releaseInfo, versionPattern, 'tokens', 'once');
9+
latestVersion = version{1};
10+
% get local version
11+
librariesVersion = ver;
12+
localVersion ='0.0.0';
13+
for i = librariesVersion
14+
if strcmp(i.Name,'Ocean Networks Canada API Client Library')
15+
localVersion = i.Version;
16+
break;
17+
end
18+
end
19+
20+
% compare
21+
if ~strcmp(localVersion, latestVersion)
22+
[oncFolderPath, ~, ~] = fileparts(which('Onc'));
23+
localFilePath = [oncFolderPath '\..\doc\UpdateInstruction.html'];
24+
formattedPath = ['file:///', strrep(localFilePath, '\', '/')];
25+
link = sprintf('<a href="%s">How to update this library</a>', formattedPath);
26+
warning(['You are using an outdated version(%s) of the library. Update to the latest version(%s) to avoid potential errors. ' ...
27+
'For instructions on updating to the latest version, please visit: %s'], localVersion, latestVersion, link);
28+
else
29+
isLatestVersion = 1;
30+
end
31+
catch ME
32+
% do nothing
33+
end

onc/Contents.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
% Ocean Networks Canada API Client Library
2+
% Version 2.2.0 10-Jun-2024
3+
%
4+
% Functions
5+
% +onc/OncDiscovery - Contains the functionality that wraps the API discovery services
6+
% +onc/OncDelivery - Contains the functionality that wraps the API data product delivery services. To be inherited by the Onc class
7+
% +onc/OncRealTime - Contains the functionality that wraps API real-time services.
8+
% +onc/OncArchive - Contains the functionality that wraps API archivefile services
9+
%
10+
% Live Scripts
11+
% examples/OncDiscoveryLocations.mat - Example Usage of OncDiscovery Location Service
12+
% examples/OncDiscoveryProperties.mat - Example Usage of OncDiscovery Properties Service
13+
% examples/OncDiscoveryDataProducts.mat - Example Usage of OncDiscovery DataProducts Service
14+
% examples/OncDiscoveryDeployments.mat - Example Usage of OncDiscovery Deployments Service
15+
% examples/OncDiscoveryDeviceCategories.mat - Example Usage of OncDiscovery Device Categories Service
16+
% examples/OncDiscoveryDevices.mat - Example Usage of OncDiscovery Devices Service
17+
% examples/OncRealTime.mat - Example Usage of OncRealTime Service
18+
% examples/OncDeliveryDataProducts.mat - Example Usage of OncDelivery Service
19+
% examples/OncArchive.mat - Example Usage of OncArchive Service
20+
%
21+
% Copyright 2024, ONC Data Team

onc/Onc.m

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef Onc < onc.OncDiscovery & onc.OncDelivery & onc.OncRealTime & onc.OncArchive
2-
%% ONC Facilitates access to Ocean Networks Canada's data through the Oceans 2.0 API.
3-
% For detailed information and usage examples, visit our official documentation
4-
% at https://wiki.oceannetworks.ca/display/CLmatlab
2+
%% ONC Facilitates access to Ocean Networks Canada's data through the Oceans 3.0 API.
3+
% For detailed information and usage examples, run doc command or visit MATLAB's help browser
4+
% then find Ocean Networks Canada API Client under supplemental software
55
%
66
% ONC Properties:
77
% token - User token, can be obtained at: https://data.oceannetworks.ca/Profile
@@ -63,20 +63,33 @@
6363
end
6464

6565
methods (Access = public)
66+
%% The ONC class
67+
% The ONC class provides a wrapper for Oceans 3.0 API requests. All the client library’s functionality is provided as methods of this class.
68+
% Create an ONC object to access this library’s functionalities.
69+
% Parameters:
70+
% * token ([char]) - The ONC API token, which could be retrieved at https://data.oceannetworks.ca/Profile once logged in.
71+
% * production (logical, optional, default = True) -
72+
% Whether the ONC Production server URL is used for service requests.
73+
% True: Use the production server.
74+
% False: Use the internal ONC test server (reserved for ONC staff IP addresses).
75+
% * showInfo (logical, optional, default = false) -
76+
% Whether verbose script messages are displayed, such as request url and processing time information.
77+
% True: Print all information and debug messages (intended for debugging).
78+
% False: Only print information messages.
79+
% * outPath ([char], optional, default = 'output') - Output path for downloaded files
80+
% The directory will be created if it does not exist during the download.
81+
% * timeout (int, optional, default = 60) - Number of seconds before a request to the API is canceled
82+
%
83+
% Returns: The Onc object created.
84+
%
85+
% Examples:
86+
% onc = ONC("YOUR_TOKEN_HERE", 'showInfo', true, 'outPath', 'myOutPath');
87+
%%
6688
function this = Onc(token, varargin)
6789
%% Class initializer
6890
% All toolkit functionality must be invoked from an Onc object
6991
%
7092
% Onc(token, production=true, showInfo=false, outPath='output', timeout=60)
71-
%
72-
% * token: ([char]) User token
73-
% - production: (logical) Send requests to the production server (otherwise use internal QA)
74-
% - showInfo: (logical) Whether verbose debug messages are displayed
75-
% - outPath: ([char]) Output path for downloaded files
76-
% - timeout: (int) Number of seconds before a request to the API is canceled
77-
%
78-
% Returns: The Onc object created.
79-
8093
% parse inputs (can be named or positional)
8194
p = inputParser;
8295
addRequired(p, 'token', @ischar);
@@ -128,7 +141,9 @@
128141
this.tree = temp.tree;
129142
%These codes can then be used for input to onc.getDevices by
130143
%providing the locationCodes
131-
144+
145+
% check if it's running the latest version. If not, throw a warning
146+
util.checkVersion;
132147

133148
end
134149

0 commit comments

Comments
 (0)