flickr-fu 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flickr/base.rb +4 -0
- data/lib/flickr/people.rb +54 -0
- data/lib/flickr/person.rb +74 -0
- data/lib/flickr/photo.rb +1 -1
- data/lib/flickr/photo_response.rb +2 -2
- data/lib/flickr/photos.rb +9 -6
- data/lib/flickr/status.rb +19 -0
- data/lib/flickr/uploader.rb +21 -0
- data/lib/flickr_fu.rb +3 -1
- metadata +5 -2
data/lib/flickr/base.rb
CHANGED
@@ -79,12 +79,16 @@ module Flickr
|
|
79
79
|
#
|
80
80
|
def sign_request(options, authorize = true)
|
81
81
|
options.merge!(:auth_token => self.auth.token(false).to_s) if authorize and self.auth.token(false)
|
82
|
+
options.delete(:api_sig)
|
82
83
|
options.merge!(:api_sig => Digest::MD5.hexdigest(@api_secret + options.keys.sort_by{|k| k.to_s}.collect{|k| k.to_s + options[k].to_s}.join)) if @api_secret
|
83
84
|
end
|
84
85
|
|
85
86
|
# creates and/or returns the Flickr::Photos object
|
86
87
|
def photos() @photos ||= Photos.new(self) end
|
87
88
|
|
89
|
+
# creates and/or returns the Flickr::People object
|
90
|
+
def people() @people ||= People.new(self) end
|
91
|
+
|
88
92
|
# creates and/or returns the Flickr::Auth object
|
89
93
|
def auth() @auth ||= Auth.new(self) end
|
90
94
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Flickr::People < Flickr::Base
|
2
|
+
def initialize(flickr)
|
3
|
+
@flickr = flickr
|
4
|
+
end
|
5
|
+
|
6
|
+
# Get information about a user.
|
7
|
+
#
|
8
|
+
# Params
|
9
|
+
# * id (Required)
|
10
|
+
# the nsid of the user to get information for
|
11
|
+
#
|
12
|
+
def find_by_id(id)
|
13
|
+
rsp = @flickr.send_request('flickr.people.getInfo', {:user_id => id})
|
14
|
+
|
15
|
+
Person.new(@flickr, :nsid => rsp.person[:nsid],
|
16
|
+
:is_admin => (rsp.person[:isadmin] == "1" ? true : false),
|
17
|
+
:is_pro => (rsp.person[:ispro] == "1" ? true : false),
|
18
|
+
:icon_server => rsp.person[:iconserver],
|
19
|
+
:icon_farm => rsp.person[:iconfarm],
|
20
|
+
:username => rsp.person.username.to_s,
|
21
|
+
:realname => rsp.person.realname.to_s,
|
22
|
+
:mbox_sha1sum => rsp.person.mbox_sha1sum.to_s,
|
23
|
+
:location => rsp.person.location.to_s,
|
24
|
+
:photos_url => rsp.person.photosurl.to_s,
|
25
|
+
:profile_url => rsp.person.profileurl.to_s,
|
26
|
+
:photo_count => rsp.person.photos.count.to_s.to_i,
|
27
|
+
:photo_first_upload => (Time.at(rsp.person.photos.firstdate.to_s.to_i) rescue nil),
|
28
|
+
:photo_first_taken => (Time.parse(rsp.person.photos.firstdatetaken.to_s) rescue nil))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get information about a user.
|
32
|
+
#
|
33
|
+
# Params
|
34
|
+
# * username (Required)
|
35
|
+
# the username of the user to get information for
|
36
|
+
#
|
37
|
+
def find_by_username(username)
|
38
|
+
rsp = @flickr.send_request('flickr.people.findByUsername', {:username => username})
|
39
|
+
|
40
|
+
find_by_id(rsp.user[:nsid])
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get information about a user.
|
44
|
+
#
|
45
|
+
# Params
|
46
|
+
# * email (Required)
|
47
|
+
# the email of the user to get information for
|
48
|
+
#
|
49
|
+
def find_by_email(email)
|
50
|
+
rsp = @flickr.send_request('flickr.people.findByEmail', {:find_email => email})
|
51
|
+
|
52
|
+
find_by_id(rsp.user[:nsid])
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# wrapping class to hold an flickr photo
|
2
|
+
#
|
3
|
+
class Flickr::People::Person
|
4
|
+
attr_accessor :username, :nsid, :is_admin, :is_pro, :icon_server, :icon_farm, :realname, :mbox_sha1sum, :location, :photos_url, :profile_url, :photo_count, :photo_first_upload, :photo_first_taken
|
5
|
+
|
6
|
+
# create a new instance of a flickr person.
|
7
|
+
#
|
8
|
+
# Params
|
9
|
+
# * flickr (Required)
|
10
|
+
# the flickr object
|
11
|
+
# * attributes (Required)
|
12
|
+
# a hash of attributes used to set the initial values of the person object
|
13
|
+
def initialize(flickr, attributes)
|
14
|
+
@flickr = flickr
|
15
|
+
attributes.each do |k,v|
|
16
|
+
send("#{k}=", v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get a list of public photos for the given user.
|
21
|
+
#
|
22
|
+
# Options
|
23
|
+
# * safe_search (Optional)
|
24
|
+
# Safe search setting:
|
25
|
+
# 1 for safe.
|
26
|
+
# 2 for moderate.
|
27
|
+
# 3 for restricted.
|
28
|
+
# (Please note: Un-authed calls can only see Safe content.)
|
29
|
+
# * per_page (Optional)
|
30
|
+
# Number of photos to return per page. If this argument is omitted, it defaults to 100. The maximum allowed value is 500.
|
31
|
+
# * page (Optional)
|
32
|
+
# The page of results to return. If this argument is omitted, it defaults to 1.
|
33
|
+
def public_photos(options = {})
|
34
|
+
options.merge!({:user_id => self.nsid, :extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
35
|
+
|
36
|
+
rsp = @flickr.send_request('flickr.people.getPublicPhotos', options)
|
37
|
+
|
38
|
+
returning Flickr::Photos::PhotoResponse.new(:page => rsp.photos[:page].to_i,
|
39
|
+
:pages => rsp.photos[:pages].to_i,
|
40
|
+
:per_page => rsp.photos[:perpage].to_i,
|
41
|
+
:total => rsp.photos[:total].to_i,
|
42
|
+
:photos => [],
|
43
|
+
:api => self,
|
44
|
+
:method => 'public_photos',
|
45
|
+
:options => options) do |photos|
|
46
|
+
rsp.photos.photo.each do |photo|
|
47
|
+
attributes = {:id => photo[:id],
|
48
|
+
:owner => photo[:owner],
|
49
|
+
:secret => photo[:secret],
|
50
|
+
:server => photo[:server],
|
51
|
+
:farm => photo[:farm],
|
52
|
+
:title => photo[:title],
|
53
|
+
:is_public => photo[:ispublic],
|
54
|
+
:is_friend => photo[:isfriend],
|
55
|
+
:is_family => photo[:isfamily],
|
56
|
+
:license => photo[:license],
|
57
|
+
:uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
|
58
|
+
:taken_at => (Time.parse(photo[:datetaken]) rescue nil),
|
59
|
+
:owner_name => photo[:ownername],
|
60
|
+
:icon_server => photo[:icon_server],
|
61
|
+
:original_format => photo[:originalformat],
|
62
|
+
:updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
|
63
|
+
:geo => photo[:geo],
|
64
|
+
:tags => photo[:tags],
|
65
|
+
:machine_tags => photo[:machine_tags],
|
66
|
+
:o_dims => photo[:o_dims],
|
67
|
+
:views => photo[:views].to_i,
|
68
|
+
:media => photo[:media]}
|
69
|
+
|
70
|
+
photos << Flickr::Photos::Photo.new(@flickr, attributes)
|
71
|
+
end if rsp.photos.photo
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/flickr/photo.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
class Flickr::Photos::Photo
|
4
4
|
attr_accessor :id, :owner, :secret, :server, :farm, :title, :is_public, :is_friend, :is_family # standard attributes
|
5
|
-
attr_accessor :license, :uploaded_at, :taken_at, :owner_name, :icon_server, :original_format, :updated_at, :geo, :tags, :machine_tags, :o_dims, :views # extra attributes
|
5
|
+
attr_accessor :license, :uploaded_at, :taken_at, :owner_name, :icon_server, :original_format, :updated_at, :geo, :tags, :machine_tags, :o_dims, :views, :media # extra attributes
|
6
6
|
attr_accessor :info_added, :description, :original_secret, :owner_username, :owner_realname, :url_photopage, :notes # info attributes
|
7
7
|
attr_accessor :sizes_added, :sizes, :url_square, :url_thumbnail, :url_small, :url_medium, :url_large, :url_original # size attributes
|
8
8
|
attr_accessor :comments_added, :comments # comment attributes
|
@@ -22,12 +22,12 @@ class Flickr::Photos::PhotoResponse
|
|
22
22
|
|
23
23
|
# gets the next page from flickr if there are anymore pages in the current photos object
|
24
24
|
def next_page
|
25
|
-
api.send(self.method
|
25
|
+
api.send(self.method, options.merge(:page => self.page.to_i + 1)) if self.page.to_i < self.pages.to_i
|
26
26
|
end
|
27
27
|
|
28
28
|
# gets the previous page from flickr if there is a previous page in the current photos object
|
29
29
|
def previous_page
|
30
|
-
api.send(self.method
|
30
|
+
api.send(self.method, options.merge(:page => self.page.to_i - 1)) if self.page.to_i > 1
|
31
31
|
end
|
32
32
|
|
33
33
|
# passes all unknown request to the photos array if it responds to the method
|
data/lib/flickr/photos.rb
CHANGED
@@ -113,7 +113,7 @@ class Flickr::Photos < Flickr::Base
|
|
113
113
|
# The page of results to return. If this argument is omitted, it defaults to 1.
|
114
114
|
#
|
115
115
|
def search(options)
|
116
|
-
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views"})
|
116
|
+
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
117
117
|
|
118
118
|
rsp = @flickr.send_request('flickr.photos.search', options)
|
119
119
|
|
@@ -121,8 +121,9 @@ class Flickr::Photos < Flickr::Base
|
|
121
121
|
:pages => rsp.photos[:pages].to_i,
|
122
122
|
:per_page => rsp.photos[:perpage].to_i,
|
123
123
|
:total => rsp.photos[:total].to_i,
|
124
|
-
:photos => [],
|
125
|
-
:
|
124
|
+
:photos => [],
|
125
|
+
:api => self,
|
126
|
+
:method => 'search',
|
126
127
|
:options => options) do |photos|
|
127
128
|
rsp.photos.photo.each do |photo|
|
128
129
|
attributes = {:id => photo[:id],
|
@@ -145,7 +146,8 @@ class Flickr::Photos < Flickr::Base
|
|
145
146
|
:tags => photo[:tags],
|
146
147
|
:machine_tags => photo[:machine_tags],
|
147
148
|
:o_dims => photo[:o_dims],
|
148
|
-
:views => photo[:views].to_i
|
149
|
+
:views => photo[:views].to_i,
|
150
|
+
:media => photo[:media]}
|
149
151
|
|
150
152
|
photos << Photo.new(@flickr, attributes)
|
151
153
|
end if rsp.photos.photo
|
@@ -164,7 +166,7 @@ class Flickr::Photos < Flickr::Base
|
|
164
166
|
# The page of results to return. If this argument is omitted, it defaults to 1.
|
165
167
|
#
|
166
168
|
def get_recent(options)
|
167
|
-
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views"})
|
169
|
+
options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
|
168
170
|
|
169
171
|
rsp = @flickr.send_request('flickr.photos.getRecent', options)
|
170
172
|
|
@@ -196,7 +198,8 @@ class Flickr::Photos < Flickr::Base
|
|
196
198
|
:tags => photo[:tags],
|
197
199
|
:machine_tags => photo[:machine_tags],
|
198
200
|
:o_dims => photo[:o_dims],
|
199
|
-
:views => photo[:views].to_i
|
201
|
+
:views => photo[:views].to_i,
|
202
|
+
:media => photo[:media]}
|
200
203
|
|
201
204
|
photos << Photo.new(@flickr, attributes)
|
202
205
|
end if rsp.photos.photo
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# wrapper class to hold a flickr upload status object.
|
2
|
+
#
|
3
|
+
class Flickr::Uploader::Status
|
4
|
+
attr_accessor :nsid, :is_pro, :username, :max_bandwidth, :used_bandwidth, :remaining_bandwidth, :max_filesize, :max_videosize, :sets_created, :sets_remaining
|
5
|
+
|
6
|
+
# create a new instance of a flickr upload status object.
|
7
|
+
#
|
8
|
+
# Params
|
9
|
+
# * flickr (Required)
|
10
|
+
# the flickr object
|
11
|
+
# * attributes (Required)
|
12
|
+
# a hash of attributes used to set the initial values of the status object
|
13
|
+
def initialize(flickr, attributes)
|
14
|
+
@flickr = flickr
|
15
|
+
attributes.each do |k,v|
|
16
|
+
send("#{k}=", v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/flickr/uploader.rb
CHANGED
@@ -67,6 +67,27 @@ class Flickr::Uploader < Flickr::Base
|
|
67
67
|
raise "#{xm.err[:code]}: #{xm.err[:msg]}"
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
# Returns information for the calling user related to photo uploads.
|
72
|
+
#
|
73
|
+
# * Bandwidth and filesize numbers are provided in bytes.
|
74
|
+
# * Bandwidth is specified in bytes per month.
|
75
|
+
# * Pro accounts display 99 for the number of remaining sets, since they have unlimited sets. Free accounts will display either 3, 2, 1, or 0.
|
76
|
+
#
|
77
|
+
def status
|
78
|
+
rsp = @flickr.send_request('flickr.people.getUploadStatus')
|
79
|
+
|
80
|
+
Flickr::Uploader::Status.new(@flickr, :nsid => rsp.user[:id],
|
81
|
+
:is_pro => (rsp.user[:ispro] == "1" ? true : false),
|
82
|
+
:username => rsp.user.username.to_s,
|
83
|
+
:max_bandwidth => rsp.user.bandwidth[:maxbytes],
|
84
|
+
:used_bandwidth => rsp.user.bandwidth[:usedbytes],
|
85
|
+
:remaining_bandwidth => rsp.user.bandwidth[:remainingbytes],
|
86
|
+
:max_filesize => rsp.user.filesize[:maxbytes],
|
87
|
+
:max_videosize => rsp.user.videosize[:maxbytes],
|
88
|
+
:sets_created => rsp.user.sets[:created].to_i,
|
89
|
+
:sets_remaining => (rsp.user[:ispro] == "1" ? 99 : rsp.user.sets[:remaining].to_i))
|
90
|
+
end
|
70
91
|
end
|
71
92
|
|
72
93
|
class Flickr::Uploader::FormPart
|
data/lib/flickr_fu.rb
CHANGED
@@ -6,9 +6,11 @@ require 'uri'
|
|
6
6
|
require 'mime/types'
|
7
7
|
require 'digest/md5'
|
8
8
|
require 'yaml'
|
9
|
+
require 'time'
|
10
|
+
require 'date'
|
9
11
|
|
10
12
|
# base must load first
|
11
|
-
%w(base auth token photos photo photo_response comment note size uploader).each do |file|
|
13
|
+
%w(base auth token photos photo photo_response comment note size uploader status people person).each do |file|
|
12
14
|
require File.join(File.dirname(__FILE__), 'flickr', file)
|
13
15
|
end
|
14
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickr-fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-04-
|
12
|
+
date: 2008-04-10 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -35,10 +35,13 @@ files:
|
|
35
35
|
- lib/flickr/base.rb
|
36
36
|
- lib/flickr/comment.rb
|
37
37
|
- lib/flickr/note.rb
|
38
|
+
- lib/flickr/people.rb
|
39
|
+
- lib/flickr/person.rb
|
38
40
|
- lib/flickr/photo.rb
|
39
41
|
- lib/flickr/photo_response.rb
|
40
42
|
- lib/flickr/photos.rb
|
41
43
|
- lib/flickr/size.rb
|
44
|
+
- lib/flickr/status.rb
|
42
45
|
- lib/flickr/token.rb
|
43
46
|
- lib/flickr/uploader.rb
|
44
47
|
- lib/flickr_fu.rb
|