Java Code Examples for com.googlecode.flickrjandroid.photos.Photo#setServer()

The following examples show how to use com.googlecode.flickrjandroid.photos.Photo#setServer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhotosetsInterface.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the information for a specified photoset.
 * 
 * This method does not require authentication.
 * 
 * @param photosetId
 *            The photoset ID
 * @return The Photoset
 * @throws FlickrException
 * @throws IOException
 * @throws JSONException
 */
public Photoset getInfo(String photosetId) throws FlickrException, IOException, JSONException {
	List<Parameter> parameters = new ArrayList<Parameter>();
	parameters.add(new Parameter("method", METHOD_GET_INFO));
	parameters.add(new Parameter("api_key", apiKey));

	parameters.add(new Parameter("photoset_id", photosetId));

	Response response = transportAPI.get(transportAPI.getPath(), parameters);
	if (response.isError()) {
		throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
	}
	JSONObject photosetElement = response.getData().getJSONObject("photoset");
	Photoset photoset = new Photoset();
	photoset.setId(photosetElement.getString("id"));

	User owner = new User();
	owner.setId(photosetElement.getString("owner"));
	photoset.setOwner(owner);

	Photo primaryPhoto = new Photo();
	primaryPhoto.setId(photosetElement.getString("primary"));
	primaryPhoto.setSecret(photosetElement.getString("secret")); // TODO verify that this is the secret for the photo
	primaryPhoto.setServer(photosetElement.getString("server")); // TODO verify that this is the server for the photo
	primaryPhoto.setFarm(photosetElement.getString("farm"));
	photoset.setPrimaryPhoto(primaryPhoto);

	// TODO remove secret/server/farm from photoset?
	// It's rather related to the primaryPhoto, then to the photoset itself.
	photoset.setSecret(photosetElement.getString("secret"));
	photoset.setServer(photosetElement.getString("server"));
	photoset.setFarm(photosetElement.getString("farm"));
	photoset.setPhotoCount(photosetElement.getString("photos"));

	photoset.setTitle(JSONUtils.getChildValue(photosetElement, "title"));
	photoset.setDescription(JSONUtils.getChildValue(photosetElement, "description"));
	photoset.setPrimaryPhoto(primaryPhoto);

	return photoset;
}
 
Example 2
Source File: PhotosetsInterface.java    From flickr-uploader with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get a list of all photosets for the specified user.
 * 
 * This method does not require authentication. But to get a Photoset into the list, that contains just private photos, the call needs to be authenticated.
 * 
 * @param userId
 *            The User id
 * @return The Photosets collection
 * @throws IOException
 * @throws FlickrException
 * @throws JSONException
 */
public Photosets getList(String userId) throws IOException, FlickrException, JSONException {
	List<Parameter> parameters = new ArrayList<Parameter>();
	parameters.add(new Parameter("method", METHOD_GET_LIST));

	boolean signed = OAuthUtils.hasSigned();
	if (signed) {
		parameters.add(new Parameter(OAuthInterface.PARAM_OAUTH_CONSUMER_KEY, apiKey));
	} else {
		parameters.add(new Parameter("api_key", apiKey));
	}

	if (userId != null) {
		parameters.add(new Parameter("user_id", userId));
	}

	if (signed) {
		OAuthUtils.addOAuthToken(parameters);
	}

	Response response = signed ? transportAPI.postJSON(sharedSecret, parameters) : transportAPI.get(transportAPI.getPath(), parameters);
	if (response.isError()) {
		throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
	}
	Photosets photosetsObject = new Photosets();
	JSONObject photosetsElement = response.getData().getJSONObject("photosets");
	List<Photoset> photosets = new ArrayList<Photoset>();
	JSONArray photosetElements = photosetsElement.optJSONArray("photoset");
	for (int i = 0; photosetElements != null && i < photosetElements.length(); i++) {
		JSONObject photosetElement = photosetElements.getJSONObject(i);
		Photoset photoset = new Photoset();
		photoset.setId(photosetElement.getString("id"));

		if (photosetElement.has("owner")) {
			User owner = new User();
			owner.setId(photosetElement.getString("owner"));
			photoset.setOwner(owner);
		}

		Photo primaryPhoto = new Photo();
		primaryPhoto.setId(photosetElement.getString("primary"));
		primaryPhoto.setSecret(photosetElement.getString("secret")); // TODO verify that this is the secret for the photo
		primaryPhoto.setServer(photosetElement.getString("server")); // TODO verify that this is the server for the photo
		primaryPhoto.setFarm(photosetElement.getString("farm"));
		photoset.setPrimaryPhoto(primaryPhoto);

		photoset.setSecret(photosetElement.getString("secret"));
		photoset.setServer(photosetElement.getString("server"));
		photoset.setFarm(photosetElement.getString("farm"));
		photoset.setPhotoCount(photosetElement.getString("photos"));

		photoset.setTitle(JSONUtils.getChildValue(photosetElement, "title"));
		photoset.setDescription(JSONUtils.getChildValue(photosetElement, "description"));

		photosets.add(photoset);
	}

	photosetsObject.setPhotosets(photosets);
	return photosetsObject;
}