001package com.box.sdk; 002 003/** 004 * This API connection uses a shared link (along with an optional password) to authenticate with the Box API. It wraps a 005 * preexisting BoxAPIConnection in order to provide additional access to items that are accessible with a shared link. 006 */ 007public class SharedLinkAPIConnection extends BoxAPIConnection { 008 private final BoxAPIConnection wrappedConnection; 009 private final String sharedLink; 010 private final String sharedLinkPassword; 011 012 SharedLinkAPIConnection(BoxAPIConnection connection, String sharedLink) { 013 this(connection, sharedLink, null); 014 } 015 016 SharedLinkAPIConnection(BoxAPIConnection connection, String sharedLink, String sharedLinkPassword) { 017 //this is a hack to maintain backward compatibility and to prevent confusing the compiler 018 //between two possible BoxApiConnection constructors for super(null) 019 super(""); 020 021 this.wrappedConnection = connection; 022 this.sharedLink = sharedLink; 023 this.sharedLinkPassword = sharedLinkPassword; 024 } 025 026 @Override 027 public long getExpires() { 028 return this.wrappedConnection.getExpires(); 029 } 030 031 @Override 032 public void setExpires(long milliseconds) { 033 this.wrappedConnection.setExpires(milliseconds); 034 } 035 036 @Override 037 public String getBaseURL() { 038 return this.wrappedConnection.getBaseURL(); 039 } 040 041 @Override 042 public void setBaseURL(String baseURL) { 043 this.wrappedConnection.setBaseURL(baseURL); 044 } 045 046 @Override 047 public String getBaseUploadURL() { 048 return this.wrappedConnection.getBaseUploadURL(); 049 } 050 051 @Override 052 public void setBaseUploadURL(String baseUploadURL) { 053 this.wrappedConnection.setBaseUploadURL(baseUploadURL); 054 } 055 056 @Override 057 public String getUserAgent() { 058 return this.wrappedConnection.getUserAgent(); 059 } 060 061 @Override 062 public void setUserAgent(String userAgent) { 063 this.wrappedConnection.setUserAgent(userAgent); 064 } 065 066 @Override 067 public String getAccessToken() { 068 return this.wrappedConnection.getAccessToken(); 069 } 070 071 @Override 072 public void setAccessToken(String accessToken) { 073 this.wrappedConnection.setAccessToken(accessToken); 074 } 075 076 @Override 077 public String getRefreshToken() { 078 return this.wrappedConnection.getRefreshToken(); 079 } 080 081 @Override 082 public void setRefreshToken(String refreshToken) { 083 this.wrappedConnection.setRefreshToken(refreshToken); 084 } 085 086 @Override 087 public boolean getAutoRefresh() { 088 return this.wrappedConnection.getAutoRefresh(); 089 } 090 091 @Override 092 public void setAutoRefresh(boolean autoRefresh) { 093 this.wrappedConnection.setAutoRefresh(autoRefresh); 094 } 095 096 /** 097 * Sets the total maximum number of times an API request will be tried when error responses 098 * are received. 099 * 100 * @return the maximum number of request attempts. 101 * @deprecated getMaxRetryAttempts is preferred because it more clearly gets the number 102 * of times a request should be retried after an error response is received. 103 */ 104 @Deprecated 105 @Override 106 public int getMaxRequestAttempts() { 107 return this.wrappedConnection.getMaxRetryAttempts() + 1; 108 } 109 110 /** 111 * Sets the total maximum number of times an API request will be tried when error responses 112 * are received. 113 * 114 * @param attempts the maximum number of request attempts. 115 * @deprecated setMaxRetryAttempts is preferred because it more clearly sets the number 116 * of times a request should be retried after an error response is received. 117 */ 118 @Deprecated 119 @Override 120 public void setMaxRequestAttempts(int attempts) { 121 this.wrappedConnection.setMaxRetryAttempts(attempts - 1); 122 } 123 124 /** 125 * Gets the maximum number of times an API request will be retried after an error response 126 * is received. 127 * 128 * @return the maximum number of request attempts. 129 */ 130 @Override 131 public int getMaxRetryAttempts() { 132 return this.wrappedConnection.getMaxRetryAttempts(); 133 } 134 135 /** 136 * Sets the maximum number of times an API request will be retried after an error response 137 * is received. 138 * 139 * @param attempts the maximum number of request attempts. 140 */ 141 @Override 142 public void setMaxRetryAttempts(int attempts) { 143 this.wrappedConnection.setMaxRetryAttempts(attempts); 144 } 145 146 @Override 147 public boolean canRefresh() { 148 return this.wrappedConnection.canRefresh(); 149 } 150 151 @Override 152 public boolean needsRefresh() { 153 return this.wrappedConnection.needsRefresh(); 154 } 155 156 @Override 157 public void refresh() { 158 this.wrappedConnection.refresh(); 159 } 160 161 @Override 162 String lockAccessToken() { 163 return this.wrappedConnection.lockAccessToken(); 164 } 165 166 @Override 167 void unlockAccessToken() { 168 this.wrappedConnection.unlockAccessToken(); 169 } 170 171 /** 172 * Gets the shared link used for accessing shared items. 173 * 174 * @return the shared link used for accessing shared items. 175 */ 176 String getSharedLink() { 177 return this.sharedLink; 178 } 179 180 /** 181 * Gets the shared link password used for accessing shared items. 182 * 183 * @return the shared link password used for accessing shared items. 184 */ 185 String getSharedLinkPassword() { 186 return this.sharedLinkPassword; 187 } 188}