flickr 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +185 -0
- data/examples/auth.rb +22 -0
- data/examples/interestingness.rb +7 -0
- data/examples/search.rb +20 -0
- data/examples/sinatra.rb +31 -0
- data/examples/upload.rb +16 -0
- data/examples/web_oauth.rb +47 -0
- data/flickr_rdoc.rb +128 -0
- data/lib/flickr.rb +281 -0
- data/lib/flickr/errors.rb +15 -0
- data/lib/flickr/oauth_client.rb +175 -0
- data/lib/flickr/request.rb +7 -0
- data/lib/flickr/response.rb +38 -0
- data/lib/flickr/response_list.rb +29 -0
- data/lib/flickr/util.rb +13 -0
- data/lib/flickr/version.rb +3 -0
- data/rakefile +22 -0
- data/test/test.rb +471 -0
- data/test/test_cache.rb +45 -0
- data/test/test_request.rb +36 -0
- data/test/test_response.rb +30 -0
- data/test/test_upload.rb +41 -0
- metadata +103 -53
- data/Rakefile +0 -36
- data/flickr.rb +0 -501
- data/index.html +0 -129
- data/test_flickr.rb +0 -173
data/index.html
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
-
|
3
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
-
<head>
|
5
|
-
<title>Flickr.rb</title>
|
6
|
-
<style>
|
7
|
-
body {
|
8
|
-
font-family: arial;
|
9
|
-
color: #222;
|
10
|
-
margin: 0;
|
11
|
-
padding: 1.5em;
|
12
|
-
font-size: 0.9em;
|
13
|
-
}
|
14
|
-
h1 {
|
15
|
-
margin: 0;
|
16
|
-
}
|
17
|
-
h1+p {
|
18
|
-
margin-top: 0;
|
19
|
-
}
|
20
|
-
div {
|
21
|
-
border-top: 1px solid #ccc;
|
22
|
-
}
|
23
|
-
h2 {
|
24
|
-
float: left;
|
25
|
-
text-transform: uppercase;
|
26
|
-
font-size: .8em;
|
27
|
-
color: #555;
|
28
|
-
margin-top: .8em;
|
29
|
-
}
|
30
|
-
div p {
|
31
|
-
margin-top: .8em;
|
32
|
-
margin-left: 9em;
|
33
|
-
}
|
34
|
-
div pre {
|
35
|
-
margin-left: 11em;
|
36
|
-
}
|
37
|
-
code {
|
38
|
-
background-color: #ddd;
|
39
|
-
padding: 0em;
|
40
|
-
}
|
41
|
-
code span {
|
42
|
-
color: #707;
|
43
|
-
}
|
44
|
-
</style>
|
45
|
-
</head>
|
46
|
-
<body>
|
47
|
-
<h1>Flickr.rb</h1>
|
48
|
-
<p><em>An insanely easy Ruby interface to the <a href="http://flickr.com/services/api/">Flickr</a> photo-sharing service. By Scott Raymond <<a href="mailto:sco@scottraymond.net">sco@redgreenblu.com</a>></em></p>
|
49
|
-
|
50
|
-
<div>
|
51
|
-
<h2>Get it</h2>
|
52
|
-
<p>via RubyGems: <code>gem install flickr</code><br/>
|
53
|
-
...or download the gem: <a href="pkg/flickr-1.0.0.gem">flickr-1.0.0.gem</a><br/>
|
54
|
-
...or just get the source by itself: <a href="flickr.rb">flickr.rb</a></p>
|
55
|
-
<p>You'll also need a <a href="http://www.flickr.com/services/api/misc.api_keys.html">Flickr API key</a>.</p>
|
56
|
-
</div>
|
57
|
-
|
58
|
-
<div>
|
59
|
-
<h2>Example</h2>
|
60
|
-
<p><pre><code>require 'flickr'
|
61
|
-
|
62
|
-
<span># basics</span>
|
63
|
-
flickr = Flickr.new <span># create a flickr client</span>
|
64
|
-
flickr.login(email, password) <span># log in for actions that require it</span>
|
65
|
-
flickr.users <span># get all users currently online</span>
|
66
|
-
flickr.photos <span># get the 100 most recent public photos</span>
|
67
|
-
flickr.tag('red') <span># search for photos tagged with 'red'</span>
|
68
|
-
flickr.groups <span># get all active public groups</span>
|
69
|
-
|
70
|
-
<span># working with users</span>
|
71
|
-
user = flickr.users('sco') <span># lookup a user by username</span>
|
72
|
-
user = flickr.users('sco@scottraymond.net') <span># or email</span>
|
73
|
-
user.name <span># get the user's real name</span>
|
74
|
-
user.location <span># and location</span>
|
75
|
-
user.photos <span># grab their collection of Photo objects...</span>
|
76
|
-
user.tag('red') <span># search their photos for the tag 'red'</span>
|
77
|
-
user.groups <span># ...the groups they're in...</span>
|
78
|
-
user.contacts <span># ...their contacts...</span>
|
79
|
-
user.favorites <span># ...favorite photos...</span>
|
80
|
-
user.photosets <span># ...their photo sets...</span>
|
81
|
-
user.tags <span># ...and their tags</span>
|
82
|
-
|
83
|
-
<span># working with photos</span>
|
84
|
-
photo = flickr.photos.first <span># get the most recent public photo</span>
|
85
|
-
photo.url <span># see the URL for the photo's page...</span>
|
86
|
-
photo.url('Original') <span># as well as for its various sizes</span>
|
87
|
-
photo.source <span># see the URL for the JPEG itself...</span>
|
88
|
-
photo.source('Small') <span># as well as for its various sizes</span>
|
89
|
-
photo.title <span># get its title,</span>
|
90
|
-
photo.description <span># description,</span>
|
91
|
-
photo.owner <span># owner,</span>
|
92
|
-
photo.owner.name <span># and its owner's name, etc.</span>
|
93
|
-
|
94
|
-
<span># downloading files</span>
|
95
|
-
File.open(photo.filename, 'w') do |file|
|
96
|
-
file.puts photo.file <span># save the photo to a local file</span>
|
97
|
-
end
|
98
|
-
flickr.photos.each do |photo| <span># get the last 100 public photos...</span>
|
99
|
-
File.open(photo.filename, 'w') do |file|
|
100
|
-
file.puts photo.file('Square') <span># ...and save a local copy of their square thumbnail</span>
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
<span># ...and so much more. see the docs for full details.</span>
|
105
|
-
|
106
|
-
</code></pre></p>
|
107
|
-
</div>
|
108
|
-
|
109
|
-
<div>
|
110
|
-
<h2>Documentation</h2>
|
111
|
-
<p><a href="doc/">Rdoc Documentation</a><br/><small>Also see: <a href="http://www.flickr.com/services/api/">Original Flickr API reference</a></small></p>
|
112
|
-
</div>
|
113
|
-
|
114
|
-
<div>
|
115
|
-
<h2>License</h2>
|
116
|
-
<p><a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>. Attribution and contribution encouraged.</p>
|
117
|
-
</div>
|
118
|
-
|
119
|
-
<div>
|
120
|
-
<h2>Thanks</h2>
|
121
|
-
<p>
|
122
|
-
<strong>Maik Schmidt</strong> for <a href="http://www.maik-schmidt.de/xml-simple.html">XmlSimple</a>,
|
123
|
-
<strong>Ludicorp</strong> for <a href="http://www.flickr.com/">Flickr</a>,
|
124
|
-
and <strong>Premshee Pillai</strong> for <a href="http://premshree.seacrow.com/code/ruby/flickr-ruby">Flickr-ruby</a>.
|
125
|
-
</p>
|
126
|
-
</div>
|
127
|
-
|
128
|
-
</body>
|
129
|
-
</html>
|
data/test_flickr.rb
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'flickr'
|
2
|
-
require 'test/unit'
|
3
|
-
#require 'stringio'
|
4
|
-
|
5
|
-
class MockFlickr < Flickr
|
6
|
-
#@@data = eval(DATA.read)
|
7
|
-
#def _get_response(url)
|
8
|
-
# raise "no data for #{url.inspect}" unless @@data.has_key? url
|
9
|
-
# return REXML::Document.new(@@data[url])
|
10
|
-
#end
|
11
|
-
end
|
12
|
-
|
13
|
-
class TestFlickr < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@api_key = '86e18ef2a064ff2255845e029208d7f4'
|
17
|
-
@email = 'sco@redgreenblu.com'
|
18
|
-
@password = 'flickr.rb'
|
19
|
-
@username = 'flickr.rb'
|
20
|
-
@user_id = '35034359890@N01'
|
21
|
-
@photo_id = '8649502'
|
22
|
-
@tag = 'onetag'
|
23
|
-
@tags = 'onetag twotag'
|
24
|
-
@tag_id = '27359619'
|
25
|
-
@date_posted = '2005-01-01 16:01:26'
|
26
|
-
@dates = '1093566950'
|
27
|
-
@group_id = '37718676860@N01'
|
28
|
-
@group_url = 'http://flickr.com/groups/kansascity/'
|
29
|
-
@user_url = 'http://flickr.com/photos/sco/'
|
30
|
-
@title = 'New Set'
|
31
|
-
@f = MockFlickr.new
|
32
|
-
@f.login(@email, @password)
|
33
|
-
@u = @f.users(@email)
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
##### DIRECT MODE
|
38
|
-
|
39
|
-
def test_test_echo
|
40
|
-
assert_equal @f.test_echo['stat'], 'ok'
|
41
|
-
end
|
42
|
-
def test_test_login
|
43
|
-
assert_equal @f.test_login['stat'], 'ok'
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
##### BASICS
|
48
|
-
|
49
|
-
def test_request
|
50
|
-
assert_equal @f.request('test.echo')['stat'], 'ok'
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_request_url
|
54
|
-
assert_equal "http://flickr.com/services/rest/?api_key=#{@api_key}&method=flickr.test.echo&foo=bar&email=#{@email}&password=#{@password}", @f.request_url('test.echo', ['foo'=>'bar'])
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_login
|
58
|
-
assert_equal @username, @f.user.getInfo.username
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_find_by_url
|
62
|
-
assert_equal @group_id, @f.find_by_url(@group_url).getInfo.id # find group by URL
|
63
|
-
assert_equal @user_id, @f.find_by_url(@user_url).getInfo.id # find user by URL
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_photos
|
67
|
-
assert_equal 100, @f.photos.size # find recent
|
68
|
-
assert_equal @user_id, @f.photos('user_id'=>@user_id).first.getInfo.owner.id # search by user_id
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_users
|
72
|
-
assert_equal @username, @f.users(@email).getInfo.username # find by email
|
73
|
-
assert_equal @username, @f.users(@username).getInfo.username # find by username
|
74
|
-
assert_kind_of Flickr::User, @f.users.first # find all online users
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_groups
|
78
|
-
assert_kind_of Flickr::Group, @f.groups.first # find all active groups
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_licenses
|
82
|
-
assert_kind_of Array, @f.licenses # find all licenses
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
##### USER
|
87
|
-
|
88
|
-
def test_getInfo
|
89
|
-
@u.getInfo
|
90
|
-
assert_equal @username, @u.username
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_groups
|
94
|
-
assert_kind_of Flickr::Group, @u.groups.first # public groups
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_photos
|
98
|
-
assert_kind_of Flickr::Photo, @u.photos.first # public photos
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_contacts
|
102
|
-
assert_kind_of Flickr::User, @u.contacts.first # public contacts
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_favorites
|
106
|
-
assert_kind_of Flickr::Photo, @u.favorites.first # public favorites
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_photosets
|
110
|
-
assert_kind_of Flickr::Photoset, @u.photosets.first # public photosets
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_tags
|
114
|
-
assert_kind_of Array, @u.tags # tags
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_contactsPhotos
|
118
|
-
assert_kind_of Flickr::Photo, @u.contactsPhotos.first # contacts' favorites
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
##### PHOTO
|
123
|
-
|
124
|
-
def test_getInfo
|
125
|
-
@p.getInfo
|
126
|
-
assert_equal @photo_id, @p.id
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
##### PHOTOSETS
|
131
|
-
|
132
|
-
#def setup
|
133
|
-
# super
|
134
|
-
# @photoset = @f.photosets_create('title'=>@title, 'primary_photo_id'=>@photo_id)
|
135
|
-
# @photoset_id = @photoset['photoset']['id']
|
136
|
-
#end
|
137
|
-
#def teardown
|
138
|
-
# @f.photosets_delete('photoset_id'=>@photoset_id)
|
139
|
-
#end
|
140
|
-
|
141
|
-
def test_photosets_editMeta
|
142
|
-
assert_equal @f.photosets_editMeta('photoset_id'=>@photoset_id, 'title'=>@title)['stat'], 'ok'
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_photosets_editPhotos
|
146
|
-
assert_equal @f.photosets_editPhotos('photoset_id'=>@photoset_id, 'primary_photo_id'=>@photo_id, 'photo_ids'=>@photo_id)['stat'], 'ok'
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_photosets_getContext
|
150
|
-
assert_equal @f.photosets_getContext('photoset_id'=>@photoset_id, 'photo_id'=>@photo_id)['stat'], 'ok'
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_photosets_getContext
|
154
|
-
assert_equal @f.photosets_getContext('photoset_id'=>@photoset_id, 'photo_id'=>@photo_id)['stat'], 'ok'
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_photosets_getInfo
|
158
|
-
assert_equal @f.photosets_getInfo('photoset_id'=>@photoset_id)['stat'], 'ok'
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_photosets_getList
|
162
|
-
assert_equal @f.photosets_getList['stat'], 'ok'
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_photosets_getPhotos
|
166
|
-
assert_equal @f.photosets_getPhotos('photoset_id'=>@photoset_id)['stat'], 'ok'
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_photosets_orderSets
|
170
|
-
assert_equal @f.photosets_orderSets('photoset_ids'=>@photoset_id)['stat'], 'ok'
|
171
|
-
end
|
172
|
-
|
173
|
-
end
|