Create Photo Gallery on the cloud. This service allows to manage i.e. create, retrieve and remove albums on the cloud. Its useful for Mobile/Device App and Web App developer who want Photo Gallery functionality. It gives them a complete Photo Gallery out of the box and reduces the footprint on the device. Developers can focus on how the Photo Gallery will be rendered and this Cloud API will manage the Gallery on the cloud thereby reducing development time.Functions available under Gallery API are
In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.
ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");
After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of AlbumService, buildAlbumService() method needs to be called.
AlbumService albumService = api.buildAlbumService();
Once the API instance has been retrieved, You are ready to use the functions available for that particular API.
The methods available under a particular API will return the domain object (like Album in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.
String userName = "Nick";
String albumName = "MyAlbum";
String albumDescription = "Album Description";
Album album = albumService.createAlbum(userName,albumName,albumDescription); /* returns the Album object. */
System.out.println("userName is " + album.getUserName());
System.out.println("albumName is " + album.getName());
System.out.println("albumDescription is " + album.getDescription());
String jsonResponse = album.toString(); /* returns the response in JSON format. */
The functions available under Gallery API can throw some exceptions in abnormal conditions. Example of the same has been given below.
E.g. If App developer is creating an album for the user which is not in database, the function will throw the App42Exception (as shown below) with message as "Bad Request" and the appErrorCode as "2500" and the details as "The request parameters are invalid. Album with the name '<albumName>' for the user '<userName>' already exists".
String userName = "Nick";
String albumName = "MyAlbum";
String albumDescription = "Album Description";
try
{
Album album = albumService.createAlbum(userName,albumName,albumDescription);
}
catch(App42Exception ex)
{
int appErrorCode = ex.getAppErrorCode();
int httpErrorCode = ex.getHttpErrorCode();
if(appErrorCode == 2500)
{
// Handle here for Bad Request (The request parameters are invalid. Album with the name '<albumName>' for the user '<userName>' already exists.)
}
else if(appErrorCode == 1401){
// handle here for Client is not authorized
}
else if(appErrorCode == 1500){
// handle here for Internal Server Error
}
String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
}
{
"app42Fault": {
"httpErrorCode": 404,
"appErrorCode": 2500,
"message": "Bad Request",
"details": "The request parameters are invalid. Album with the name 'MyAlbum' for the user 'Nick' already exists"
}
}
Below are the HTTP Error Codes and their description, the function under the Gallery API can throw.
/* 1400 - BAD REQUEST - The Request parameters are invalid 1401 - UNAUTHORIZED - Client is not authorized 1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again */
Below are the Application Error Codes and their description, the function under the Gallery API can throw.
/* 2500 - BAD REQUEST - The request parameters are invalid. Album with the name '<albumName>' for the user '<userName>' already exists. 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. 2502 - NOT FOUND - Albums for the user '<userName>' do not exist. 2503 - NOT FOUND - Albums and Photos for the user '<userName>' does not exist. 2504 - NOT FOUND - Photo with the name '<photoName>' from the album '<albumName>' for the user '<userName>' does not exist. 2505 - BAD REQUEST - The request parameters are invalid. Photo by the name '<photoName>' for album '<albumName>' for the user '<userName>' already exists. 2506 - NOT FOUND - The number of albums for the user '<userName>' are less than the specified offset : <offset>. 2507 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' have less photos than the specified offset : <offset>. 2508 - NOT FOUND -Albums and Photos for the tag '<tag>' does not exist. */
Various functions available under Gallery API has been explained below.
Creates Album on the cloud.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2500 - BAD REQUEST - The request parameters are invalid. Album with the name '<albumName>' for the user '<userName>' already exists. */
String userName = "Nick";
String albumName = "MyAlbum";
String albumDescription = "Album Description";
Album album = albumService.createAlbum(userName,albumName,albumDescription); /* returns the Album object. */
System.out.println("userName is " + album.getUserName());
System.out.println("albumName is " + album.getName());
System.out.println("albumDescription is " + album.getDescription());
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description"
}
}
}
}
}
Fetches all the Albums based on the userName
Parameters:
Returns:
Response: ArrayList<Album> Object
Exception:
/* 2502 - NOT FOUND - Albums for the user '<userName>' do not exist. */
String userName = "Nick";
ArrayList<Album> albumList = albumService.getAlbums(userName); /* returns the list of Album objects. */
for(Album album : albumList)
{
System.out.println("userName is " + album.getUserName());
System.out.println("albumName is " + album.getName());
System.out.println("albumDescription is " + album.getDescription());
}
String jsonResponse = albumList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": [
{
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description"
},
{
"userName": "Nick",
"name": "Album091",
"description": "Album Description"
}
]
}
}
}
}
Fetches the count of all the Albums based on the userName
Parameters:
Returns:
Response: App42Response Object
String userName = "Nick"; App42Response response = albumService.getAlbumsCount(userName); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches all the Albums based on the userName by Paging.
Parameters:
Returns:
Response: ArrayList<Album> Object
Exception:
/* 2506 - NOT FOUND - The number of albums for the user '<userName>' are less than the specified offset : <offset>. */
String userName = "Nick";
int max = 1;
int offset = 0;
ArrayList<Album> albumList = albumService.getAlbums(userName,max,offset); /* returns the list of Album objects. */
for(Album album : albumList)
{
System.out.println("userName is " + album.getUserName());
System.out.println("albumName is " + album.getName());
System.out.println("albumDescription is " + album.getDescription());
}
String jsonResponse = albumList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": [
{
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description"
},
{
"userName": "Nick",
"name": "Partyalbum",
"description": "Album Description"
}
]
}
}
}
}
Fetch all Album based on the userName and albumName.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. */
String userName = "Nick";
String albumName = "MyAlbum";
Album album = albumService.getAlbumByName(userName,albumName); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("albumDescription is " + album.getDescription());
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description"
}
}
}
}
}
Removes the album based on the userName and albumName.
Note: All photos added to this Album will also be removed.
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. */
String userName = "Nick"; String albumName = "MyAlbum"; App42Response response = albumService.removeAlbum(userName, albumName); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "Photo091",
"description": "Photo Details",
"url": "http://XXXX.png",
"thumbNailUrl": null
}
}
}
}
}
}
}
Adds Photo for a particular user and album. The Photo is uploaded on the cloud.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. 2505 - BAD REQUEST - The request parameters are invalid. Photo by the name '<photoName>' for album '<albumName>' for the user '<userName>' already exists. */
String userName = "Nick";
String albumName = "MyAlbum";
String photoName = "Photo091";
String photoDescription = "Photo Details";
String path = "Local file path";
Album album = photoService.addPhoto(userName,albumName,photoName,photoDescription,path); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("description is " + album.getDescription());
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + photo.getName());
System.out.println("description is " + photo.getDescription());
}
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "Photo091",
"description": "Photo Details",
"url": "http://XXXX.png",
"thumbNailUrl": "http://XXXX-thumbnail.png"
}
}
}
}
}
}
}
Adds Photo for a particular user and album via Stream. The Photo is uploaded on the cloud.
Parameters:
Returns:
Response: Album Object
String userName = "Nick";
String albumName = "MyAlbum";
String photoName = "Photo091";
String photoDescription = "Photo Details";
String imagePath = "Local file path";
FileInputStream fileInputStream = null;
try
{
fileInputStream = new FileInputStream(imagePath);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
Album album = photoService.addPhoto(userName,albumName,photoName,photoDescription,fileInputStream); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("description is " + album.getDescription());
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + photo.getName());
System.out.println("description is " + photo.getDescription());
}
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "Photo091",
"description": "Photo Details",
"url": "http://XXXX.png",
"thumbNailUrl": "http://XXXX-thumbnail.png"
"thumbNailTinyUrl": "http://tinyurl.com/XXXX"
}
}
}
}
}
}
}
Add tags to the Photo for the user in the album.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. 2504 - NOT FOUND - Photo with the name '<photoName>' from the album '<albumName>' for the user '<userName>' does not exist. */
String userName = "Nick";
String albumName = "MyAlbum";
String photoName = "PhotoName_01";
ArrayList<String> tagList = new ArrayList<String>();
tagList.add("John");
Album album = photoService.addTagToPhoto(userName,albumName,photoName,taglist); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("description is " + album.getDescription());
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + photo.getName());
System.out.println("description is " + photo.getDescription());
System.out.println("taglist is " + photo.getTagList());
}
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": " MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "PhotoName_01.png",
"description": "Photo DESC",
"url": "http://XXXX.png",
"tinyUrl": "http://tinyurl.com/XXXX",
"thumbNailUrl": "http://XXXX-thumbnail.png",
"thumbNailTinyUrl": "http://tinyurl.com/XXXX",
"tags": "TagName_01"
}
}
}
}
}
}
}
Fetches all the Photos based on the userName.
Parameters:
Returns:
Response: ArrayList<Album> Object
Exception:
/* 2503 - NOT FOUND - Albums and Photos for the user '<userName>' does not exist. */
String userName = "Nick";
ArrayList<Album> albumList = photoService.getPhotos(userName); /* returns the list of Album objects. */
for(Album album : albumList)
{
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("description is " + album.getDescription());
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + Photo.getName());
System.out.println("description is " + Photo.getDescription());
}
}
String jsonResponse = albumList.toString (); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": [
{
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": [
{
"name": "Photo090",
"description": "Photo Description",
"url": "http://XXXX.jpg",
"thumbNailUrl": "http://XXXX-thumbnail.jpg"
},
{
"name": "Photo091",
"description": "Photo Details",
"url": "http://YYYY.png",
"thumbNailUrl": "http://YYYY-thumbnail.png"
}
]
}
},
{
"userName": "Jack",
"name": "Album091",
"description": "Album Description"
}
]
}
}
}
}
Fetches all the Photos based on the userName and tag
Parameters:
Returns:
Response: ArrayList<Album> Object
Exception:
/* 2503 - NOT FOUND - Albums and Photos for the user '<userName>' does not exist. 2508 - NOT FOUND -Albums and Photos for the tag '<tag>' does not exist. */
String userName = "Nick";
String tag = "joy";
ArrayList<Album> albumList = photoService.getTaggedPhotos(userName,tag); /* returns the list of Album objects. */
for(Album album : albumList)
{
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("description is " + album.getDescription());
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + photo.getName());
System.out.println("description is " + photo.getDescription());
ArrayList<String> tagList = photo.getTagList();
}
}
String jsonResponse = albumList.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "MyAlbum description",
"photos": {
"photo": {
"name": "myPhoto",
"description": "photo at Tour",
"url": "http://XXXX.jpg",
"tinyUrl": "http://tinyurl.com/XXXX",
"thumbNailTinyUrl": "http://tinyurl.com/XXXX",
"thumbNailUrl": "http://XXXX-thumbnail.jpg",
"tags": "joy"
}
}
}
}
}
}
}
Fetches all Photos based on the userName and album name.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. */
String userName = "Nick";
String albumName = "MyAlbum";
Album album = photoService.getPhotosByAlbumName(userName,albumName); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
String albumDescription = album.getDescription();
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
String name = photo.getName();
String description = photo.getDescription();
}
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": [
{
"name": "Photo090",
"description": "Photo Description",
"url": "http://XXXX.jpg",
"thumbNailUrl": "http://XXXX-thumbnail.jpg"
},
{
"name": "Photo091",
"description": "Photo Details",
"url": "http://YYYY.png",
"thumbNailUrl": "http://YYYY-thumbnail.png"
}
]
}
}
}
}
}
}
Fetches the count of all Photos based on the userName and album name
Parameters:
Returns:
Response: App42Response Object
String userName = "Nick"; String albumName = "MyAlbum"; App42Response response = photoService.getPhotosCountByAlbumName(userName,albumName); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}
Fetches all Photos based on the userName and album name by paging.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. 2507 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' have less photos than the specified offset : <offset>. */
String userName = "Nick";
String albumName = "MyAlbum";
int max = 1;
int offset = 0;
Album album = photoService.getPhotosByAlbumName(userName,albumName,max,offset); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
System.out.println("albumDescription is " + album.getDescription());
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + photo.getName());
System.out.println("description is " + photo.getDescription());
}
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "photoName1",
"description": "welcome",
"url": "http://XXXX.jpg",
"thumbNailUrl": "http://XXXX-thumbnail.jpg"
}
}
}
}
}
}
}
Fetches the particular photo based on the userName, album name and photo name.
Parameters:
Returns:
Response: Album Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. 2504 - NOT FOUND - Photo with the name '<photoName>' from the album '<albumName>' for the user '<userName>' does not exist. */
String userName = "Nick";
String albumName = "MyAlbum";
String photoName = "Photo091";
Album album = photoService.getPhotosByAlbumAndPhotoName(userName,albumName,photoName); /* returns the Album object. */
System.out.println("albumName is " + album.getName());
System.out.println("userName is " + album.getUserName());
String albumDescription = album.getDescription();
ArrayList<Album.Photo> photoList = album.getPhotoList();
for(Album.Photo photo : photoList)
{
System.out.println("name is " + photo.getName());
System.out.println("description is " + photo.getDescription());
}
String jsonResponse = album.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "Photo091",
"description": "Photo Details",
"url": "http://XXXX.png",
"thumbNailUrl": "http://XXXX.png"
}
}
}
}
}
}
}
Removes the particular Photo from the specified Album for a particular user.
Note: The Photo is removed from the cloud and wont be accessible in future
Parameters:
Returns:
Response: App42Response Object
Exception:
/* 2501 - NOT FOUND - Album by the name '<albumName>' for the user '<userName>' does not exist. 2504 - NOT FOUND - Photo with the name '<photoName>' from the album '<albumName>' for the user '<userName>' does not exist. */
String userName = "Nick"; String albumName = "MyAlbum"; String photoName = "Album Description"; App42Response response = photoService.removePhoto(userName, albumName, photoName); /* returns the App42Response object. */ boolean success = response.isResponseSuccess(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"albums": {
"album": {
"userName": "Nick",
"name": "MyAlbum",
"description": "Album Description",
"photos": {
"photo": {
"name": "Photo090",
"description": "Photo Description",
"url": "http://XXXX.jpg",
"thumbNailUrl": "http://XXXX.jpg"
}
}
}
}
}
}
}