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 void setAutoRefresh(boolean autoRefresh) {
088        this.wrappedConnection.setAutoRefresh(autoRefresh);
089    }
090
091    @Override
092    public boolean getAutoRefresh() {
093        return this.wrappedConnection.getAutoRefresh();
094    }
095
096    /**
097     * Sets the total maximum number of times an API request will be tried when error responses
098     * are received.
099     * @return the maximum number of request attempts.
100     * @deprecated getMaxRetryAttempts is preferred because it more clearly gets the number
101     * of times a request should be retried after an error response is received.
102     */
103    @Deprecated
104    @Override
105    public int getMaxRequestAttempts() {
106        return this.wrappedConnection.getMaxRetryAttempts() + 1;
107    }
108
109    /**
110     * Sets the total maximum number of times an API request will be tried when error responses
111     * are received.
112     * @param attempts the maximum number of request attempts.
113     * @deprecated setMaxRetryAttempts is preferred because it more clearly sets the number
114     * of times a request should be retried after an error response is received.
115     */
116    @Deprecated
117    @Override
118    public void setMaxRequestAttempts(int attempts) {
119        this.wrappedConnection.setMaxRetryAttempts(attempts - 1);
120    }
121
122    /**
123     * Gets the maximum number of times an API request will be retried after an error response
124     * is received.
125     * @return the maximum number of request attempts.
126     */
127    @Override
128    public int getMaxRetryAttempts() {
129        return this.wrappedConnection.getMaxRetryAttempts();
130    }
131
132    /**
133     * Sets the maximum number of times an API request will be retried after an error response
134     * is received.
135     * @param attempts the maximum number of request attempts.
136     */
137    @Override
138    public void setMaxRetryAttempts(int attempts) {
139        this.wrappedConnection.setMaxRetryAttempts(attempts);
140    }
141
142    @Override
143    public boolean canRefresh() {
144        return this.wrappedConnection.canRefresh();
145    }
146
147    @Override
148    public boolean needsRefresh() {
149        return this.wrappedConnection.needsRefresh();
150    }
151
152    @Override
153    public void refresh() {
154        this.wrappedConnection.refresh();
155    }
156
157    @Override
158    String lockAccessToken() {
159        return this.wrappedConnection.lockAccessToken();
160    }
161
162    @Override
163    void unlockAccessToken() {
164        this.wrappedConnection.unlockAccessToken();
165    }
166
167    /**
168     * Gets the shared link used for accessing shared items.
169     * @return the shared link used for accessing shared items.
170     */
171    String getSharedLink() {
172        return this.sharedLink;
173    }
174
175    /**
176     * Gets the shared link password used for accessing shared items.
177     * @return the shared link password used for accessing shared items.
178     */
179    String getSharedLinkPassword() {
180        return this.sharedLinkPassword;
181    }
182}