Class: App42::Gallery::AlbumService

Inherits:
Object
  • Object
show all
Defined in:
lib/gallery/AlbumService.rb

Overview

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 Also:

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, base_url) ⇒ AlbumService

this is a constructor that takes

Parameters:

  • apiKey
  • secretKey
  • baseURL


34
35
36
37
38
39
40
41
# 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

Instance Method Details

#create_album(userName, albumName, albumDescription) ⇒ Object

Creates Album on the cloud

Parameters:

  • userName
    • The user to which the album belongs

  • albumName
    • Name of the album to be created on the cloud

  • albumDescription
    • Description of the album to be created

Returns:

  • Album object containing the album which has been created

Raises:

  • App42Exception



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object

Fetch all Album based on the userName and albumName

Parameters:

  • userName
    • The user for which the album has to be fetched

  • albumName
    • Name of the album that has to be fetched

Returns:

  • Album object containing album for the given userName and albumName

Raises:

  • App42Exception



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# 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) ⇒ Object

Fetches all the Albums based on the userName

Parameters:

  • userName
    • The user for which the albums have to be fetched

Returns:

  • Album object containing all the album for the given userName

Raises:

  • App42Exception



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 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) ⇒ Object

Fetches all the Albums based on the userName by Paging.

Parameters:

  • userName
    • The user for which the albums have to be fetched

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Album object containing all the album for the given userName

Raises:

  • App42Exception



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# 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) ⇒ Object

Fetches the count of all the Albums based on the userName

Parameters:

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

Returns:

  • App42Response object containing the count of all the album for the given userName

Raises:

  • App42Exception



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# 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) ⇒ Object

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

Parameters:

  • userName
    • The user for which the album has to be removed

  • albumName
    • Name of the album that has to be removed

Returns:

  • App42Response if removed successfully

Raises:

  • App42Exception



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# 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