picasa 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91a09cb41c7e4e13eb830c390c2cac41ec9bc159
4
- data.tar.gz: 25ab483fc8fbe5ef7095ed336b991b19ca01830d
3
+ metadata.gz: 1c620c0f045fc74dc70cd23a64fbd92770c457e1
4
+ data.tar.gz: 52dada0a9d55ab05a8bf1d685445b727008c89fa
5
5
  SHA512:
6
- metadata.gz: b11f16ab4af155c874d5511eeb0ab4787720cff01639ada8508f93591a14a1318102e683adc74b446ad0519ae9bfc24c89825ec3638d74db88b6cb06336b04c9
7
- data.tar.gz: 5f8638b15e131fa0109f08bdcda0ad4c7ffe53a34acbcbd032172b193ae7ff99e04daef20965e2166ef1d6171275cad64bc277ffa08cfa700c02c7ae55a7f178
6
+ metadata.gz: 06ec8d9e5affa7181a84ab9536161bca5d53efb83749a90e45db4dc0759f080e1491728ae1c57191421661458cda13ac6bb14cc8f28c16b91fefda51a1362d89
7
+ data.tar.gz: ddcc148b54492c1db5b025e26c5ba71d70c86590c2402a8649517b64d1eece7d6f979221db5f41e7f9d454328bc73720f7d5025a235a76d910bc406c82a643b5
data/README.md CHANGED
@@ -8,7 +8,7 @@ Ruby library for [Picasa Web Albums Data API](https://developers.google.com/pica
8
8
  gem install picasa
9
9
  ```
10
10
 
11
- ## Usage
11
+ # Usage
12
12
 
13
13
  [Documentation](http://rubydoc.info/github/morgoth/picasa)
14
14
 
@@ -24,7 +24,7 @@ client.photo.create("album_id", file_path: "path/to/my-photo.png")
24
24
  # => Picasa::Presenter::Photo
25
25
  ```
26
26
 
27
- ### Authentication
27
+ ## Authentication
28
28
 
29
29
  When request is authenticated, response will contain private data, however this can be controlled by `access` parameter.
30
30
 
@@ -37,6 +37,8 @@ client = Picasa::Client.new(user_id: "some.user@gmail.com", access_token: "acces
37
37
  As authenticating by providing password is no longer possible due to google API shutdown https://developers.google.com/accounts/docs/AuthForInstalledApps
38
38
  you need to set `access_token` for authenticated requests.
39
39
 
40
+ ### One time usage
41
+
40
42
  For one time usage, you can retrieve access_token from google playground:
41
43
  * Visit https://developers.google.com/oauthplayground
42
44
  * Find "Picasa Web v2"
@@ -46,7 +48,50 @@ For one time usage, you can retrieve access_token from google playground:
46
48
 
47
49
  OAuth2 integration is not yet supported in this gem.
48
50
 
49
- ### Proxy
51
+ ### Permanent server side usage
52
+
53
+ * Go to https://console.developers.google.com
54
+ * Register an account and create project
55
+ * On "APIs & auth > Credentials" click "Create new Client ID"
56
+ * Choose "Installed application > Other"
57
+ * Note "Client ID" and "Client secret"
58
+ * Craft URL replacing `YOUR_CLIENT_ID` `https://accounts.google.com/o/oauth2/auth?scope=http://picasaweb.google.com/data/&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=YOUR_CLIENT_ID`
59
+ * Visit URL, grant access to your account and note `code`
60
+ * Install gem `signet`
61
+ * One time setup, to fetch `refresh_token`
62
+ ```ruby
63
+ client_id = "client-id"
64
+ client_secret = "client-secret"
65
+ code = "authorization-code"
66
+
67
+ require "signet/oauth_2/client"
68
+ signet = Signet::OAuth2::Client.new(
69
+ code: code,
70
+ token_credential_uri: "https://www.googleapis.com/oauth2/v3/token",
71
+ client_id: client_id,
72
+ client_secret: client_secret,
73
+ redirect_uri: "urn:ietf:wg:oauth:2.0:oob"
74
+ )
75
+ signet.fetch_access_token!
76
+ signet.refresh_token
77
+ ```
78
+ * Note `refresh_token`
79
+ * Before gem usage, you can get `access_token` by:
80
+ ```ruby
81
+ require "signet/oauth_2/client"
82
+ signet = Signet::OAuth2::Client.new(
83
+ client_id: client_id,
84
+ client_secret: client_secret,
85
+ token_credential_uri: "https://www.googleapis.com/oauth2/v3/token",
86
+ refresh_token: refresh_token
87
+ )
88
+ signet.refresh!
89
+
90
+ # Use access token with picasa gem
91
+ signet.access_token
92
+ ```
93
+
94
+ ## Proxy
50
95
 
51
96
  You can connect via proxy server setting `https_proxy` or `HTTPS_PROXY` environment variable to valid URL.
52
97
 
@@ -82,7 +127,7 @@ If you run out of quota and want to resize images to fit Picasa free storage lim
82
127
  thor imagery:resize path-to-folder-with-photos
83
128
  ```
84
129
 
85
- ### Boost
130
+ ## Boost
86
131
 
87
132
  Picasa uses gzipped requests to speedup fetching results. Benchmarks are available on [Vinicius Teles gist](https://gist.github.com/4012466)
88
133
 
@@ -1,20 +1,15 @@
1
1
  require "picasa"
2
2
 
3
3
  # add tags to your photos in an album.
4
- begin
5
- client = Picasa::Client.new(:user_id => "your_gmail_account", :password => "password")
6
- albums = client.album.list.entries
7
- album = albums.find { |album| album.title == "New Album" }
4
+ client = Picasa::Client.new(user_id: "your-gmail-account@gmail.com", access_token: "oauth-access-token")
5
+ albums = client.album.list.entries
6
+ album = albums.find { |album| album.title == "New Album" }
8
7
 
9
- photos = client.album.show(album.id).entries
8
+ photos = client.album.show(album.id).entries
10
9
 
11
- photos.each do |photo|
12
- client.tag.create(
13
- :album_id => album.id,
14
- :photo_id => photo.id,
15
- :tag_name => "test")
16
- end
17
-
18
- rescue Picasa::ForbiddenError
19
- puts "You have the wrong user_id or password."
10
+ photos.each do |photo|
11
+ client.tag.create(
12
+ :album_id => album.id,
13
+ :photo_id => photo.id,
14
+ :tag_name => "test")
20
15
  end
@@ -1,14 +1,9 @@
1
1
  require "picasa"
2
2
 
3
- begin
4
- client = Picasa::Client.new(:user_id => "your_gmail_account", :password => "password")
5
- # create new album.
6
- client.album.create(
7
- :title => "New Album",
8
- :summary => "This is a new album.",
9
- :access => "protected"
10
- )
11
-
12
- rescue Picasa::ForbiddenError
13
- puts "You have the wrong user_id or password."
14
- end
3
+ client = Picasa::Client.new(user_id: "your-gmail-account@gmail.com", access_token: "oauth-access-token")
4
+ # create new album.
5
+ client.album.create(
6
+ :title => "New Album",
7
+ :summary => "This is a new album.",
8
+ :access => "protected"
9
+ )
@@ -1,20 +1,16 @@
1
1
  require "picasa"
2
2
 
3
3
  # delete all photos in an album.
4
- begin
5
- client = Picasa::Client.new(:user_id => "your_gmail_account", :password => "password")
6
- albums = client.album.list.entries
7
- album = albums.find { |album| album.title == "New Album" }
4
+ client = Picasa::Client.new(user_id: "your-gmail-account@gmail.com", access_token: "oauth-access-token")
5
+ albums = client.album.list.entries
6
+ album = albums.find { |album| album.title == "New Album" }
8
7
 
9
- photos = client.album.show(album.id).entries
8
+ photos = client.album.show(album.id).entries
10
9
 
11
- photos.each do |photo|
12
- if client.tag.delete(album_id, photo.id)
13
- "#{photo.title} deleted"
14
- else
15
- "#{photo.title} failed to delete"
16
- end
10
+ photos.each do |photo|
11
+ if client.tag.delete(album_id, photo.id)
12
+ "#{photo.title} deleted"
13
+ else
14
+ "#{photo.title} failed to delete"
17
15
  end
18
- rescue Picasa::ForbiddenError
19
- puts "You have the wrong user_id or password."
20
16
  end
@@ -7,35 +7,30 @@ require "open-uri"
7
7
  username = "user@gmail.com"
8
8
  dir = "/Users/path.../"
9
9
 
10
- begin
11
- client = Picasa::Client.new(:user_id => username)
12
- albums = client.album.list.entries
13
-
14
- albums.each do |album|
15
- Dir.chdir(dir)
16
- this_album = client.album.show(album.id).entries
17
- Dir.mkdir(album.title)
18
- Dir.chdir(album.title)
19
-
20
- for photo in this_album
21
- begin
22
- get_string = photo.content.src
23
- puts "processing" << photo.id
24
-
25
- rescue Exception => e
26
- puts photo.id << " **ERROR**"
27
- puts e
28
- end
29
-
30
- open(get_string) do |f|
31
- File.open(photo.title, "wb") do |file|
32
- file.puts f.read
33
- end
34
- end
35
- puts "======================================"
10
+ client = Picasa::Client.new(:user_id => username)
11
+ albums = client.album.list.entries
12
+
13
+ albums.each do |album|
14
+ Dir.chdir(dir)
15
+ this_album = client.album.show(album.id).entries
16
+ Dir.mkdir(album.title)
17
+ Dir.chdir(album.title)
18
+
19
+ for photo in this_album
20
+ begin
21
+ get_string = photo.content.src
22
+ puts "processing" << photo.id
23
+
24
+ rescue Exception => e
25
+ puts photo.id << " **ERROR**"
26
+ puts e
36
27
  end
37
- end
38
28
 
39
- rescue Picasa::ForbiddenError
40
- puts "You have the wrong user_id or password."
29
+ open(get_string) do |f|
30
+ File.open(photo.title, "wb") do |file|
31
+ file.puts f.read
32
+ end
33
+ end
34
+ puts "======================================"
35
+ end
41
36
  end
@@ -7,31 +7,27 @@ require "open-uri"
7
7
  username = "user@gmail.com"
8
8
  dir = "/Users/path.../"
9
9
 
10
- begin
11
- client = Picasa::Client.new(:user_id => username)
12
- albums = client.album.list.entries
10
+ client = Picasa::Client.new(:user_id => username)
11
+ albums = client.album.list.entries
13
12
 
14
- album = albums.find { |album| album.title == "your_album_name" }
15
- photos = client.album.show(album.id).entries
13
+ album = albums.find { |album| album.title == "your_album_name" }
14
+ photos = client.album.show(album.id).entries
16
15
 
17
- photos.each do |photo|
18
- begin
19
- get_string = photo.content.src
20
- puts "processing " << photo.id
16
+ photos.each do |photo|
17
+ begin
18
+ get_string = photo.content.src
19
+ puts "processing " << photo.id
21
20
 
22
- rescue Exception => e
23
- puts photo.id << " **ERROR**"
24
- puts e
21
+ rescue Exception => e
22
+ puts photo.id << " **ERROR**"
23
+ puts e
25
24
 
26
- Dir.chdir(dir)
27
- open(get_string) do |f|
28
- File.open(photo.title, "wb") do |file|
29
- file.puts f.read
30
- end
31
- end
32
- puts "======================================"
25
+ Dir.chdir(dir)
26
+ open(get_string) do |f|
27
+ File.open(photo.title, "wb") do |file|
28
+ file.puts f.read
29
+ end
33
30
  end
34
- end
35
- rescue Picasa::ForbiddenError
36
- puts "You have the wrong user_id or password."
31
+ puts "======================================"
32
+ end
37
33
  end
@@ -1,12 +1,7 @@
1
1
  require "picasa"
2
2
 
3
3
  # get some albums.
4
- begin
5
- client = Picasa::Client.new(:user_id => "your_gmail_account", :password => "password")
4
+ client = Picasa::Client.new(user_id: "your-gmail-account@gmail.com", access_token: "oauth-access-token")
6
5
 
7
- albums = client.album.list.entries
8
- albums.each { |album| puts album.title }
9
-
10
- rescue Picasa::ForbiddenError
11
- puts "You have the wrong user_id or password."
12
- end
6
+ albums = client.album.list.entries
7
+ albums.each { |album| puts album.title }
@@ -1,16 +1,11 @@
1
1
  require "picasa"
2
2
 
3
3
  # get some photos in an album
4
- begin
5
- client = Picasa::Client.new(:user_id => "your_gmail_account", :password => "password")
4
+ client = Picasa::Client.new(user_id: "your-gmail-account@gmail.com", access_token: "oauth-access-token")
6
5
 
7
- albums = client.album.list.entries
8
- album = albums.find { |album| album.title == "New Album" }
6
+ albums = client.album.list.entries
7
+ album = albums.find { |album| album.title == "New Album" }
9
8
 
10
- photos = client.album.show(album.id).entries
9
+ photos = client.album.show(album.id).entries
11
10
 
12
- photos.each { |photo| puts photo.title }
13
-
14
- rescue Picasa::ForbiddenError
15
- puts "You have the wrong user_id or password."
16
- end
11
+ photos.each { |photo| puts photo.title }
@@ -0,0 +1,29 @@
1
+ require "signet/oauth_2/client"
2
+
3
+ # Setup your private credentials
4
+ client_id = "client-id"
5
+ client_secret = "client-secret"
6
+ code = "authorization-code"
7
+
8
+ signet = Signet::OAuth2::Client.new(
9
+ code: code,
10
+ token_credential_uri: "https://www.googleapis.com/oauth2/v3/token",
11
+ client_id: client_id,
12
+ client_secret: client_secret,
13
+ redirect_uri: "urn:ietf:wg:oauth:2.0:oob"
14
+ )
15
+ signet.fetch_access_token!
16
+ refresh_token = signet.refresh_token
17
+ # Note and store refresh_token
18
+
19
+ # In your app fetch access_token by:
20
+ signet = Signet::OAuth2::Client.new(
21
+ client_id: client_id,
22
+ client_secret: client_secret,
23
+ token_credential_uri: "https://www.googleapis.com/oauth2/v3/token",
24
+ refresh_token: refresh_token
25
+ )
26
+ signet.refresh!
27
+
28
+ # Use access token with picasa gem
29
+ signet.access_token
@@ -1,23 +1,18 @@
1
1
  require "picasa"
2
2
 
3
3
  # upload photo
4
- begin
5
- client = Picasa::Client.new(:user_id => "your_gmail_account", :password => "password")
4
+ client = Picasa::Client.new(user_id: "your-gmail-account@gmail.com", access_token: "oauth-access-token")
6
5
 
7
- photo_bin = File.binread("./test.jpg")
6
+ photo_bin = File.binread("./test.jpg")
8
7
 
9
- albums = client.album.list.entries
10
- album = albums.find { |album| album.title == "New Album" }
8
+ albums = client.album.list.entries
9
+ album = albums.find { |album| album.title == "New Album" }
11
10
 
12
- client.photo.create(album.id,
13
- {
14
- :binary => photo_bin,
15
- :content_type => "image/jpeg",
16
- :title => "Test Photo",
17
- :summary => "Hoge hoge"
18
- }
19
- )
20
-
21
- rescue Picasa::ForbiddenError
22
- puts "You have the wrong user_id or password."
23
- end
11
+ client.photo.create(album.id,
12
+ {
13
+ :binary => photo_bin,
14
+ :content_type => "image/jpeg",
15
+ :title => "Test Photo",
16
+ :summary => "Hoge hoge"
17
+ }
18
+ )
@@ -10,18 +10,7 @@ module Picasa
10
10
  end
11
11
 
12
12
  def inspect
13
- inspection = methods_to_inspect.map do |method|
14
- value = send(method)
15
- value = value.nil? ? "nil" : value.inspect
16
- "#{method}: #{value}"
17
- end.join(", ")
18
- "#<#{self.class} #{inspection}>"
19
- end
20
-
21
- private
22
-
23
- def methods_to_inspect
24
- public_methods - Object.methods - [:parsed_body, :entries]
13
+ "#<#{self.class}>"
25
14
  end
26
15
  end
27
16
  end
@@ -10,12 +10,16 @@ module Picasa
10
10
 
11
11
  # @return [String]
12
12
  def cover_photo_url
13
- @cover_photo_url ||= parsed_body['media$content'][0]['url']
13
+ return @cover_photo_url if defined?(@cover_photo_url)
14
+ content = safe_retrieve(parsed_body, "media$content")
15
+ @cover_photo_url = content && content[0]["url"]
14
16
  end
15
17
 
16
18
  # @return [String]
17
19
  def credit
18
- @credit ||= parsed_body["media$credit"][0]["$t"]
20
+ return @credit if defined?(@credit)
21
+ content = safe_retrieve(parsed_body, "media$credit")
22
+ @credit = content && content[0]["$t"]
19
23
  end
20
24
 
21
25
  # @return [String]
@@ -1,3 +1,3 @@
1
1
  module Picasa
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -28,6 +28,4 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "webmock"
29
29
  spec.add_development_dependency "mocha", ">= 0.13.0"
30
30
  spec.add_development_dependency "vcr", ">= 2.4.0"
31
-
32
- spec.post_install_message = "Authenticating by providing password is no longer possible due to google API shutdown https://developers.google.com/accounts/docs/AuthForInstalledApps You need to set `access_token` for authenticated requests now."
33
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picasa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Wnętrzak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -128,6 +128,7 @@ files:
128
128
  - examples/download_one_album.rb
129
129
  - examples/get_some_albums.rb
130
130
  - examples/get_some_photos.rb
131
+ - examples/refresh-access-token.rb
131
132
  - examples/upload_photo.rb
132
133
  - extra/Thorfile
133
134
  - lib/picasa.rb
@@ -203,9 +204,7 @@ homepage: https://github.com/morgoth/picasa
203
204
  licenses:
204
205
  - MIT
205
206
  metadata: {}
206
- post_install_message: Authenticating by providing password is no longer possible due
207
- to google API shutdown https://developers.google.com/accounts/docs/AuthForInstalledApps
208
- You need to set `access_token` for authenticated requests now.
207
+ post_install_message:
209
208
  rdoc_options: []
210
209
  require_paths:
211
210
  - lib
@@ -221,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
220
  version: '0'
222
221
  requirements: []
223
222
  rubyforge_project:
224
- rubygems_version: 2.4.7
223
+ rubygems_version: 2.4.8
225
224
  signing_key:
226
225
  specification_version: 4
227
226
  summary: Simple Google Picasa managment
@@ -261,3 +260,4 @@ test_files:
261
260
  - test/presenter/photo_test.rb
262
261
  - test/template_test.rb
263
262
  - test/utils_test.rb
263
+ has_rdoc: