picasawebalbums 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/PicasaWebAlbums/version.rb +1 -1
- data/lib/PicasaWebAlbums.rb +1 -9
- data/lib/{album.rb → domain/album.rb} +0 -0
- data/lib/{photo.rb → domain/photo.rb} +0 -0
- data/lib/{tag.rb → domain/tag.rb} +0 -0
- data/lib/repositories/albums_repository.rb +39 -0
- data/lib/repositories/photos_repository.rb +66 -0
- data/lib/repositories/repository.rb +49 -0
- data/lib/repositories/tags_repository.rb +22 -0
- data/readme.md +8 -3
- metadata +8 -5
- data/lib/repository.rb +0 -152
data/lib/PicasaWebAlbums.rb
CHANGED
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'net/http'
|
3
|
-
require 'rexml/document'
|
4
|
-
require 'date'
|
5
|
-
require 'uri'
|
6
|
-
require_relative 'album'
|
7
|
-
require_relative 'photo'
|
8
|
-
require_relative 'tag'
|
9
|
-
require_relative 'repository'
|
1
|
+
require_relative 'repositories/repository'
|
10
2
|
|
11
3
|
module PicasaWebAlbums
|
12
4
|
def self.get_repository(email, password)
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'date'
|
2
|
+
require_relative '../domain/album'
|
3
|
+
|
4
|
+
module AlbumsRepository
|
5
|
+
def get_all_albums
|
6
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=album&access=all")
|
7
|
+
albums = []
|
8
|
+
xml.root.elements.each("//entry") do |entry|
|
9
|
+
gallery = PicasaWebAlbums::Album.new
|
10
|
+
gallery.id = entry.elements["gphoto:id"].text
|
11
|
+
gallery.title = entry.elements["title"].text
|
12
|
+
gallery.date_created = DateTime.parse(entry.elements["published"].text)
|
13
|
+
gallery.date_updated = DateTime.parse(entry.elements["updated"].text)
|
14
|
+
gallery.slug = entry.elements["gphoto:name"].text
|
15
|
+
gallery.cover_photo_url = entry.elements["media:group/media:content"].attributes["url"]
|
16
|
+
gallery.description = entry.elements["media:group/media:description"].text
|
17
|
+
albums << gallery
|
18
|
+
end
|
19
|
+
return albums
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_album_by_id(id)
|
23
|
+
albums = get_all_albums
|
24
|
+
album_to_return = albums[albums.find_index{|album| album.id == id.to_s}]
|
25
|
+
return album_to_return
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_album_by_title(title)
|
29
|
+
albums = get_all_albums
|
30
|
+
album_to_return = albums[albums.find_index{|album| album.title == title.to_s}]
|
31
|
+
return album_to_return
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_album_by_slug(slug)
|
35
|
+
albums = get_all_albums
|
36
|
+
album_to_return = albums[albums.find_index{|album| album.slug == slug.to_s}]
|
37
|
+
return album_to_return
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative '../domain/photo'
|
2
|
+
|
3
|
+
module PhotosRepository
|
4
|
+
def get_photos_by_album_id(id)
|
5
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/base/user/#{@email}/albumid/#{id}")
|
6
|
+
photos = []
|
7
|
+
xml.root.elements.each("//entry") do |entry|
|
8
|
+
photo = PicasaWebAlbums::Photo.new
|
9
|
+
photo.id = get_photo_id_from_photo_id_url(entry.elements["id"].text)
|
10
|
+
photo.url = entry.elements["media:group/media:content"].attributes["url"]
|
11
|
+
photo.width = entry.elements["media:group/media:content"].attributes["width"].to_i
|
12
|
+
photo.height = entry.elements["media:group/media:content"].attributes["height"].to_i
|
13
|
+
photo.caption = entry.elements["media:group/media:description"].text
|
14
|
+
photo.file_name = entry.elements["media:group/media:title"].text
|
15
|
+
photos << photo
|
16
|
+
end
|
17
|
+
return photos
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_photo_by_album_id_and_photo_id(album_id, photo_id)
|
21
|
+
photos = get_photos_by_album_id(album_id)
|
22
|
+
photo_to_return = PicasaWebAlbums::Photo.new
|
23
|
+
photos.each do |photo|
|
24
|
+
if photo.id == photo_id
|
25
|
+
photo_to_return = photo
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return photo_to_return
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_photos_by_tags(tags)
|
32
|
+
url = "http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=photo&tag=#{get_tags_string(tags)}"
|
33
|
+
xml = get_xml(url)
|
34
|
+
photos = []
|
35
|
+
xml.root.elements.each("//entry") do |entry|
|
36
|
+
photo = PicasaWebAlbums::Photo.new
|
37
|
+
photo.id = entry.elements["gphoto:id"].text
|
38
|
+
photo.url = entry.elements["media:group/media:content"].attributes["url"]
|
39
|
+
photo.width = entry.elements["media:group/media:content"].attributes["width"].to_i
|
40
|
+
photo.height = entry.elements["media:group/media:content"].attributes["height"].to_i
|
41
|
+
photo.caption = entry.elements["media:group/media:description"].text
|
42
|
+
photo.file_name = entry.elements["media:group/media:title"].text
|
43
|
+
photos << photo
|
44
|
+
end
|
45
|
+
return photos
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def get_tags_string(tags)
|
51
|
+
tags_string = ""
|
52
|
+
tags.each do |tag|
|
53
|
+
tags_string += URI.escape(tag.strip)
|
54
|
+
tags_string += '%2C' unless tag == tags.last
|
55
|
+
end
|
56
|
+
return tags_string
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_photo_id_from_photo_id_url(photo_id_url)
|
60
|
+
start_index = photo_id_url.index('/photoid/') + 9
|
61
|
+
slice_of_id_url_to_end = photo_id_url[start_index..-1]
|
62
|
+
end_index = slice_of_id_url_to_end.index(/[?|\/]/)
|
63
|
+
id = slice_of_id_url_to_end[0...end_index]
|
64
|
+
return id
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'uri'
|
4
|
+
require_relative 'albums_repository'
|
5
|
+
require_relative 'photos_repository'
|
6
|
+
require_relative 'tags_repository'
|
7
|
+
|
8
|
+
module PicasaWebAlbums
|
9
|
+
class Repository
|
10
|
+
include AlbumsRepository
|
11
|
+
include PhotosRepository
|
12
|
+
include TagsRepository
|
13
|
+
|
14
|
+
def initialize(email, password)
|
15
|
+
@email = email
|
16
|
+
@authentication_token = get_authentication_token(email, password)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_xml(url)
|
22
|
+
uri = URI(url)
|
23
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
24
|
+
request['Authorization'] = @authentication_token
|
25
|
+
response = Net::HTTP.start(uri.hostname, uri.port) { |http|
|
26
|
+
http.request(request)
|
27
|
+
}
|
28
|
+
xml = REXML::Document.new(response.body)
|
29
|
+
return xml
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_authentication_token(email, password)
|
33
|
+
uri = URI("https://www.google.com/accounts/ClientLogin")
|
34
|
+
body = ""
|
35
|
+
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
36
|
+
request = Net::HTTP::Post.new uri.request_uri
|
37
|
+
data = "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=lh2&source=someapp1"
|
38
|
+
response = http.request(request, data)
|
39
|
+
body = response.body
|
40
|
+
end
|
41
|
+
start_index = body.index('Auth=')
|
42
|
+
slice_of_auth_to_end = body[start_index..-1]
|
43
|
+
end_index = slice_of_auth_to_end.index("\n")
|
44
|
+
auth_string = slice_of_auth_to_end[0...end_index]
|
45
|
+
auth_token = "GoogleLogin #{auth_string}"
|
46
|
+
return auth_token
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../domain/tag'
|
2
|
+
|
3
|
+
module TagsRepository
|
4
|
+
def get_all_tags
|
5
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=tag")
|
6
|
+
tags = []
|
7
|
+
xml.root.elements.each("//entry") do |entry|
|
8
|
+
tag = PicasaWebAlbums::Tag.new
|
9
|
+
tag.text = entry.elements["title"].text
|
10
|
+
tags << tag
|
11
|
+
end
|
12
|
+
return tags
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_tags_by_album_id(album_id)
|
16
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/userID/albumid/#{album_id}?kind=tag")
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_tags_by_album_id_and_photo_id(album_id, photo_id)
|
20
|
+
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/default/albumid/#{album_id}/photoid/#{photo_id}?kind=tag")
|
21
|
+
end
|
22
|
+
end
|
data/readme.md
CHANGED
@@ -13,8 +13,8 @@ Rails/Application Integration
|
|
13
13
|
|
14
14
|
Add one of the below lines to the Gemfile:
|
15
15
|
|
16
|
-
- `gem 'picasawebalbums'
|
17
|
-
- `gem 'picasawebalbums', :git => 'git@github.com:mkraft/PicasaWebAlbums.git'`
|
16
|
+
- `gem 'picasawebalbums'`, or
|
17
|
+
- `gem 'picasawebalbums', :git => 'git@github.com:mkraft/PicasaWebAlbums.git'`
|
18
18
|
|
19
19
|
Then run `bundle install`
|
20
20
|
|
@@ -92,4 +92,9 @@ Domain Object Properties
|
|
92
92
|
Additional Documentation
|
93
93
|
------------------------
|
94
94
|
|
95
|
-
Additional documentation can be found on the [rubydoc pages](http://rubydoc.info/gems/picasawebalbums)
|
95
|
+
Additional documentation can be found on the [rubydoc pages](http://rubydoc.info/gems/picasawebalbums)
|
96
|
+
|
97
|
+
Feature Requests and Bugs
|
98
|
+
-------------------------
|
99
|
+
|
100
|
+
Please feel free to log any bugs or feature requests in the [Issues tab on Github](https://github.com/mkraft/PicasaWebAlbums/issues). Thank you.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picasawebalbums
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -24,10 +24,13 @@ files:
|
|
24
24
|
- Rakefile
|
25
25
|
- lib/PicasaWebAlbums.rb
|
26
26
|
- lib/PicasaWebAlbums/version.rb
|
27
|
-
- lib/album.rb
|
28
|
-
- lib/photo.rb
|
29
|
-
- lib/
|
30
|
-
- lib/
|
27
|
+
- lib/domain/album.rb
|
28
|
+
- lib/domain/photo.rb
|
29
|
+
- lib/domain/tag.rb
|
30
|
+
- lib/repositories/albums_repository.rb
|
31
|
+
- lib/repositories/photos_repository.rb
|
32
|
+
- lib/repositories/repository.rb
|
33
|
+
- lib/repositories/tags_repository.rb
|
31
34
|
- readme.md
|
32
35
|
- test/test_albums.rb
|
33
36
|
- test/test_photos.rb
|
data/lib/repository.rb
DELETED
@@ -1,152 +0,0 @@
|
|
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_photos_by_tags(tags)
|
71
|
-
url = "http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=photo&tag=#{get_tags_string(tags)}"
|
72
|
-
xml = get_xml(url)
|
73
|
-
photos = []
|
74
|
-
xml.root.elements.each("//entry") do |entry|
|
75
|
-
photo = Photo.new
|
76
|
-
photo.id = entry.elements["gphoto:id"].text
|
77
|
-
photo.url = entry.elements["media:group/media:content"].attributes["url"]
|
78
|
-
photo.width = entry.elements["media:group/media:content"].attributes["width"].to_i
|
79
|
-
photo.height = entry.elements["media:group/media:content"].attributes["height"].to_i
|
80
|
-
photo.caption = entry.elements["media:group/media:description"].text
|
81
|
-
photo.file_name = entry.elements["media:group/media:title"].text
|
82
|
-
photos << photo
|
83
|
-
end
|
84
|
-
return photos
|
85
|
-
end
|
86
|
-
|
87
|
-
def get_all_tags
|
88
|
-
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=tag")
|
89
|
-
tags = []
|
90
|
-
xml.root.elements.each("//entry") do |entry|
|
91
|
-
tag = Tag.new
|
92
|
-
tag.text = entry.elements["title"].text
|
93
|
-
tags << tag
|
94
|
-
end
|
95
|
-
return tags
|
96
|
-
end
|
97
|
-
|
98
|
-
def get_tags_by_album_id(album_id)
|
99
|
-
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/userID/albumid/#{album_id}?kind=tag")
|
100
|
-
end
|
101
|
-
|
102
|
-
def get_tags_by_album_id_and_photo_id(album_id, photo_id)
|
103
|
-
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/default/albumid/#{album_id}/photoid/#{photo_id}?kind=tag")
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def get_tags_string(tags)
|
109
|
-
tags_string = ""
|
110
|
-
tags.each do |tag|
|
111
|
-
tags_string += URI.escape(tag.strip)
|
112
|
-
tags_string += '%2C' unless tag == tags.last
|
113
|
-
end
|
114
|
-
return tags_string
|
115
|
-
end
|
116
|
-
|
117
|
-
def get_xml(url)
|
118
|
-
uri = URI(url)
|
119
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
120
|
-
request['Authorization'] = @authentication_token
|
121
|
-
response = Net::HTTP.start(uri.hostname, uri.port) { |http|
|
122
|
-
http.request(request)
|
123
|
-
}
|
124
|
-
xml = REXML::Document.new(response.body)
|
125
|
-
return xml
|
126
|
-
end
|
127
|
-
|
128
|
-
def get_photo_id_from_photo_id_url(photo_id_url)
|
129
|
-
start_index = photo_id_url.index('/photoid/') + 9
|
130
|
-
slice_of_id_url_to_end = photo_id_url[start_index..-1]
|
131
|
-
end_index = slice_of_id_url_to_end.index(/[?|\/]/)
|
132
|
-
id = slice_of_id_url_to_end[0...end_index]
|
133
|
-
return id
|
134
|
-
end
|
135
|
-
|
136
|
-
def get_authentication_token(email, password)
|
137
|
-
uri = URI("https://www.google.com/accounts/ClientLogin")
|
138
|
-
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
139
|
-
request = Net::HTTP::Post.new uri.request_uri
|
140
|
-
data = "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=lh2&source=someapp1"
|
141
|
-
response = http.request(request, data)
|
142
|
-
@body = response.body
|
143
|
-
end
|
144
|
-
start_index = @body.index('Auth=')
|
145
|
-
slice_of_auth_to_end = @body[start_index..-1]
|
146
|
-
end_index = slice_of_auth_to_end.index("\n")
|
147
|
-
auth_string = slice_of_auth_to_end[0...end_index]
|
148
|
-
auth_token = "GoogleLogin #{auth_string}"
|
149
|
-
return auth_token
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|