class App42::Gallery::AlbumService

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.

@see Album @see Photo

Public Class Methods

new(api_key, secret_key, base_url) click to toggle source

this is a constructor that takes

@param apiKey @param secretKey @param baseURL

# File lib/gallery/AlbumService.rb, line 34
def initialize(api_key, secret_key, base_url)
  puts "Photo Gallery->initialize"
  @api_key = api_key
  @secret_key = secret_key
  @base_url = base_url
  @resource = "gallery"
  @version = "1.0"
end

Public Instance Methods

create_album(userName, albumName, albumDescription) click to toggle source

Creates Album on the cloud

@param userName

- The user to which the album belongs

@param albumName

- Name of the album to be created on the cloud

@param albumDescription

- Description of the album to be created

@return Album object containing the album which has been created

@raise App42Exception

# File lib/gallery/AlbumService.rb, line 58
def create_album(userName, albumName, albumDescription)
  puts "Create Album Called "
  puts "Base url #{@base_url}"
  response = nil;
  albumObj = nil;
  albumObj = Album.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "User Name");
  util.throwExceptionIfNullOrBlank(albumName, "Album Name");
  util.throwExceptionIfNullOrBlank(albumDescription, "Description");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"album"=> {
      "name" => albumName,
      "description" => albumDescription
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/album/#{userName}"
    response = connection.post(signature, resource_url, query_params, body)
    puts "Response is #{response}"
    album = AlbumResponseBuilder.new()
    albumObj = album.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return albumObj
end
get_album_by_name(userName, albumName) click to toggle source

Fetch all Album based on the userName and albumName

@param userName

- The user for which the album has to be fetched

@param albumName

- Name of the album that has to be fetched

@return Album object containing album for the given userName and albumName

@raise App42Exception

# File lib/gallery/AlbumService.rb, line 208
def get_album_by_name(userName, albumName)
  puts "getAlbumByName Called "
  puts "Base url #{@base_url}"
  response = nil;
  albumObj = nil;
  albumObj = Album.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "User Name");
  util.throwExceptionIfNullOrBlank(albumName, "Album Name");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("userName", userName)
    params.store("albumName", albumName)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/album/#{userName}/#{albumName}"
    response = connection.get(signature, resource_url, query_params)
    puts "Response is #{response}"
    album = AlbumResponseBuilder.new()
    albumObj = album.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return albumObj
end
get_albums(userName) click to toggle source

Fetches all the Albums based on the userName

@param userName

- The user for which the albums have to be fetched

@return Album object containing all the album for the given userName

@raise App42Exception

# File lib/gallery/AlbumService.rb, line 109
def get_albums(userName)
  puts "Get Albums Called "
  puts "Base url #{@base_url}"
  response = nil;
  albumList = nil;
  albumList = Array.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "User Name");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("userName", userName)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/album/#{userName}"
    response = connection.get(signature, resource_url, query_params)
    album = AlbumResponseBuilder.new()
    albumObj = album.buildArrayResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return albumObj
end
get_albums_by_paging(userName, max, offset) click to toggle source

Fetches all the Albums based on the userName by Paging.

@param userName

- The user for which the albums have to be fetched

@param max

- Maximum number of records to be fetched

@param offset

- From where the records are to be fetched

@return Album object containing all the album for the given userName

@raise App42Exception

# File lib/gallery/AlbumService.rb, line 157
def get_albums_by_paging(userName, max, offset)
  puts "getAlbumsByPaging Called "
  puts "Base url #{@base_url}"
  response = nil;
  albumList = nil;
  albumList = Array.new
  util = Util.new
  util.validateMax(max);
  util.throwExceptionIfNullOrBlank(userName, "User Name");
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("userName", userName)
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/album/#{userName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    album = AlbumResponseBuilder.new()
    albumObj = album.buildArrayResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return albumObj
end
get_albums_count(userName) click to toggle source

Fetches the count of all the Albums based on the userName

@param userName

- The user for which the count of albums have to be fetched

@return App42Response object containing the count of all the album for the given userName

@raise App42Exception

# File lib/gallery/AlbumService.rb, line 302
def get_albums_count(userName)
  puts "getAlbumsCount Called "
  puts "Base url #{@base_url}"
  response = nil;
  responseObj = App42Response.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "User Name");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("userName", userName);
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/album/#{userName}/count"
    response = connection.get(signature, resource_url, query_params)
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
    responseObj = AlbumResponseBuilder.new()
    responseObj.getTotalRecords(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end
remove_album(userName, albumName) click to toggle source

Removes the album based on the userName and albumName. Note: All photos added to this Album will also be removed

@param userName

- The user for which the album has to be removed

@param albumName

- Name of the album that has to be removed

@return App42Response if removed successfully

@raise App42Exception

# File lib/gallery/AlbumService.rb, line 257
def remove_album(userName, albumName)
  puts "Delete Album Called "
  puts "Base url #{@base_url}"
  response = nil;
  responseObj = App42Response.new();
  util = Util.new
  util.throwExceptionIfNullOrBlank(userName, "User Name");
  util.throwExceptionIfNullOrBlank(albumName, "Album Name");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("userName", userName)
    params.store("albumName", albumName)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/#{userName}/#{albumName}"
    response = connection.delete(signature, resource_url, query_params)
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end