Commits

Anonymous committed 525887b

US3511 - Miscellaneous clean up. Changes to support Facebook offline_access deprecation.

Comments (0)

Files changed (9)

core/src/com/photobucket/api/core/PhotobucketAPI.java

 
 
 public class PhotobucketAPI {
-	
+	public static final String API_SUBDOMAIN = "api.photobucket.com";
 	private String oauthToken;
 	private String oauthTokenSecret;
 	private String oauthConsumerKey;
 	private String oauthConsumerSecret;
 	private Long oauthTimestamp;
-    private String subdomain = "api.photobucket.com";
+    private String subdomain = API_SUBDOMAIN;
     private boolean ssl;
     private String requestPath;
 	private Map<String, String> parameters = new HashMap<String, String>();

core/src/com/photobucket/api/oauth/PhotobucketHttpOAuthConsumer.java

 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.photobucket.api.core.PhotobucketAPI;
+
 @SuppressWarnings("serial")
 public class PhotobucketHttpOAuthConsumer extends CommonsHttpOAuthConsumer {
 	private static final Logger logger = LoggerFactory.getLogger(PhotobucketHttpOAuthConsumer.class);
     		time = this.getOauthTimestamp().toString();
     	} else {
 			try {
-				URL timeUrl = new URL("https://api.photobucket.com:443/time");
+				URL timeUrl = new URL("https://" + PhotobucketAPI.API_SUBDOMAIN + ":443/time");
 				BufferedReader reader = new BufferedReader(new InputStreamReader(timeUrl.openStream()));
 				time = reader.readLine();
 				reader.close();

core/src/com/photobucket/api/rest/RESTfulOAuthClient.java

 import com.photobucket.api.core.FileBodyWithProgress;
 import com.photobucket.api.core.IFileUploadProgressEventListener;
 import com.photobucket.api.core.InputStreamBodyWithProgress;
+import com.photobucket.api.core.PhotobucketAPI;
 import com.photobucket.api.oauth.PhotobucketHttpOAuthConsumer;
 
 public class RESTfulOAuthClient {
 	private static final Logger logger = LoggerFactory.getLogger(RESTfulOAuthClient.class);
 	
-	/** Photobucket Base domain - always api.photobucket.com */
-	private static final String PHOTOBUCKET_BASE_DOMAIN = "api.photobucket.com";
-
 	private static final int ACTUAL_REQUEST = 0;
 	private static final int BASE_DOMAIN_REQUEST = 1;
 	
     		String parameters = URLEncodedUtils.format(qParams, "UTF-8"); 
     		URI actualUri = URIUtils.createURI(url.getProtocol(), url.getHost(), url.getPort(), url.getPath(), 
     				parameters, null);
-    		URI baseDomainUri = URIUtils.createURI(url.getProtocol(), PHOTOBUCKET_BASE_DOMAIN, url.getPort(), 
+    		URI baseDomainUri = URIUtils.createURI(url.getProtocol(), PhotobucketAPI.API_SUBDOMAIN, url.getPort(), 
     				url.getPath(), parameters, null);
 
     		// Construct the right kind of HTTP Request

core/src/com/photobucket/api/rest/RESTfulRequest.java

 import java.util.Vector;
 
 import com.photobucket.api.core.IFileUploadProgressEventListener;
+import com.photobucket.api.core.PhotobucketAPI;
 
 public class RESTfulRequest {
 	/** Photobucket Base domain - always api.photobucket.com */
-	private static final String PHOTOBUCKET_BASE_DOMAIN = "api.photobucket.com";
 	
 	public enum Method {
 		GET,
     private InputStream uploadStream;
     private String uploadFileName;
     private Integer uploadFileSize;
-    private String subdomain = new String(PHOTOBUCKET_BASE_DOMAIN);
+    private String subdomain = PhotobucketAPI.API_SUBDOMAIN;
     private boolean ssl = false;
    
     // Photobucket specific
 	    StringBuilder sb = new StringBuilder();
         sb.append(getProtocol());
         sb.append("://");
-        sb.append(PHOTOBUCKET_BASE_DOMAIN);
+        sb.append(PhotobucketAPI.API_SUBDOMAIN);
         sb.append(getRequestPath());
 		return sb.toString();
 	}

core/test/com/photobucket/api/core/AlbumTest.java

 		Map<String,String> params = api.getParameters();
 		params.put("password", "abc1234");
 		
-		api.setSubdomain("api.photobucket.com");
+		api.setSubdomain(PhotobucketAPI.API_SUBDOMAIN);
 		api.setRequestPath("/login/direct/pbapi");
 		api.setMethod("post");
 		api.setFormat("json");

service/src/com/photobucket/api/service/BaseShareStrategy.java

 	private static final long serialVersionUID = -5551454030117653442L;
 	private static final Logger logger = LoggerFactory.getLogger(BaseShareStrategy.class);
 	
+	public static enum ShareResult {
+	    GENERAL_ERROR("error"),
+	    AUTH_ERROR("authentication error"),
+	    NOT_SENT("not sent"),
+	    SUCCESS("");
+	    
+	    private String apiResult;
+	    
+	    private ShareResult(String apiResult) {
+	        this.apiResult = apiResult;
+	    }
+	    
+	    public String getApiResult() {
+	        return apiResult;
+	    }
+	    
+	    public static ShareResult fromApiResult(String apiResult) {
+	        ShareResult result = null; // Default.
+	        
+	        // Look for known errors first.
+	        for (ShareResult test : ShareResult.values()) {
+	            if (test.getApiResult().equalsIgnoreCase(apiResult)) {
+	                result = test;
+	                break;
+	            }
+	        }
+	        
+	        if (result == null) {
+    	        if (apiResult == null) {
+    	            result = GENERAL_ERROR;
+    	        } else {
+    	            result = SUCCESS;
+    	        }
+	        }
+	        
+	        return result;
+	    }
+	}
+	
     protected String message;
     protected Set<String> services = new HashSet<String>(5);
-	protected Map<String,String> results;
+	protected Map<String, ShareResult> results;
 	
 	public BaseShareStrategy(String message) {
 		super();
     	this.services.addAll(services);
     }
     
-    public Map<String,String> getResults() {
+    public Map<String, ShareResult> getResults() {
 		// Return an empty hash set if we don't have anything, to avoid null checks in the caller.
 		if (results == null)
-			results = new HashMap<String,String>(0);
+			results = new HashMap<String, ShareResult>(0);
 		
 		return results;
 	}
 		    	
 		    	// Only create the results map if we have some results to process.
 		    	if (iter.hasNext())
-		    		results = new HashMap<String, String>(services.size());
+		    		results = new HashMap<String, ShareResult>(services.size());
 		    	
 		    	while (iter.hasNext()) {
 		    		String key = (String)iter.next();
 		    		String result = content.getString(key);
-		    		results.put(key, result);
+		    		results.put(key, ShareResult.fromApiResult(result));
 		    	}
 			} else {
                 json = new JSONObject(response.getResponseString());

service/src/com/photobucket/api/service/UserShareConnectionsStrategy.java

 	protected Logger getLogger() {
 		return logger;
 	}
-
+	
 	@Override
 	protected void parseContent(Object contentObject) throws JSONException {
 		JSONObject content = (JSONObject)contentObject;

service/src/com/photobucket/api/service/model/Media.java

     private static final String HTTP_GI = "http://gi";
     private static final String HTTP_GOI = "http://goi";
     private static final String HTTP_RESIZE = "http://rs.photobucket.com/";
+    public static boolean USE_SILOED_API = true;
 	
 	public enum Type { 
 		IMAGE("image"), VIDEO("video");
     			String host = url.getHost();
     			String silo = getSilo();
     			
-    			if (silo.length() == 0) {
+    			if (!USE_SILOED_API || (silo.length() == 0)) {
     				// The image is not on any silo, so just append to the existing host name.
     				apiSubdomain = API_PREFIX + "." + host;
     			} else {

service/test/com/photobucket/api/test/SecureTestCase.java

 
 import org.junit.Ignore;
 
+import com.photobucket.api.core.PhotobucketAPI;
 import com.photobucket.api.service.DirectLoginStrategy;
 import com.photobucket.api.service.model.User;
 
 		// Override the subdomain if we're not targeting production
 		String subdomain = bundle.getString("subdomain");
 		
-		if (!subdomain.equals("api.photobucket.com")) {
+		if (!subdomain.equals(PhotobucketAPI.API_SUBDOMAIN)) {
 			user.setSubdomain(subdomain);			
 		}