Class: GallerySync::S3Destination
- Inherits:
-
Gallery
- Object
- Gallery
- GallerySync::S3Destination
show all
- Defined in:
- lib/gallery_sync/gallery_sync.rb
Instance Method Summary
collapse
Methods inherited from Gallery
#[], #albums, #serialized_albums, #sync_to
Constructor Details
#initialize(bucket_name, s3_key, s3_secret) ⇒ S3Destination
Returns a new instance of S3Destination.
360
361
362
363
364
365
366
|
# File 'lib/gallery_sync/gallery_sync.rb', line 360
def initialize(bucket_name,s3_key,s3_secret)
@con = AWS::S3::new(
:access_key_id => s3_key,
:secret_access_key => s3_secret
)
@bucket = @con.buckets.create bucket_name
end
|
Instance Method Details
#bucket ⇒ Object
368
369
370
|
# File 'lib/gallery_sync/gallery_sync.rb', line 368
def bucket
@bucket
end
|
#load_albums ⇒ Object
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
# File 'lib/gallery_sync/gallery_sync.rb', line 372
def load_albums
albums = []
dirs = @bucket.as_tree.children.select(&:branch?)
dirs.each { |dir|
photos = []
album = Album.new(File.basename(dir.prefix))
metadata = @bucket.objects[File.join(dir.prefix,'album.yml')]
if(metadata.exists?)
album.load_metadata_from_yaml(metadata.read)
end
dir = dir.children.select(&:branch?)[0]
if (dir)
dir.children.select(&:leaf?).each { |leaf|
if( !leaf.key.end_with?("/") )
photos << S3Photo.new(album, File.basename(leaf.key), leaf.key, self)
end
}
end
if( !photos.empty? )
album.photos = photos
album.album_photo = photos[0]
albums << album
end
}
albums
end
|
#rm_album(album_name) ⇒ Object
403
404
405
406
407
408
|
# File 'lib/gallery_sync/gallery_sync.rb', line 403
def rm_album album_name
album = self[album_name]
album.photos.each { |p|
rm_photo p
}
end
|
#rm_photo(photo) ⇒ Object
410
411
412
413
414
415
416
417
|
# File 'lib/gallery_sync/gallery_sync.rb', line 410
def rm_photo photo
key_thumb = photo.album.name + "/thumb/" + photo.name
key_medium = photo.album.name + "/medium/" + photo.name
key_full = photo.album.name + "/full/" + photo.name
@bucket.objects[key_thumb].delete
@bucket.objects[key_medium].delete
@bucket.objects[key_full].delete
end
|
#to_s ⇒ Object
442
443
444
|
# File 'lib/gallery_sync/gallery_sync.rb', line 442
def to_s
@bucket.name
end
|
437
438
439
440
|
# File 'lib/gallery_sync/gallery_sync.rb', line 437
def update_album_metadata(album,metadata)
metadata_key = album.name + "/album.yml"
@bucket.objects.create(metadata_key, :data => YAML::dump(metadata), :acl => :public_read)
end
|
#upload_album(album) ⇒ Object
419
420
421
422
423
|
# File 'lib/gallery_sync/gallery_sync.rb', line 419
def upload_album album
album.photos.each { |photo|
upload_photo(photo)
}
end
|
#upload_photo(photo) ⇒ Object
425
426
427
428
429
430
431
432
433
434
435
|
# File 'lib/gallery_sync/gallery_sync.rb', line 425
def upload_photo(photo)
key_thumb = photo.album.name + "/thumb/" + photo.name
key_medium = photo.album.name + "/medium/" + photo.name
key_full = photo.album.name + "/full/" + photo.name
photos = ImageScaler.scale_image(photo.file)
@bucket.objects.create(key_thumb, :data => photos[:thumb], :acl => :public_read)
@bucket.objects.create(key_medium, :data => photos[:medium], :acl => :public_read)
end
|