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    public SharedLinkAPIConnection(BoxAPIConnection connection, String sharedLink) {
013        this(connection, sharedLink, null);
014    }
015
016    public 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     * Gets the maximum number of times an API request will be retried after an error response
098     * is received.
099     *
100     * @return the maximum number of request attempts.
101     */
102    @Override
103    public int getMaxRetryAttempts() {
104        return this.wrappedConnection.getMaxRetryAttempts();
105    }
106
107    /**
108     * Sets the maximum number of times an API request will be retried after an error response
109     * is received.
110     *
111     * @param attempts the maximum number of request attempts.
112     */
113    @Override
114    public void setMaxRetryAttempts(int attempts) {
115        this.wrappedConnection.setMaxRetryAttempts(attempts);
116    }
117
118    @Override
119    public boolean canRefresh() {
120        return this.wrappedConnection.canRefresh();
121    }
122
123    @Override
124    public boolean needsRefresh() {
125        return this.wrappedConnection.needsRefresh();
126    }
127
128    @Override
129    public void refresh() {
130        this.wrappedConnection.refresh();
131    }
132
133    @Override
134    String lockAccessToken() {
135        return this.wrappedConnection.lockAccessToken();
136    }
137
138    @Override
139    void unlockAccessToken() {
140        this.wrappedConnection.unlockAccessToken();
141    }
142
143    @Override
144    public RequestInterceptor getRequestInterceptor() {
145        return this.wrappedConnection.getRequestInterceptor();
146    }
147
148    /**
149     * Gets the shared link used for accessing shared items.
150     *
151     * @return the shared link used for accessing shared items.
152     */
153    String getSharedLink() {
154        return this.sharedLink;
155    }
156
157    /**
158     * Gets the shared link password used for accessing shared items.
159     *
160     * @return the shared link password used for accessing shared items.
161     */
162    String getSharedLinkPassword() {
163        return this.sharedLinkPassword;
164    }
165}