commonthread-flickr_fu 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +37 -1
- data/Rakefile +30 -11
- data/flickr_fu.gemspec +3 -2
- data/lib/flickr/auth.rb +8 -1
- data/lib/flickr/base.rb +40 -18
- data/lib/flickr/errors.rb +20 -0
- data/lib/flickr/license.rb +10 -0
- data/lib/flickr/photo.rb +82 -106
- data/lib/flickr/photos.rb +19 -10
- data/lib/flickr/token.rb +1 -1
- data/lib/flickr_fu.rb +1 -1
- metadata +3 -2
data/README
CHANGED
@@ -23,6 +23,12 @@
|
|
23
23
|
|
24
24
|
http://www.commonthread.com/projects/flickr_fu/rdoc/
|
25
25
|
|
26
|
+
== Example flickr.yml
|
27
|
+
--- !map:HashWithIndifferentAccess
|
28
|
+
key: "YOUR KEY"
|
29
|
+
secret: "YOUR SECRET"
|
30
|
+
token_cache: "token_cache.yml"
|
31
|
+
|
26
32
|
== Authorization
|
27
33
|
|
28
34
|
To authorise your application to access Flickr using your API key you will
|
@@ -32,6 +38,12 @@
|
|
32
38
|
access it from your browser. Confirm the application has permission at
|
33
39
|
the level you have specified.
|
34
40
|
|
41
|
+
Note that flickr has different types of keys. If you use one for a webapplication,
|
42
|
+
which is most likely, you need to define a callback and somehow make sure that
|
43
|
+
you connect the parameter :frob that flickr send via the callback is assigned
|
44
|
+
to the right user account. The best way to do this is to loop over all the current
|
45
|
+
user's flickr accounts and try flickr.auth.token with the :frob.
|
46
|
+
|
35
47
|
Finally, cache the token (this will create the token cache file)
|
36
48
|
|
37
49
|
If you have an invalid API key you will see errors such as:
|
@@ -44,7 +56,7 @@
|
|
44
56
|
"98: Login failed / Invalid auth token" or
|
45
57
|
"99: User not logged in / Insufficient permissions"
|
46
58
|
|
47
|
-
== Authorization Example
|
59
|
+
== Authorization Example for non-webapplication
|
48
60
|
|
49
61
|
require 'flickr_fu'
|
50
62
|
|
@@ -59,6 +71,28 @@
|
|
59
71
|
|
60
72
|
flickr.auth.cache_token
|
61
73
|
|
74
|
+
== Authorization Example for a webapplication
|
75
|
+
|
76
|
+
flickr.auth.token also contains the nsid and username, this
|
77
|
+
example only stores the token and no other userdata.
|
78
|
+
|
79
|
+
require 'flickr_fu'
|
80
|
+
class FlickrController < ActionController::Base
|
81
|
+
def create
|
82
|
+
flickr = Flickr.new('flickr.yml')
|
83
|
+
redirect_to flickr.auth.url(:write)
|
84
|
+
end
|
85
|
+
def flickr_callback
|
86
|
+
flickr = Flickr.new('flickr.yml')
|
87
|
+
flickr.auth.frob = params[:frob]
|
88
|
+
current_user.update_attribute :flickr_token, flickr.auth.token.token
|
89
|
+
end
|
90
|
+
def something_else_with_flickr
|
91
|
+
flickr = Flickr.new(YAML.load_file('flickr.yml').merge(:token => current_user.flickr_token))
|
92
|
+
# now you have full access on the user's data :)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
62
96
|
== Search Example
|
63
97
|
|
64
98
|
require 'flickr_fu'
|
@@ -108,3 +142,5 @@
|
|
108
142
|
Mike Perham
|
109
143
|
Chris Anderton
|
110
144
|
Luke Francl
|
145
|
+
Thomas R. Koll
|
146
|
+
P. Mark Anderson
|
data/Rakefile
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
2
|
require 'rake/rdoctask'
|
4
3
|
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'Test the contact_info plugin.'
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
14
|
-
|
15
4
|
desc 'Generate documentation for the contact_info plugin.'
|
16
5
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
17
6
|
rdoc.rdoc_dir = 'rdoc'
|
@@ -20,3 +9,33 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
20
9
|
rdoc.rdoc_files.include('README')
|
21
10
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
11
|
end
|
12
|
+
|
13
|
+
# RSpec support
|
14
|
+
begin
|
15
|
+
require 'spec'
|
16
|
+
rescue LoadError
|
17
|
+
require 'rubygems'
|
18
|
+
require 'spec'
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
rescue LoadError
|
23
|
+
puts <<-EOS
|
24
|
+
To use rspec for testing you must install rspec gem:
|
25
|
+
gem install rspec
|
26
|
+
EOS
|
27
|
+
exit(0)
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
desc "Run the specs under spec/models"
|
33
|
+
Spec::Rake::SpecTask.new do |t|
|
34
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
35
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Run rcov"
|
39
|
+
task :rcov do
|
40
|
+
system "rcov spec/**/*.rb -x /var/lib -x spec/"
|
41
|
+
end
|
data/flickr_fu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "flickr_fu"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "2008-
|
3
|
+
s.version = "0.2.0"
|
4
|
+
s.date = "2008-12-30"
|
5
5
|
s.summary = "Provides a ruby interface to flickr via the REST api"
|
6
6
|
s.email = "ben@commonthread.com"
|
7
7
|
s.homepage = "http://github.com/commonthread/flickr_fu"
|
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
"lib/flickr/auth.rb",
|
16
16
|
"lib/flickr/base.rb",
|
17
17
|
"lib/flickr/comment.rb",
|
18
|
+
"lib/flickr/errors.rb",
|
18
19
|
"lib/flickr/license.rb",
|
19
20
|
"lib/flickr/note.rb",
|
20
21
|
"lib/flickr/people.rb",
|
data/lib/flickr/auth.rb
CHANGED
@@ -7,6 +7,11 @@ class Flickr::Auth < Flickr::Base
|
|
7
7
|
def frob
|
8
8
|
@frob ||= get_frob
|
9
9
|
end
|
10
|
+
|
11
|
+
# set the frob
|
12
|
+
def frob= frob
|
13
|
+
@frob=frob
|
14
|
+
end
|
10
15
|
|
11
16
|
# generates the authorization url to allow access to a flickr account.
|
12
17
|
#
|
@@ -58,7 +63,9 @@ class Flickr::Auth < Flickr::Base
|
|
58
63
|
end
|
59
64
|
|
60
65
|
def get_token(pass_through)
|
61
|
-
if @flickr.
|
66
|
+
if @flickr.token
|
67
|
+
@flickr.token
|
68
|
+
elsif @flickr.token_cache and File.exists?(@flickr.token_cache)
|
62
69
|
YAML.load_file(@flickr.token_cache)
|
63
70
|
elsif pass_through
|
64
71
|
rsp = @flickr.send_request('flickr.auth.getToken', {:frob => self.frob})
|
data/lib/flickr/base.rb
CHANGED
@@ -4,7 +4,7 @@ module Flickr
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class Base
|
7
|
-
attr_reader :api_key, :api_secret, :token_cache
|
7
|
+
attr_reader :api_key, :api_secret, :token_cache, :token
|
8
8
|
|
9
9
|
REST_ENDPOINT = 'http://api.flickr.com/services/rest/'
|
10
10
|
AUTH_ENDPOINT = 'http://flickr.com/services/auth/'
|
@@ -12,30 +12,44 @@ module Flickr
|
|
12
12
|
|
13
13
|
# create a new flickr object
|
14
14
|
#
|
15
|
-
#
|
15
|
+
# You can either pass a hash with the following attributes:
|
16
|
+
#
|
17
|
+
# * :key (Required)
|
18
|
+
# the API key
|
19
|
+
# * :secret (Required)
|
20
|
+
# the API secret
|
21
|
+
# * :token (Optional)
|
22
|
+
# Flickr::Auth::Token object
|
23
|
+
#
|
24
|
+
# or:
|
16
25
|
# * config_file (Required)
|
17
26
|
# yaml file to load configuration from
|
18
27
|
# * token_cache (Optional)
|
19
28
|
# location of the token cache file. This will override the setting in the config file
|
20
29
|
#
|
21
30
|
# Config Example (yaml file)
|
22
|
-
#
|
23
31
|
# ---
|
24
32
|
# key: YOUR_API_KEY
|
25
33
|
# secret: YOUR_API_SECRET
|
26
34
|
# token_cache: token.yml
|
27
35
|
#
|
28
|
-
def initialize(
|
29
|
-
|
36
|
+
def initialize(config_hash_or_file, token_cache = nil)
|
37
|
+
if config_hash_or_file.is_a? Hash
|
38
|
+
@api_key = config_hash_or_file[:key]
|
39
|
+
@api_secret = config_hash_or_file[:secret]
|
40
|
+
@token = config_hash_or_file[:token]
|
41
|
+
raise 'config_hash must contain api key and secret' unless @api_key and @api_secret
|
42
|
+
else
|
43
|
+
config = YAML.load_file(config_hash_or_file)
|
30
44
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
45
|
+
@api_key = config['key']
|
46
|
+
@api_secret = config['secret']
|
47
|
+
@token_cache = token_cache || config['token_cache']
|
48
|
+
raise 'flickr config file must contain an api key and secret' unless @api_key and @api_secret
|
49
|
+
end
|
36
50
|
end
|
37
51
|
|
38
|
-
# sends a request to the
|
52
|
+
# sends a request to the flickr REST api
|
39
53
|
#
|
40
54
|
# Params
|
41
55
|
# * method (Required)
|
@@ -53,12 +67,7 @@ module Flickr
|
|
53
67
|
options.merge!(:api_key => @api_key, :method => method)
|
54
68
|
sign_request(options)
|
55
69
|
|
56
|
-
|
57
|
-
api_call = endpoint + "?" + options.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
|
58
|
-
rsp = Net::HTTP.get(URI.parse(api_call))
|
59
|
-
else
|
60
|
-
rsp = Net::HTTP.post_form(URI.parse(endpoint), options).body
|
61
|
-
end
|
70
|
+
rsp = request_over_http(options, http_method, endpoint)
|
62
71
|
|
63
72
|
rsp = '<rsp stat="ok"></rsp>' if rsp == ""
|
64
73
|
xm = XmlMagic.new(rsp)
|
@@ -66,7 +75,7 @@ module Flickr
|
|
66
75
|
if xm[:stat] == 'ok'
|
67
76
|
xm
|
68
77
|
else
|
69
|
-
raise
|
78
|
+
raise Flickr::Errors.error_for(xm.err[:code], xm.err[:msg])
|
70
79
|
end
|
71
80
|
end
|
72
81
|
|
@@ -98,5 +107,18 @@ module Flickr
|
|
98
107
|
|
99
108
|
# creates and/or returns the Flickr::Uploader object
|
100
109
|
def uploader() @uploader ||= Flickr::Uploader.new(self) end
|
110
|
+
|
111
|
+
protected
|
112
|
+
|
113
|
+
# For easier testing. You can mock this method with a XML file you're expecting to receive
|
114
|
+
def request_over_http(options, http_method, endpoint)
|
115
|
+
if http_method == :get
|
116
|
+
api_call = endpoint + "?" + options.collect{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
|
117
|
+
Net::HTTP.get(URI.parse(api_call))
|
118
|
+
else
|
119
|
+
Net::HTTP.post_form(URI.parse(endpoint), options).body
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
101
123
|
end
|
102
124
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Flickr
|
2
|
+
class Error < RuntimeError
|
3
|
+
attr_accessor :code
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
class Errors
|
8
|
+
|
9
|
+
# Method used for raising the appropriate error class for a given error code.
|
10
|
+
# Currently raises only Flickr::Error
|
11
|
+
def self.error_for(code, message)
|
12
|
+
raise RuntimeError.new("Internal error. Flickr API error not identified or unknown error.") if (code.nil? || message.nil? || message.empty?)
|
13
|
+
raise RuntimeError.new("Internal error. Unknown error.") if code.to_i == 0 # We assume that error code 0 is never returned
|
14
|
+
e = Flickr::Error.new("#{code}: #{message}")
|
15
|
+
e.code = code
|
16
|
+
raise e
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/flickr/license.rb
CHANGED
@@ -11,4 +11,14 @@ class Flickr::Photos::License
|
|
11
11
|
send("#{k}=", v)
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
def == o
|
16
|
+
return false unless o.respond_to?(:id) && o.respond_to?(:name) && o.respond_to?(:url)
|
17
|
+
return true if id == o.id && name == o.name && url == o.url
|
18
|
+
false
|
19
|
+
end
|
20
|
+
|
21
|
+
def eql? o
|
22
|
+
return self == o
|
23
|
+
end
|
14
24
|
end
|
data/lib/flickr/photo.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# wrapping class to hold an flickr photo
|
2
|
-
#
|
3
2
|
class Flickr::Photos::Photo
|
4
3
|
attr_accessor :id, :owner, :secret, :server, :farm, :title, :is_public, :is_friend, :is_family # standard attributes
|
5
4
|
attr_accessor :license_id, :uploaded_at, :taken_at, :owner_name, :icon_server, :original_format, :updated_at, :geo, :tags, :machine_tags, :o_dims, :views, :media # extra attributes
|
6
5
|
attr_accessor :info_added, :description, :original_secret, :owner_username, :owner_realname, :url_photopage, :notes # info attributes
|
7
|
-
attr_accessor :
|
8
|
-
attr_accessor :comments_added, :comments # comment attributes
|
6
|
+
attr_accessor :comments # comment attributes
|
9
7
|
|
10
8
|
# create a new instance of a flickr photo.
|
11
9
|
#
|
@@ -21,8 +19,13 @@ class Flickr::Photos::Photo
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
22
|
+
# Alias to image_url method
|
23
|
+
def url(size = :medium)
|
24
|
+
image_url(size)
|
25
|
+
end
|
26
|
+
|
24
27
|
# retreive the url to the image stored on flickr
|
25
|
-
#
|
28
|
+
#
|
26
29
|
# == Params
|
27
30
|
# * size (Optional)
|
28
31
|
# the size of the image to return. Optional sizes are:
|
@@ -32,10 +35,24 @@ class Flickr::Photos::Photo
|
|
32
35
|
# :medium - 500 on longest side
|
33
36
|
# :large - 1024 on longest side (only exists for very large original images)
|
34
37
|
# :original - original image, either a jpg, gif or png, depending on source format
|
35
|
-
#
|
36
|
-
def
|
37
|
-
|
38
|
-
|
38
|
+
#
|
39
|
+
def image_url(size = :medium)
|
40
|
+
# It turns out that flickr always stores all the sizes of the picture even when getSizes call returns otherwise.
|
41
|
+
# Not calling getSizes is also very important for performance reasons.
|
42
|
+
# Retrieving 30 search results means calling the API 31 times if you call getSizes every time.
|
43
|
+
# Mind that you still need to call getSizes if you go out for the original image.
|
44
|
+
if size == :original
|
45
|
+
size_hash[size.to_s].source if size_hash.has_key? size.to_s
|
46
|
+
else
|
47
|
+
key = "_#{size_key(size.to_sym)}"
|
48
|
+
key = "" if key == "_"
|
49
|
+
"http://farm#{farm}.static.flickr.com/#{server}/#{id}_#{secret}#{key}.jpg"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def photopage_url
|
54
|
+
# Keeping the same convention as image_url (foo_url)
|
55
|
+
url_photopage
|
39
56
|
end
|
40
57
|
|
41
58
|
# save the current photo to the local computer
|
@@ -73,7 +90,7 @@ class Flickr::Photos::Photo
|
|
73
90
|
# comma seperated list of tags
|
74
91
|
#
|
75
92
|
def add_tags(tags)
|
76
|
-
|
93
|
+
@flickr.send_request('flickr.photos.addTags', {:photo_id => self.id, :tags => tags}, :post)
|
77
94
|
true
|
78
95
|
end
|
79
96
|
|
@@ -84,7 +101,7 @@ class Flickr::Photos::Photo
|
|
84
101
|
# text of the comment
|
85
102
|
#
|
86
103
|
def add_comment(message)
|
87
|
-
|
104
|
+
@flickr.send_request('flickr.photos.comments.addComment', {:photo_id => self.id, :comment_text => message}, :post)
|
88
105
|
true
|
89
106
|
end
|
90
107
|
|
@@ -103,7 +120,7 @@ class Flickr::Photos::Photo
|
|
103
120
|
# The height of the note
|
104
121
|
#
|
105
122
|
def add_note(message, x, y, w, h)
|
106
|
-
|
123
|
+
@flickr.send_request('flickr.photos.notes.add', {:photo_id => self.id, :note_x => x, :note_y => y, :note_w => w, :note_h => h, :note_text => message}, :post)
|
107
124
|
true
|
108
125
|
end
|
109
126
|
|
@@ -114,7 +131,7 @@ class Flickr::Photos::Photo
|
|
114
131
|
# The amount of degrees by which to rotate the photo (clockwise) from it's current orientation. Valid values are 90, 180 and 270.
|
115
132
|
#
|
116
133
|
def rotate(degrees)
|
117
|
-
|
134
|
+
@flickr.send_request('flickr.photos.transform.rotate', {:photo_id => self.id, :degrees => degrees}, :post)
|
118
135
|
true
|
119
136
|
end
|
120
137
|
|
@@ -130,7 +147,7 @@ class Flickr::Photos::Photo
|
|
130
147
|
# * license_id (Required)
|
131
148
|
# The license to apply, or 0 (zero) to remove the current license.
|
132
149
|
def set_license(license_id)
|
133
|
-
|
150
|
+
@flickr.send_request('flickr.photos.licenses.setLicense', {:photo_id => self.id, :license_id => license_id}, :post)
|
134
151
|
true
|
135
152
|
end
|
136
153
|
|
@@ -160,13 +177,39 @@ class Flickr::Photos::Photo
|
|
160
177
|
end
|
161
178
|
|
162
179
|
def comments # :nodoc:
|
163
|
-
|
164
|
-
|
180
|
+
@comments ||= begin
|
181
|
+
if @comment_count == 0
|
182
|
+
self.comments = []
|
183
|
+
self.comments_added = true
|
184
|
+
elsif not self.comments_added
|
185
|
+
rsp = @flickr.send_request('flickr.photos.comments.getList', :photo_id => self.id)
|
186
|
+
|
187
|
+
self.comments = []
|
188
|
+
self.comments_added = true
|
189
|
+
|
190
|
+
rsp.comments.comment.each do |comment|
|
191
|
+
self.comments << Flickr::Photos::Comment.new(:id => comment[:id],
|
192
|
+
:comment => comment.to_s,
|
193
|
+
:author => comment[:author],
|
194
|
+
:author_name => comment[:authorname],
|
195
|
+
:permalink => comment[:permalink],
|
196
|
+
:created_at => (Time.at(comment[:datecreate].to_i) rescue nil))
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
165
200
|
end
|
166
201
|
|
167
202
|
def sizes # :nodoc:
|
168
|
-
|
169
|
-
|
203
|
+
@sizes ||= begin
|
204
|
+
rsp = @flickr.send_request('flickr.photos.getSizes', :photo_id => self.id)
|
205
|
+
|
206
|
+
_sizes = []
|
207
|
+
rsp.sizes.size.each do |size|
|
208
|
+
_sizes << Flickr::Photos::Size.new(:label => size[:label], :width => size[:width],
|
209
|
+
:height => size[:height], :source => size[:source], :url => size[:url])
|
210
|
+
end
|
211
|
+
_sizes
|
212
|
+
end
|
170
213
|
end
|
171
214
|
|
172
215
|
def notes # :nodoc:
|
@@ -175,34 +218,14 @@ class Flickr::Photos::Photo
|
|
175
218
|
end
|
176
219
|
|
177
220
|
protected
|
178
|
-
def
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
|
-
def url_small # :nodoc:
|
189
|
-
attach_sizes
|
190
|
-
@url_small
|
191
|
-
end
|
192
|
-
|
193
|
-
def url_medium # :nodoc:
|
194
|
-
attach_sizes
|
195
|
-
@url_medium
|
196
|
-
end
|
197
|
-
|
198
|
-
def url_large # :nodoc:
|
199
|
-
attach_sizes
|
200
|
-
@url_large
|
201
|
-
end
|
202
|
-
|
203
|
-
def url_original # :nodoc:
|
204
|
-
attach_sizes
|
205
|
-
@url_original
|
221
|
+
def size_hash
|
222
|
+
@size_hash ||= begin
|
223
|
+
hash = {}
|
224
|
+
sizes.each do |size|
|
225
|
+
hash[size.label.downcase] = size
|
226
|
+
end
|
227
|
+
hash
|
228
|
+
end
|
206
229
|
end
|
207
230
|
|
208
231
|
private
|
@@ -211,12 +234,12 @@ class Flickr::Photos::Photo
|
|
211
234
|
# convert the size to the key used in the flickr url
|
212
235
|
def size_key(size)
|
213
236
|
case size.to_sym
|
214
|
-
when :square
|
215
|
-
when :thumb, :thumbnail
|
216
|
-
when :small
|
217
|
-
when :medium
|
218
|
-
when :large
|
219
|
-
when :original
|
237
|
+
when :square then 's'
|
238
|
+
when :thumb, :thumbnail then 't'
|
239
|
+
when :small then 'm'
|
240
|
+
when :medium then ''
|
241
|
+
when :large then 'b'
|
242
|
+
when :original then 'o'
|
220
243
|
else ''
|
221
244
|
end
|
222
245
|
end
|
@@ -227,7 +250,7 @@ class Flickr::Photos::Photo
|
|
227
250
|
rsp = @flickr.send_request('flickr.photos.getInfo', :photo_id => self.id, :secret => self.secret)
|
228
251
|
|
229
252
|
self.info_added = true
|
230
|
-
self.description = rsp.photo.description.to_s
|
253
|
+
self.description = rsp.photo.description.to_s.strip
|
231
254
|
self.original_secret = rsp.photo[:originalsecret]
|
232
255
|
self.owner_username = rsp.photo.owner[:username]
|
233
256
|
self.owner_realname = rsp.photo.owner[:realname]
|
@@ -238,61 +261,14 @@ class Flickr::Photos::Photo
|
|
238
261
|
|
239
262
|
rsp.photo.notes.note.each do |note|
|
240
263
|
self.notes << Flickr::Photos::Note.new(:id => note[:id],
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
264
|
+
:note => note.to_s,
|
265
|
+
:author => note[:author],
|
266
|
+
:author_name => note[:authorname],
|
267
|
+
:x => note[:x],
|
268
|
+
:y => note[:y],
|
269
|
+
:width => note[:w],
|
270
|
+
:height => note[:h])
|
248
271
|
end if rsp.photo.notes.note
|
249
272
|
end
|
250
273
|
end
|
251
|
-
|
252
|
-
# loads picture sizes only after one has been requested
|
253
|
-
def attach_sizes
|
254
|
-
unless self.sizes_added
|
255
|
-
rsp = @flickr.send_request('flickr.photos.getSizes', :photo_id => self.id)
|
256
|
-
|
257
|
-
self.sizes_added = true
|
258
|
-
self.sizes = []
|
259
|
-
|
260
|
-
# TODO: investigate the new video features and integrate better
|
261
|
-
rsp.sizes.size.each do |size|
|
262
|
-
method = "url_#{size[:label].downcase}="
|
263
|
-
next unless respond_to? method
|
264
|
-
send(method, size[:source])
|
265
|
-
|
266
|
-
# send("url_#{size[:label].downcase}=", size[:source])
|
267
|
-
|
268
|
-
self.sizes << Flickr::Photos::Size.new(:label => size[:label],
|
269
|
-
:width => size[:width],
|
270
|
-
:height => size[:height],
|
271
|
-
:source => size[:source],
|
272
|
-
:url => size[:url])
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
# loads comments once they have been requested
|
278
|
-
def attach_comments
|
279
|
-
if @comment_count == 0
|
280
|
-
self.comments = []
|
281
|
-
self.comments_added = true
|
282
|
-
elsif not self.comments_added
|
283
|
-
rsp = @flickr.send_request('flickr.photos.comments.getList', :photo_id => self.id)
|
284
|
-
|
285
|
-
self.comments = []
|
286
|
-
self.comments_added = true
|
287
|
-
|
288
|
-
rsp.comments.comment.each do |comment|
|
289
|
-
self.comments << Flickr::Photos::Comment.new(:id => comment[:id],
|
290
|
-
:comment => comment.to_s,
|
291
|
-
:author => comment[:author],
|
292
|
-
:author_name => comment[:authorname],
|
293
|
-
:permalink => comment[:permalink],
|
294
|
-
:created_at => (Time.at(comment[:datecreate].to_i) rescue nil))
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
274
|
end
|
data/lib/flickr/photos.rb
CHANGED
@@ -187,7 +187,25 @@ class Flickr::Photos < Flickr::Base
|
|
187
187
|
end
|
188
188
|
|
189
189
|
def licenses
|
190
|
-
@licenses ||=
|
190
|
+
@licenses ||= begin
|
191
|
+
rsp = @flickr.send_request('flickr.photos.licenses.getInfo')
|
192
|
+
|
193
|
+
returning Hash.new do |licenses|
|
194
|
+
rsp.licenses.license.each do |license|
|
195
|
+
licenses[license[:id].to_i] = Flickr::Photos::License.new(:id => license[:id].to_i, :name => license[:name], :url => license[:url])
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns a Flickr::Photos::Photo object of the given id.
|
202
|
+
# Raises an error if photo not found
|
203
|
+
def find_by_id(photo_id)
|
204
|
+
rsp = @flickr.send_request('flickr.photos.getInfo', :photo_id => photo_id)
|
205
|
+
Photo.new(@flickr, :id => rsp.photo[:id].to_i, :owner => rsp.photo.owner,
|
206
|
+
:secret => rsp.photo[:secret], :server => rsp.photo[:server].to_i, :farm => rsp.photo[:farm],
|
207
|
+
:title => rsp.photo.title,
|
208
|
+
:is_public => rsp.photo.visibility[:public], :is_friend => rsp.photo.visibility[:is_friend], :is_family => rsp.photo.visibility[:is_family])
|
191
209
|
end
|
192
210
|
|
193
211
|
protected
|
@@ -216,13 +234,4 @@ class Flickr::Photos < Flickr::Base
|
|
216
234
|
:media => photo[:media]}
|
217
235
|
end
|
218
236
|
|
219
|
-
def get_licenses
|
220
|
-
rsp = @flickr.send_request('flickr.photos.licenses.getInfo')
|
221
|
-
|
222
|
-
returning Hash.new do |licenses|
|
223
|
-
rsp.licenses.license.each do |license|
|
224
|
-
licenses[license[:id].to_i] = Flickr::Photos::License.new(:id => license[:id].to_i, :name => license[:name], :url => license[:url])
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
237
|
end
|
data/lib/flickr/token.rb
CHANGED
data/lib/flickr_fu.rb
CHANGED
@@ -10,7 +10,7 @@ require 'time'
|
|
10
10
|
require 'date'
|
11
11
|
|
12
12
|
# base must load first
|
13
|
-
%w(base test auth token photos photo photo_response comment note size uploader status people person license).each do |file|
|
13
|
+
%w(base test auth token photos photo photo_response comment note size uploader status people person license errors).each do |file|
|
14
14
|
require File.join(File.dirname(__FILE__), 'flickr', file)
|
15
15
|
end
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonthread-flickr_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Wyrosdick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-30 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/flickr/auth.rb
|
47
47
|
- lib/flickr/base.rb
|
48
48
|
- lib/flickr/comment.rb
|
49
|
+
- lib/flickr/errors.rb
|
49
50
|
- lib/flickr/license.rb
|
50
51
|
- lib/flickr/note.rb
|
51
52
|
- lib/flickr/people.rb
|