picasawebalbums 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/PicasaWebAlbums.rb +1 -0
- data/lib/PicasaWebAlbums/version.rb +1 -1
- data/lib/repository.rb +26 -0
- data/readme.md +12 -5
- data/test/test_tags.rb +8 -0
- metadata +1 -1
data/lib/PicasaWebAlbums.rb
CHANGED
data/lib/repository.rb
CHANGED
@@ -67,6 +67,23 @@ module PicasaWebAlbums
|
|
67
67
|
return photo_to_return
|
68
68
|
end
|
69
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
|
+
|
70
87
|
def get_all_tags
|
71
88
|
xml = get_xml("http://picasaweb.google.com/data/feed/api/user/#{@email}?kind=tag")
|
72
89
|
tags = []
|
@@ -88,6 +105,15 @@ module PicasaWebAlbums
|
|
88
105
|
|
89
106
|
private
|
90
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
|
+
|
91
117
|
def get_xml(url)
|
92
118
|
uri = URI(url)
|
93
119
|
request = Net::HTTP::Get.new(uri.request_uri)
|
data/readme.md
CHANGED
@@ -6,15 +6,15 @@ Gem for accessing photos and albums from Picasa Web Albums
|
|
6
6
|
Installation
|
7
7
|
------------
|
8
8
|
|
9
|
-
gem install
|
9
|
+
gem install picasawebalbums
|
10
10
|
|
11
11
|
Rails/Application Integration
|
12
12
|
-----------------------------
|
13
13
|
|
14
14
|
Add one of the below lines to the Gemfile:
|
15
15
|
|
16
|
-
- `gem '
|
17
|
-
- `gem '
|
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
18
|
|
19
19
|
Then run `bundle install`
|
20
20
|
|
@@ -24,7 +24,7 @@ Code Examples
|
|
24
24
|
Print the title of all albums
|
25
25
|
|
26
26
|
repo = PicasaWebAlbums.get_repository('someperson@gmail.com', 'somepassword')
|
27
|
-
albums = repo.
|
27
|
+
albums = repo.get_all_albums
|
28
28
|
albums.each { |album| puts album.title }
|
29
29
|
|
30
30
|
Print the URL of each photo in the album titled "Big Boy"
|
@@ -34,6 +34,12 @@ Print the URL of each photo in the album titled "Big Boy"
|
|
34
34
|
photos = repo.get_photos_by_album_id(album.id)
|
35
35
|
photos.each { |photo| puts photo.url }
|
36
36
|
|
37
|
+
Get photos with specific tags
|
38
|
+
|
39
|
+
repo = PicasaWebAlbums.get_repository('someperson@gmail.com', 'somepassword')
|
40
|
+
photos = repo.get_photos_by_tags(['cat', 'dog'])
|
41
|
+
# returns photos tagged with 'cat' AND 'dog'
|
42
|
+
|
37
43
|
Repository Methods
|
38
44
|
-------------------
|
39
45
|
|
@@ -48,6 +54,7 @@ Repository Methods
|
|
48
54
|
|
49
55
|
- `get_photos_by_album_id(album_id)`
|
50
56
|
- `get_photo_by_album_id_and_photo_id(album_id, photo_id)`
|
57
|
+
- `get_photos_by_tags(tags_array)`
|
51
58
|
|
52
59
|
### Tags
|
53
60
|
|
@@ -85,4 +92,4 @@ Domain Object Properties
|
|
85
92
|
Additional Documentation
|
86
93
|
------------------------
|
87
94
|
|
88
|
-
Additional documentation can be found on the [rubydoc pages](http://rubydoc.info/gems/
|
95
|
+
Additional documentation can be found on the [rubydoc pages](http://rubydoc.info/gems/picasawebalbums).
|
data/test/test_tags.rb
CHANGED
@@ -28,6 +28,14 @@ module PicasaWebAlbums
|
|
28
28
|
assert tags.count > 0
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
context "get photos by tags" do
|
33
|
+
should "return at least 1 photo" do
|
34
|
+
repo = PicasaWebAlbums.get_repository('apitest33@gmail.com', 'ruhak23A')
|
35
|
+
photos = repo.get_photos_by_tags(['penny'])
|
36
|
+
assert photos.count > 0
|
37
|
+
end
|
38
|
+
end
|
31
39
|
|
32
40
|
end
|
33
41
|
end
|