picasawebalbums 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/PicasaWebAlbums.gemspec +24 -0
- data/Rakefile +1 -0
- data/lib/PicasaWebAlbums/version.rb +3 -0
- data/lib/PicasaWebAlbums.rb +15 -0
- data/lib/album.rb +9 -0
- data/lib/photo.rb +5 -0
- data/lib/repository.rb +126 -0
- data/lib/tag.rb +5 -0
- data/readme.md +88 -0
- data/test/test_albums.rb +41 -0
- data/test/test_photos.rb +27 -0
- data/test/test_tags.rb +33 -0
- metadata +62 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "PicasaWebAlbums/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "picasawebalbums"
|
7
|
+
s.version = PicasaWebAlbums::VERSION
|
8
|
+
s.authors = ["Martin Kraft"]
|
9
|
+
s.email = ["martinkraft@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/mkraft/PicasaWebAlbums"
|
11
|
+
s.summary = %q{Provides programmatic access to Picasa Web Albums data.}
|
12
|
+
s.description = %q{A simple way to retrieve albums, photos, tags, etc. from Picasa Web Albums.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "picasawebalbums"
|
15
|
+
s.required_ruby_version = '>= 1.9.3'
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#require "PicasaWebAlbums/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'date'
|
5
|
+
require_relative 'album'
|
6
|
+
require_relative 'photo'
|
7
|
+
require_relative 'tag'
|
8
|
+
require_relative 'repository'
|
9
|
+
|
10
|
+
module PicasaWebAlbums
|
11
|
+
def self.get_repository(email, password)
|
12
|
+
picasa_repo = Repository.new(email, password)
|
13
|
+
return picasa_repo
|
14
|
+
end
|
15
|
+
end
|
data/lib/album.rb
ADDED
data/lib/photo.rb
ADDED
data/lib/repository.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module PicasaWebAlbums
|
2
|
+
class Repository
|
3
|
+
def initialize(email, password)
|
4
|
+
@email = email
|
5
|
+
@authentication_token = get_authentication_token(email, password)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_all_albums
|
9
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=album&access=all")
|
10
|
+
albums = []
|
11
|
+
xml.root.elements.each("//entry") do |entry|
|
12
|
+
gallery = Album.new
|
13
|
+
gallery.id = entry.elements["gphoto:id"].text
|
14
|
+
gallery.title = entry.elements["title"].text
|
15
|
+
gallery.date_created = DateTime.parse(entry.elements["published"].text)
|
16
|
+
gallery.date_updated = DateTime.parse(entry.elements["updated"].text)
|
17
|
+
gallery.slug = entry.elements["gphoto:name"].text
|
18
|
+
gallery.cover_photo_url = entry.elements["media:group/media:content"].attributes["url"]
|
19
|
+
gallery.description = entry.elements["media:group/media:description"].text
|
20
|
+
albums << gallery
|
21
|
+
end
|
22
|
+
return albums
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_album_by_id(id)
|
26
|
+
albums = get_all_albums
|
27
|
+
album_to_return = albums[albums.find_index{|album| album.id == id.to_s}]
|
28
|
+
return album_to_return
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_album_by_title(title)
|
32
|
+
albums = get_all_albums
|
33
|
+
album_to_return = albums[albums.find_index{|album| album.title == title.to_s}]
|
34
|
+
return album_to_return
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_album_by_slug(slug)
|
38
|
+
albums = get_all_albums
|
39
|
+
album_to_return = albums[albums.find_index{|album| album.slug == slug.to_s}]
|
40
|
+
return album_to_return
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_photos_by_album_id(id)
|
44
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/base/user/#{@email}/albumid/#{id}")
|
45
|
+
photos = []
|
46
|
+
xml.root.elements.each("//entry") do |entry|
|
47
|
+
photo = Photo.new
|
48
|
+
photo.id = get_photo_id_from_photo_id_url(entry.elements["id"].text)
|
49
|
+
photo.url = entry.elements["media:group/media:content"].attributes["url"]
|
50
|
+
photo.width = entry.elements["media:group/media:content"].attributes["width"].to_i
|
51
|
+
photo.height = entry.elements["media:group/media:content"].attributes["height"].to_i
|
52
|
+
photo.caption = entry.elements["media:group/media:description"].text
|
53
|
+
photo.file_name = entry.elements["media:group/media:title"].text
|
54
|
+
photos << photo
|
55
|
+
end
|
56
|
+
return photos
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_photo_by_album_id_and_photo_id(album_id, photo_id)
|
60
|
+
photos = get_photos_by_album_id(album_id)
|
61
|
+
photo_to_return = Photo.new
|
62
|
+
photos.each do |photo|
|
63
|
+
if photo.id == photo_id
|
64
|
+
photo_to_return = photo
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return photo_to_return
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_all_tags
|
71
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=tag")
|
72
|
+
tags = []
|
73
|
+
xml.root.elements.each("//entry") do |entry|
|
74
|
+
tag = Tag.new
|
75
|
+
tag.text = entry.elements["title"].text
|
76
|
+
tags << tag
|
77
|
+
end
|
78
|
+
return tags
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_tags_by_album_id(album_id)
|
82
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/userID/albumid/#{album_id}?kind=tag")
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_tags_by_album_id_and_photo_id(album_id, photo_id)
|
86
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/default/albumid/#{album_id}/photoid/#{photo_id}?kind=tag")
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def get_xml(url)
|
92
|
+
uri = URI(url)
|
93
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
94
|
+
request['Authorization'] = @authentication_token
|
95
|
+
response = Net::HTTP.start(uri.hostname, uri.port) { |http|
|
96
|
+
http.request(request)
|
97
|
+
}
|
98
|
+
xml = REXML::Document.new(response.body)
|
99
|
+
return xml
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_photo_id_from_photo_id_url(photo_id_url)
|
103
|
+
start_index = photo_id_url.index('/photoid/') + 9
|
104
|
+
slice_of_id_url_to_end = photo_id_url[start_index..-1]
|
105
|
+
end_index = slice_of_id_url_to_end.index(/[?|\/]/)
|
106
|
+
id = slice_of_id_url_to_end[0...end_index]
|
107
|
+
return id
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_authentication_token(email, password)
|
111
|
+
uri = URI("https://www.google.com/accounts/ClientLogin")
|
112
|
+
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
113
|
+
request = Net::HTTP::Post.new uri.request_uri
|
114
|
+
data = "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=lh2&source=someapp1"
|
115
|
+
response = http.request(request, data)
|
116
|
+
@body = response.body
|
117
|
+
end
|
118
|
+
start_index = @body.index('Auth=')
|
119
|
+
slice_of_auth_to_end = @body[start_index..-1]
|
120
|
+
end_index = slice_of_auth_to_end.index("\n")
|
121
|
+
auth_string = slice_of_auth_to_end[0...end_index]
|
122
|
+
auth_token = "GoogleLogin #{auth_string}"
|
123
|
+
return auth_token
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/tag.rb
ADDED
data/readme.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PicasaWebAlbums
|
2
|
+
===============
|
3
|
+
|
4
|
+
Gem for accessing photos and albums from Picasa Web Albums
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
gem install PicasaWebAlbums
|
10
|
+
|
11
|
+
Rails/Application Integration
|
12
|
+
-----------------------------
|
13
|
+
|
14
|
+
Add one of the below lines to the Gemfile:
|
15
|
+
|
16
|
+
- `gem 'PicasaWebAlbums'` (to install it from rubygems)
|
17
|
+
- `gem 'PicasaWebAlbums', :git => 'git@github.com:mkraft/PicasaWebAlbums.git'` (to install directly from the git repo)
|
18
|
+
|
19
|
+
Then run `bundle install`
|
20
|
+
|
21
|
+
Code Examples
|
22
|
+
-------------
|
23
|
+
|
24
|
+
Print the title of all albums
|
25
|
+
|
26
|
+
repo = PicasaWebAlbums.get_repository('someperson@gmail.com', 'somepassword')
|
27
|
+
albums = repo.get_albums
|
28
|
+
albums.each { |album| puts album.title }
|
29
|
+
|
30
|
+
Print the URL of each photo in the album titled "Big Boy"
|
31
|
+
|
32
|
+
repo = PicasaWebAlbums.get_repository('someperson@gmail.com', 'somepassword')
|
33
|
+
album = repo.get_album_by_title("Big Boy")
|
34
|
+
photos = repo.get_photos_by_album_id(album.id)
|
35
|
+
photos.each { |photo| puts photo.url }
|
36
|
+
|
37
|
+
Repository Methods
|
38
|
+
-------------------
|
39
|
+
|
40
|
+
### Album(s)
|
41
|
+
|
42
|
+
- `get_all_albums`
|
43
|
+
- `get_album_by_id(id)`
|
44
|
+
- `get_album_by_title(title)`
|
45
|
+
- `get_album_by_slug(slug)`
|
46
|
+
|
47
|
+
### Photo(s)
|
48
|
+
|
49
|
+
- `get_photos_by_album_id(album_id)`
|
50
|
+
- `get_photo_by_album_id_and_photo_id(album_id, photo_id)`
|
51
|
+
|
52
|
+
### Tags
|
53
|
+
|
54
|
+
- `get_all_tags`
|
55
|
+
- `get_tags_by_album_id(album_id)`
|
56
|
+
- `get_tags_by_album_id_and_photo_id(album_id, photo_id)`
|
57
|
+
|
58
|
+
Domain Object Properties
|
59
|
+
------------------------
|
60
|
+
|
61
|
+
### Photo
|
62
|
+
|
63
|
+
- `id`
|
64
|
+
- `url`
|
65
|
+
- `caption`
|
66
|
+
- `width`
|
67
|
+
- `height`
|
68
|
+
- `file_name`
|
69
|
+
|
70
|
+
### Album
|
71
|
+
|
72
|
+
- `id`
|
73
|
+
- `photos`
|
74
|
+
- `title`
|
75
|
+
- `slug`
|
76
|
+
- `date_created`
|
77
|
+
- `date_updated`
|
78
|
+
- `cover_photo_url`
|
79
|
+
- `description`
|
80
|
+
|
81
|
+
### Tag
|
82
|
+
|
83
|
+
- `text`
|
84
|
+
|
85
|
+
Additional Documentation
|
86
|
+
------------------------
|
87
|
+
|
88
|
+
Additional documentation can be found on the [rubydoc pages](http://rubydoc.info/gems/PicasaWebAlbums).
|
data/test/test_albums.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'shoulda'
|
3
|
+
require_relative '../lib/picasawebalbums'
|
4
|
+
|
5
|
+
module PicasaWebAlbums
|
6
|
+
class TestAlbums < Test::Unit::TestCase
|
7
|
+
|
8
|
+
context "get all albums" do
|
9
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
10
|
+
should "return albums" do
|
11
|
+
albums = repo.get_all_albums
|
12
|
+
assert_equal 4, albums.count
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "get album by id" do
|
17
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
18
|
+
should "return an album" do
|
19
|
+
album = repo.get_album_by_id("5461230096110151249")
|
20
|
+
assert_equal "Banner Images", album.title
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "get album by title" do
|
25
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
26
|
+
should "return an album" do
|
27
|
+
album = repo.get_album_by_title("Bio Profile Pics")
|
28
|
+
assert_equal "5455332611886090353", album.id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "get album by slug" do
|
33
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
34
|
+
should "return an album" do
|
35
|
+
album = repo.get_album_by_slug("960x350")
|
36
|
+
assert_equal "5577380987485671713", album.id
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/test/test_photos.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'shoulda'
|
3
|
+
require_relative '../lib/picasawebalbums'
|
4
|
+
|
5
|
+
module PicasaWebAlbums
|
6
|
+
class TestPhotos < Test::Unit::TestCase
|
7
|
+
|
8
|
+
context "get photos from album" do
|
9
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
10
|
+
should "return at least 1 photo" do
|
11
|
+
album = repo.get_album_by_id(5461230096110151249)
|
12
|
+
photos = repo.get_photos_by_album_id(album.id)
|
13
|
+
assert_equal true, photos.count > 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "get photo by album and id" do
|
18
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
19
|
+
should "return 1 photo" do
|
20
|
+
album = repo.get_album_by_slug("960x350")
|
21
|
+
photo = repo.get_photo_by_album_id_and_photo_id(album.id, "5577383323184640194")
|
22
|
+
assert_equal "Lake Joe Home.", photo.caption
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/test/test_tags.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'shoulda'
|
3
|
+
require_relative '../lib/picasawebalbums'
|
4
|
+
|
5
|
+
module PicasaWebAlbums
|
6
|
+
class TestTags < Test::Unit::TestCase
|
7
|
+
|
8
|
+
context "get all tags" do
|
9
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
10
|
+
should "return at least 1 tag" do
|
11
|
+
tags = repo.get_all_tags
|
12
|
+
assert tags.count > 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "get tags by album id" do
|
17
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
18
|
+
should "return at least 1 tag" do
|
19
|
+
tags = repo.get_tags_by_album_id("5461230096110151249")
|
20
|
+
assert tags.count > 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "get tags by album id and photo id" do
|
25
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
26
|
+
should "return at least 1 tag" do
|
27
|
+
tags = repo.get_tags_by_album_id_and_photo_id("5461230096110151249", "5577383323184640194")
|
28
|
+
assert tags.count > 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picasawebalbums
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Martin Kraft
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple way to retrieve albums, photos, tags, etc. from Picasa Web Albums.
|
15
|
+
email:
|
16
|
+
- martinkraft@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- PicasaWebAlbums.gemspec
|
24
|
+
- Rakefile
|
25
|
+
- lib/PicasaWebAlbums.rb
|
26
|
+
- lib/PicasaWebAlbums/version.rb
|
27
|
+
- lib/album.rb
|
28
|
+
- lib/photo.rb
|
29
|
+
- lib/repository.rb
|
30
|
+
- lib/tag.rb
|
31
|
+
- readme.md
|
32
|
+
- test/test_albums.rb
|
33
|
+
- test/test_photos.rb
|
34
|
+
- test/test_tags.rb
|
35
|
+
homepage: https://github.com/mkraft/PicasaWebAlbums
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.9.3
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project: picasawebalbums
|
55
|
+
rubygems_version: 1.8.12
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Provides programmatic access to Picasa Web Albums data.
|
59
|
+
test_files:
|
60
|
+
- test/test_albums.rb
|
61
|
+
- test/test_photos.rb
|
62
|
+
- test/test_tags.rb
|