@@ -106,35 +106,14 @@ public BoxAPIConnection(String clientID, String clientSecret) {
106106 * Restores a BoxAPIConnection from a saved state.
107107 *
108108 * @see #save
109- * @param state the saved state that was created with {@link #save}.
110- * @return a restored API connection.
111- */
112- public static BoxAPIConnection restore (String state ) {
113- JsonObject json = JsonObject .readFrom (state );
114- String clientID = json .get ("clientID" ).asString ();
115- String clientSecret = json .get ("clientSecret" ).asString ();
116- String accessToken = json .get ("accessToken" ).asString ();
117- String refreshToken = json .get ("refreshToken" ).asString ();
118- long lastRefresh = json .get ("lastRefresh" ).asLong ();
119- long expires = json .get ("expires" ).asLong ();
120- String userAgent = json .get ("userAgent" ).asString ();
121- String tokenURL = json .get ("tokenURL" ).asString ();
122- String baseURL = json .get ("baseURL" ).asString ();
123- String baseUploadURL = json .get ("baseUploadURL" ).asString ();
124- boolean autoRefresh = json .get ("autoRefresh" ).asBoolean ();
125- int maxRequestAttempts = json .get ("maxRequestAttempts" ).asInt ();
126-
127- BoxAPIConnection api = new BoxAPIConnection (clientID , clientSecret , accessToken , refreshToken );
128- api .accessToken = accessToken ;
129- api .refreshToken = refreshToken ;
130- api .lastRefresh = lastRefresh ;
131- api .expires = expires ;
132- api .userAgent = userAgent ;
133- api .tokenURL = tokenURL ;
134- api .baseURL = baseURL ;
135- api .baseUploadURL = baseUploadURL ;
136- api .autoRefresh = autoRefresh ;
137- api .maxRequestAttempts = maxRequestAttempts ;
109+ * @param clientID the client ID to use with the connection.
110+ * @param clientSecret the client secret to use with the connection.
111+ * @param state the saved state that was created with {@link #save}.
112+ * @return a restored API connection.
113+ */
114+ public static BoxAPIConnection restore (String clientID , String clientSecret , String state ) {
115+ BoxAPIConnection api = new BoxAPIConnection (clientID , clientSecret );
116+ api .restore (state );
138117 return api ;
139118 }
140119
@@ -427,6 +406,37 @@ public void refresh() {
427406 this .refreshLock .writeLock ().unlock ();
428407 }
429408
409+ /**
410+ * Restores a saved connection state into this BoxAPIConnection.
411+ *
412+ * @see #save
413+ * @param state the saved state that was created with {@link #save}.
414+ */
415+ public void restore (String state ) {
416+ JsonObject json = JsonObject .readFrom (state );
417+ String accessToken = json .get ("accessToken" ).asString ();
418+ String refreshToken = json .get ("refreshToken" ).asString ();
419+ long lastRefresh = json .get ("lastRefresh" ).asLong ();
420+ long expires = json .get ("expires" ).asLong ();
421+ String userAgent = json .get ("userAgent" ).asString ();
422+ String tokenURL = json .get ("tokenURL" ).asString ();
423+ String baseURL = json .get ("baseURL" ).asString ();
424+ String baseUploadURL = json .get ("baseUploadURL" ).asString ();
425+ boolean autoRefresh = json .get ("autoRefresh" ).asBoolean ();
426+ int maxRequestAttempts = json .get ("maxRequestAttempts" ).asInt ();
427+
428+ this .accessToken = accessToken ;
429+ this .refreshToken = refreshToken ;
430+ this .lastRefresh = lastRefresh ;
431+ this .expires = expires ;
432+ this .userAgent = userAgent ;
433+ this .tokenURL = tokenURL ;
434+ this .baseURL = baseURL ;
435+ this .baseUploadURL = baseUploadURL ;
436+ this .autoRefresh = autoRefresh ;
437+ this .maxRequestAttempts = maxRequestAttempts ;
438+ }
439+
430440 /**
431441 * Notifies a refresh event to all the listeners.
432442 */
@@ -485,8 +495,6 @@ public void setRequestInterceptor(RequestInterceptor interceptor) {
485495 */
486496 public String save () {
487497 JsonObject state = new JsonObject ()
488- .add ("clientID" , this .clientID )
489- .add ("clientSecret" , this .clientSecret )
490498 .add ("accessToken" , this .accessToken )
491499 .add ("refreshToken" , this .refreshToken )
492500 .add ("lastRefresh" , this .lastRefresh )
0 commit comments