Skip to content

Commit

Permalink
issue-21: Add version check function and update initializer to run ch…
Browse files Browse the repository at this point in the history
…eckVersion at the beginning
  • Loading branch information
IslaL committed Jun 10, 2024
1 parent 3789819 commit f0465f7
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
33 changes: 33 additions & 0 deletions onc/+util/checkVersion.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function isLatestVersion = checkVersion()
url = 'https://github.com/OceanNetworksCanada/api-matlab-client/releases/latest';
isLatestVersion = 0;
try
% get latest version
releaseInfo = webread(url);
versionPattern = '<title>Release (\d+\.\d+\.\d+)';
version = regexp(releaseInfo, versionPattern, 'tokens', 'once');
latestVersion = version{1};
% get local version
librariesVersion = ver;
localVersion ='0.0.0';
for i = librariesVersion
if strcmp(i.Name,'Ocean Networks Canada API Client Library')
localVersion = i.Version;
break;
end
end

% compare
if ~strcmp(localVersion, latestVersion)
[oncFolderPath, ~, ~] = fileparts(which('Onc'));
localFilePath = [oncFolderPath '\..\doc\UpdateInstruction.html'];
formattedPath = ['file:///', strrep(localFilePath, '\', '/')];
link = sprintf('<a href="%s">How to update this library</a>', formattedPath);
warning(['You are using an outdated version(%s) of the library. Update to the latest version(%s) to avoid potential errors. ' ...
'For instructions on updating to the latest version, please visit: %s'], localVersion, latestVersion, link);
else
isLatestVersion = 1;
end
catch ME
% do nothing
end
21 changes: 21 additions & 0 deletions onc/Contents.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% Ocean Networks Canada API Client Library
% Version 2.2.0 10-Jun-2024
%
% Functions
% +onc/OncDiscovery - Contains the functionality that wraps the API discovery services
% +onc/OncDelivery - Contains the functionality that wraps the API data product delivery services. To be inherited by the Onc class
% +onc/OncRealTime - Contains the functionality that wraps API real-time services.
% +onc/OncArchive - Contains the functionality that wraps API archivefile services
%
% Live Scripts
% examples/OncDiscoveryLocations.mat - Example Usage of OncDiscovery Location Service
% examples/OncDiscoveryProperties.mat - Example Usage of OncDiscovery Properties Service
% examples/OncDiscoveryDataProducts.mat - Example Usage of OncDiscovery DataProducts Service
% examples/OncDiscoveryDeployments.mat - Example Usage of OncDiscovery Deployments Service
% examples/OncDiscoveryDeviceCategories.mat - Example Usage of OncDiscovery Device Categories Service
% examples/OncDiscoveryDevices.mat - Example Usage of OncDiscovery Devices Service
% examples/OncRealTime.mat - Example Usage of OncRealTime Service
% examples/OncDeliveryDataProducts.mat - Example Usage of OncDelivery Service
% examples/OncArchive.mat - Example Usage of OncArchive Service
%
% Copyright 2024, ONC Data Team
41 changes: 28 additions & 13 deletions onc/Onc.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef Onc < onc.OncDiscovery & onc.OncDelivery & onc.OncRealTime & onc.OncArchive
%% ONC Facilitates access to Ocean Networks Canada's data through the Oceans 2.0 API.
% For detailed information and usage examples, visit our official documentation
% at https://wiki.oceannetworks.ca/display/CLmatlab
%% ONC Facilitates access to Ocean Networks Canada's data through the Oceans 3.0 API.
% For detailed information and usage examples, run doc command or visit MATLAB's help browser
% then find Ocean Networks Canada API Client under supplemental software
%
% ONC Properties:
% token - User token, can be obtained at: https://data.oceannetworks.ca/Profile
Expand Down Expand Up @@ -63,20 +63,33 @@
end

methods (Access = public)
%% The ONC class
% 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.
% Create an ONC object to access this library’s functionalities.
% Parameters:
% * token ([char]) - The ONC API token, which could be retrieved at https://data.oceannetworks.ca/Profile once logged in.
% * production (logical, optional, default = True) -
% Whether the ONC Production server URL is used for service requests.
% True: Use the production server.
% False: Use the internal ONC test server (reserved for ONC staff IP addresses).
% * showInfo (logical, optional, default = false) -
% Whether verbose script messages are displayed, such as request url and processing time information.
% True: Print all information and debug messages (intended for debugging).
% False: Only print information messages.
% * outPath ([char], optional, default = 'output') - Output path for downloaded files
% The directory will be created if it does not exist during the download.
% * timeout (int, optional, default = 60) - Number of seconds before a request to the API is canceled
%
% Returns: The Onc object created.
%
% Examples:
% onc = ONC("YOUR_TOKEN_HERE", 'showInfo', true, 'outPath', 'myOutPath');
%%
function this = Onc(token, varargin)
%% Class initializer
% All toolkit functionality must be invoked from an Onc object
%
% Onc(token, production=true, showInfo=false, outPath='output', timeout=60)
%
% * token: ([char]) User token
% - production: (logical) Send requests to the production server (otherwise use internal QA)
% - showInfo: (logical) Whether verbose debug messages are displayed
% - outPath: ([char]) Output path for downloaded files
% - timeout: (int) Number of seconds before a request to the API is canceled
%
% Returns: The Onc object created.

% parse inputs (can be named or positional)
p = inputParser;
addRequired(p, 'token', @ischar);
Expand Down Expand Up @@ -128,7 +141,9 @@
this.tree = temp.tree;
%These codes can then be used for input to onc.getDevices by
%providing the locationCodes


% check if it's running the latest version. If not, throw a warning
util.checkVersion;

end

Expand Down

0 comments on commit f0465f7

Please sign in to comment.