google-picasa 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/google-picasa.gemspec +1 -0
- data/lib/google-picasa/multipartpost.rb +56 -0
- data/lib/google-picasa/picasa_example.rb +87 -0
- data/lib/google-picasa/version.rb +1 -1
- metadata +15 -2
data/google-picasa.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{Access Picasa Web Album using pure Ruby code.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "google-picasa"
|
15
|
+
s.add_runtime_dependency "xml-simple"
|
15
16
|
|
16
17
|
s.files = `git ls-files`.split("\n")
|
17
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#--
|
2
|
+
# Helper class to prepare an HTTP POST request with a file upload
|
3
|
+
# Mostly taken from http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/113774
|
4
|
+
# Anything that's broken and wrong probably the fault of Bill Stilwell (bill@marginalia.org)
|
5
|
+
#++
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'mime/types'
|
9
|
+
require 'net/http'
|
10
|
+
|
11
|
+
class Param
|
12
|
+
attr_accessor :k, :v
|
13
|
+
def initialize( k, v )
|
14
|
+
@k = k
|
15
|
+
@v = v
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_multipart
|
19
|
+
return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"\r\n\r\n#{v}\r\n"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FileParam
|
24
|
+
attr_accessor :k, :filename, :content
|
25
|
+
def initialize( k, filename, content )
|
26
|
+
@k = k
|
27
|
+
@filename = filename
|
28
|
+
@content = content
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_multipart
|
32
|
+
return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"; filename=\"#{@filename}\"\r\n" +
|
33
|
+
"Content-Transfer-Encoding: binary\r\n" +
|
34
|
+
"Content-Type: #{MIME::Types.type_for(@filename)}\r\n\r\n" + @content + "\r\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class MultipartPost
|
39
|
+
BOUNDARY = 'flickrrocks-aaaaaabbbb0000'
|
40
|
+
HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY + " "}
|
41
|
+
|
42
|
+
def prepare_query ( params )
|
43
|
+
fp = []
|
44
|
+
params.each do |k,v|
|
45
|
+
if v.respond_to?(:read)
|
46
|
+
fp.push(FileParam.new(k,v.path,v.read))
|
47
|
+
else
|
48
|
+
fp.push(Param.new(k,v))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
query = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--"
|
52
|
+
return query, HEADER
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "picasa"
|
2
|
+
|
3
|
+
picasa = Picasa::Picasa.new
|
4
|
+
puts picasa.login("you@gmail.com", "yourpass")
|
5
|
+
puts picasa.picasa_session.auth_key
|
6
|
+
|
7
|
+
albums = []
|
8
|
+
# get albums of logged in account
|
9
|
+
albums = picasa.albums(:access => "private")
|
10
|
+
albums.each do |album|
|
11
|
+
puts "===== Album ======"
|
12
|
+
puts album.id
|
13
|
+
puts album.name
|
14
|
+
|
15
|
+
puts album.thumbnail.url
|
16
|
+
puts album.thumbnail.width
|
17
|
+
puts album.thumbnail.height
|
18
|
+
|
19
|
+
# get photos of an album
|
20
|
+
photos = album.photos
|
21
|
+
if(photos.size > 0)
|
22
|
+
photos.each do |photo|
|
23
|
+
puts "====== Photo ====="
|
24
|
+
puts photo.id
|
25
|
+
puts photo.title
|
26
|
+
puts photo.url
|
27
|
+
photo.thumbnails.each do |thumbnail|
|
28
|
+
puts thumbnail.url
|
29
|
+
puts thumbnail.width
|
30
|
+
puts thumbnail.height
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts "====== No photo for this album ====="
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
# get photos using album name
|
40
|
+
photos = picasa.photos(:album => "AlbumFromRuby")
|
41
|
+
puts "====== Photos of AlbumFromRuby ====="
|
42
|
+
if(photos.size > 0)
|
43
|
+
photos.each do |photo|
|
44
|
+
puts "====== Photos ====="
|
45
|
+
puts photo.id
|
46
|
+
puts photo.title
|
47
|
+
puts photo.url
|
48
|
+
photo.thumbnails.each do |thumbnail|
|
49
|
+
puts thumbnail.url
|
50
|
+
puts thumbnail.width
|
51
|
+
puts thumbnail.height
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "====== No photo for this album ====="
|
56
|
+
end
|
57
|
+
|
58
|
+
# get photos using another user_id and album name
|
59
|
+
photos = []
|
60
|
+
photos = albums[0].photos(:user_id => "me")
|
61
|
+
|
62
|
+
photos.each do |photo|
|
63
|
+
puts photo.id
|
64
|
+
puts photo.title
|
65
|
+
puts photo.description
|
66
|
+
puts photo.url
|
67
|
+
photo.thumbnails.each do |thumbnail|
|
68
|
+
puts thumbnail.url
|
69
|
+
puts thumbnail.width
|
70
|
+
puts thumbnail.height
|
71
|
+
end
|
72
|
+
puts "====== Photo ====="
|
73
|
+
end
|
74
|
+
|
75
|
+
# Create an album
|
76
|
+
album = picasa.create_album(:title => "Album From Ruby",
|
77
|
+
:summary => "This album is created from ruby code",
|
78
|
+
:location => "Bangladesh", :keywords => "keyword1, keyword2")
|
79
|
+
puts album.inspect
|
80
|
+
|
81
|
+
# Post photo to an album
|
82
|
+
fileName = "C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Blue hills.jpg"
|
83
|
+
image_data = open(fileName, "rb").read
|
84
|
+
photo = picasa.post_photo(image_data, :album => "AlbumFromRuby",
|
85
|
+
:summary => "Upload2 from ruby api", :title => "From Ruby 2",
|
86
|
+
:local_file_name => "Blue hills.jpg")
|
87
|
+
puts photo.inspect
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-picasa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,18 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2011-11-26 00:00:00.000000000Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: xml-simple
|
16
|
+
requirement: &86217460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *86217460
|
14
25
|
description: Access Picasa Web Album using pure Ruby code.
|
15
26
|
email:
|
16
27
|
- dmitry@trager.ru
|
@@ -23,6 +34,8 @@ files:
|
|
23
34
|
- Rakefile
|
24
35
|
- google-picasa.gemspec
|
25
36
|
- lib/google-picasa.rb
|
37
|
+
- lib/google-picasa/multipartpost.rb
|
38
|
+
- lib/google-picasa/picasa_example.rb
|
26
39
|
- lib/google-picasa/version.rb
|
27
40
|
homepage: http://code.google.com/p/picasaonrails
|
28
41
|
licenses: []
|