Skip to content

Commit d0cc3f9

Browse files
bronsolobronsolo
authored andcommitted
first getplotlygrid
first makeplotlydir
1 parent 59c0add commit d0cc3f9

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

plotly/getplotlygrid.m

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
function response = getplotlygrid(varargin)
2+
3+
%-initialize input-%
4+
response = '';
5+
6+
%-check correct input number-%
7+
if (0 > nargin) && (nargin > 1)
8+
errkey = 'gridGet:invalidInputs';
9+
error(errkey, gridmsg(errkey));
10+
end
11+
12+
%-gridID-%
13+
gridID = varargin{1}; %will handle plotlygrid and url input soon
14+
15+
%--user authentication--%
16+
[un, key, domain] = signin;
17+
18+
if isempty(un) || isempty(key)
19+
errkey = 'gridAuthentication:credentialsNotFound';
20+
error(errkey,gridmsg(errkey));
21+
end
22+
23+
%-endpoint-%
24+
endpoint = [domain '/v2/grids/' gridID];
25+
26+
%-request-%
27+
request = 'GET';
28+
29+
%-encoding-%
30+
encoder = sun.misc.BASE64Encoder();
31+
encoded_un_key = char(encoder.encode(java.lang.String([un, ':', key]).getBytes()));
32+
33+
%-headers-%
34+
headers = struct('name', {'Authorization','plotly_client_platform','content-type','accept'},...
35+
'value', {['Basic ' encoded_un_key], 'MATLAB', 'application/json','*/*'});
36+
37+
%-make call-%
38+
resp = urlread2(endpoint, request , '', headers);
39+
40+
if ~isempty(resp)
41+
42+
%-check response-%
43+
response_handler(resp);
44+
45+
%-structure resp-%
46+
response = loadjson(resp);
47+
end
48+
49+
end

plotly/makeplotlydir.m

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function response = makeplotlydir(folder_path)
2+
3+
%-initialize input-%
4+
response = '';
5+
6+
%--user authentication--%
7+
[un, key, domain] = signin;
8+
9+
if isempty(un) || isempty(key)
10+
errkey = 'gridAuthentication:credentialsNotFound';
11+
error(errkey,gridmsg(errkey));
12+
end
13+
14+
%-input coniditioning-%
15+
if strcmp(folder_path(end),'/')
16+
folder_path = folder_path(1:end);
17+
end
18+
19+
%-get path and file-%
20+
[parent_path, filename] = fileparts(folder_path);
21+
22+
%-payload-%
23+
if isempty(parent_path)
24+
payload.parent = '-1';
25+
else
26+
payload.parent_path = ['/' parent_path];
27+
end
28+
29+
payload.name = filename;
30+
31+
%-endpoint-%
32+
endpoint = [domain '/v2/folders'];
33+
34+
%-request-%
35+
request = 'POST';
36+
37+
%-encoding-%
38+
encoder = sun.misc.BASE64Encoder();
39+
encoded_un_key = char(encoder.encode(java.lang.String([un, ':', key]).getBytes()));
40+
41+
%-headers-%
42+
headers = struct('name', {'Authorization','plotly_client_platform','content-type','accept'},...
43+
'value', {['Basic ' encoded_un_key], 'MATLAB', 'application/json','*/*'});
44+
45+
%-make call-%
46+
resp = urlread2(endpoint, request , m2json(payload) , headers);
47+
48+
if ~isempty(resp)
49+
50+
%-check response-%
51+
response_handler(resp);
52+
53+
%-structure resp-%
54+
response = loadjson(resp);
55+
end
56+
57+
end

0 commit comments

Comments
 (0)