forked from jamesra/VikingPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryODataIDs.m
40 lines (32 loc) · 1002 Bytes
/
QueryODataIDs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function [ IDs, url] = QueryODataIDs( endpoint, query )
%QUERYODATAIDS Runs an OData query and returns a list of IDs
url = [endpoint '/' query];
disp(['Executing OData query: ' url]);
try
data = webread(url, ODataWebOptions());
catch ME
IDs = [];
switch ME.identifier
case 'MATLAB:webservices:HTTP404StatusCodeError'
disp('*** 404 error, query failed! ***');
otherwise
warning(getReport(ME));
rethrow(ME);
end
return;
end
if isstruct(data.value)
if isfield(data.value, 'ID')
IDs = horzcat(data.value.ID);
else
%Assume we only have one field, use that one
names = fieldnames(data.value);
IDs = vertcat(getfield(data.value, names(1)));
end
elseif isvector(data.value)
IDs = data.value;
end
if size(IDs, 2) > 1
IDs = IDs';
end
end