picasa-ruby 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,2 +1,3 @@
1
+ v0.1.2 added photos and albums
1
2
  v0.1.1 update client
2
3
  v0.1.0 first release
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('picasa-ruby', '0.1.1') do |p|
6
+ Echoe.new('picasa-ruby', '0.1.2') do |p|
7
7
  p.description = "Ruby library for Picasa Web Albums API."
8
8
  p.url = "http://github.com/23ninja/picasa-ruby"
9
9
  p.author = "Iskander Haziev"
data/lib/picasa/album.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  module Picasa
2
2
  class Album
3
- def initialize
4
-
5
- end
3
+ attr_accessor :id, :title, :summary, :size, :image, :thumbnail
6
4
  end
7
5
  end
data/lib/picasa/client.rb CHANGED
@@ -1,25 +1,75 @@
1
1
  require 'oauth'
2
2
  require 'oauth/request_proxy/typhoeus_request'
3
+ require 'xmlsimple'
3
4
  module Picasa
4
5
  class Client
5
6
  BASE_URL = 'https://picasaweb.google.com/data'
6
7
 
7
- def initialize(api_key, api_secret, oauth_token, oauth_secret = nil)
8
- @consumer = ::OAuth::Consumer.new(api_key,api_secret, :site => BASE_URL)
9
- @token = ::OAuth::Token.new(oauth_token, oauth_secret)
10
- @oauth_params = {:consumer => @consumer, :token => @token}
8
+ def initialize(api_key = nil, api_secret = nil, token = nil, secret = nil)
9
+ @api_key, @api_secret = api_key, api_secret
11
10
  @client = ::Typhoeus::Hydra.new
11
+ # if api call protected, create token and consumer
12
+ if protected_api_call?
13
+ @consumer = ::OAuth::Consumer.new(api_key,api_secret, :site => BASE_URL)
14
+ @token = ::OAuth::Token.new(token, secret)
15
+ end
12
16
  end
13
17
 
14
18
  def call(uri)
15
19
  request = ::Typhoeus::Request.new(BASE_URL + uri)
20
+ authorize_request!(request) if protected_api_call?
21
+ @client.queue(request)
22
+ @client.run
23
+ XmlSimple.xml_in(request.response.body)
24
+ end
25
+
26
+ def albums(user)
27
+ xml = call("/feed/api/user/#{user}")
28
+ albums = []
29
+ xml['entry'].each do |entry|
30
+ album = Picasa::Album.new
31
+ album.id = entry['id'][1]
32
+ album.title = entry['title'][0]['content']
33
+ album.summary = entry['summary'][0]['content']
34
+ album.size = entry['numphotos'][0].to_i
35
+ album.image = entry['group'][0]['content']['url']
36
+ album.thumbnail = entry['group'][0]['thumbnail'][0]['url']
37
+ albums << album
38
+ end if xml['entry']
39
+ albums
40
+ end
41
+
42
+ def photos(user, album_id)
43
+ xml = call("/feed/api/user/#{user}/albumid/#{album_id}")
44
+ photos = []
45
+ xml['entry'].each do |entry|
46
+ photo = Picasa::Photo.new
47
+ photo.title = entry['group'][0]['description'][0]['content']
48
+ photo.thumbnails = [
49
+ entry['group'][0]['thumbnail'][0]['url'],
50
+ entry['group'][0]['thumbnail'][1]['url'],
51
+ entry['group'][0]['thumbnail'][2]['url']
52
+ ]
53
+ photo.image = entry['content']['src']
54
+ photos << photo
55
+ end if xml['entry']
56
+ photos
57
+ end
58
+
59
+ protected
60
+ def protected_api_call?
61
+ !@api_key.nil?
62
+ end
63
+
64
+ def authorize_request!(request)
16
65
  oauth_helper = ::OAuth::Client::Helper.new(
17
- request, @oauth_params.merge(:request_uri => BASE_URL + uri)
66
+ request, {
67
+ :consumer => @consumer,
68
+ :token => @token,
69
+ :request_uri => request.url
70
+ }
18
71
  )
19
72
  request.headers.merge!({"Authorization" => oauth_helper.header})
20
- @client.queue(request)
21
- @client.run
22
- response = request.response
23
73
  end
24
74
  end
25
75
  end
data/lib/picasa/photo.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  module Picasa
2
2
  class Photo
3
- def initialize
4
-
5
- end
3
+ attr_accessor :title, :image, :thumbnails
6
4
  end
7
5
  end
data/picasa-ruby.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{picasa-ruby}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [%q{Iskander Haziev}]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picasa-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &7203820 !ruby/object:Gem::Requirement
16
+ requirement: &7169500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7203820
24
+ version_requirements: *7169500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: typhoeus
27
- requirement: &7198000 !ruby/object:Gem::Requirement
27
+ requirement: &7166040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *7198000
35
+ version_requirements: *7166040
36
36
  description: Ruby library for Picasa Web Albums API.
37
37
  email: gvalmon@gmail.com
38
38
  executables: []