Skip to content

Commit 3146aeb

Browse files
committed
Merge pull request #45 from plotly/enterprise_signin_dev
Enterprise signin dev
2 parents e1c129e + 4c707a9 commit 3146aeb

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## MATLAB PLOTLY API WRAPPER 2.1.6
1+
## MATLAB PLOTLY API WRAPPER 2.1.7
22

33
### NUTSHELL:
44

plotly/plotly_user_aux/saveplotlyconfig.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ function saveplotlyconfig(plotly_domain,plotly_streaming_domain)
33
% Plotly config info are saved as JSON strings
44
% in ~/.plotly/.config
55

6+
% catch missing input arguments
7+
if nargin < 1
8+
error('plotly:saveconfig', ...
9+
['Incorrect number of inputs. Please save your configuration ', ...
10+
'as follows: >> saveplotlyconfig(plotly_domain,', ...
11+
'[optional]plotly_streaming_domain)']);
12+
end
13+
614
% if the config file exists, then load it up
715
try
816
config = loadplotlyconfig();
@@ -37,12 +45,16 @@ function saveplotlyconfig(plotly_domain,plotly_streaming_domain)
3745
'[email protected] for support.']);
3846
end
3947

48+
% get user credenitals
49+
[username, api_key] = signin;
4050

4151
switch nargin
4252
case 1
4353
config.plotly_domain = plotly_domain;
54+
signin(username, api_key, plotly_domain);
4455
case 2
4556
config.plotly_domain = plotly_domain;
57+
signin(username, api_key, plotly_domain);
4658
config.plotly_streaming_domain= plotly_streaming_domain;
4759
otherwise %if neither endpoints are specified, no worries!
4860
end

plotly/plotly_user_aux/saveplotlycredentials.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ function saveplotlycredentials(username, api_key, stream_ids)
33
% Plotly credentials are saved as JSON strings
44
% in ~/.plotly/.credentials
55

6+
% catch missing input arguments
7+
if nargin < 2
8+
error('plotly:savecredentials', ...
9+
['Incorrect number of inputs. Please save your credentials ', ...
10+
'as follows: >> saveplotlycredentials(username, api_key,', ...
11+
'[optional]stream_ids)']);
12+
end
13+
614
% if the credentials file exists, then load it up
715
try
816
creds = loadplotlycredentials();
@@ -45,9 +53,6 @@ function saveplotlycredentials(username, api_key, stream_ids)
4553
creds.username = username;
4654
creds.api_key = api_key;
4755
creds.stream_ids = stream_ids;
48-
otherwise %need to specify both the username and api_key
49-
error('plotly:savecredentials',...
50-
'Please specify your username and api_key');
5156
end
5257

5358
creds_string = m2json(creds);
@@ -56,4 +61,7 @@ function saveplotlycredentials(username, api_key, stream_ids)
5661
fprintf(fileIDCred,'%s',creds_string);
5762
fclose(fileIDCred);
5863

64+
%signin using newly saved credentials
65+
signin(username, api_key);
66+
5967
end

plotlysetup.m

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ function plotlysetup(username, api_key, varargin)
139139

140140
try %save user credentials
141141
fprintf('Saving username/api_key credentials ... ');
142-
saveplotlycredentials(username,api_key);
142+
143+
%update: as of v.2.1.7, This also signs in the user
144+
saveplotlycredentials(username, api_key);
145+
143146
%worked!
144147
fprintf('Done\n');
145148
catch exception %writing credentials file permission problem catch...
@@ -168,13 +171,19 @@ function plotlysetup(username, api_key, varargin)
168171

169172
if strcmp(varargin{n},'stream_ids')
170173
fprintf('Saving stream_ids credentials ... ');
171-
saveplotlycredentials(username,api_key,varargin{n+1});
174+
175+
%update: as of v.2.1.7, This also signs in the user
176+
saveplotlycredentials(username, api_key, varargin{n+1});
177+
172178
%worked!
173179
fprintf('Done\n');
174180
end
175181
if strcmp(varargin{n},'plotly_domain')
176182
fprintf('Saving plotly_domain configuration ... ');
183+
184+
%update: as of v.2.1.7, This also signs in the user
177185
saveplotlyconfig(varargin{n+1});
186+
178187
%worked!
179188
fprintf('Done\n');
180189
end
@@ -185,7 +194,10 @@ function plotlysetup(username, api_key, varargin)
185194
catch
186195
config.plotly_domain = '';
187196
end
197+
198+
%update: as of v.2.1.7, This also signs in the user
188199
saveplotlyconfig(config.plotly_domain,varargin{n+1});
200+
189201
%worked!
190202
fprintf('Done\n');
191203
end
@@ -195,9 +207,6 @@ function plotlysetup(username, api_key, varargin)
195207
fprintf(['\n\n' exception.identifier exception.message '\n\n']);
196208
end
197209

198-
%sign in the user
199-
signin(username,api_key);
200-
201210
%greet the people!
202211
fprintf('\nWelcome to Plotly! If you are new to Plotly please enter: >> plotlyhelp to get started!\n\n')
203212

@@ -210,7 +219,10 @@ function plotlysetup(username, api_key, varargin)
210219
'the Plotly folder to your MATLAB path manually by running: \n\n',...
211220
'>> plotly_path = fullfile(pwd, ''plotly'')\n',...
212221
'>> addpath(genpath(plotly_path))\n\n',...
213-
'Questions? Chuck@plotly'];
214-
222+
'You can save your credentials by running:\n\n', ...
223+
'>>saveplotlycredentials(''your_username'', ''your_api_key'')\n\n',...
224+
'You can save your domain configuration by running:\n\n',...
225+
'>>saveplotlyconfig(''your_base_domain'')\n\n',...
226+
'Questions? Chuck@plotly\n\n'];
215227
end
216228

0 commit comments

Comments
 (0)