flickrrb 2.0 → 2.1
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/README.rdoc +8 -3
- data/Rakefile +11 -0
- data/lib/flickrrb.rb +66 -8
- data/test/flickrrb_test.rb +1 -2
- data/test/groups_test.rb +1 -2
- data/test/people_test.rb +1 -2
- data/test/photos_test.rb +1 -2
- data/test/test_helper.rb +7 -7
- metadata +27 -5
data/README.rdoc
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
= Flickrrb
|
2
2
|
|
3
|
-
Flickrrb is a library to access flickr[http://flickr.com] api in a simple way.
|
4
|
-
It
|
3
|
+
Flickrrb is a nice library to access the flickr[http://flickr.com] api in a simple way.
|
4
|
+
It maps the methods described in {the official api documentation}[http://www.flickr.com/services/api] to ruby
|
5
|
+
methods, eg.
|
5
6
|
|
7
|
+
{flickr.people.findByUsername(:username => 'Henry Maddocks')}[http://www.flickr.com/services/api/flickr.people.findByUsername.html]
|
8
|
+
|
9
|
+
{flickr.photos.getInfo(:photo_id => photo)}[http://www.flickr.com/services/api/flickr.photos.getInfo.html]
|
10
|
+
|
11
|
+
You can copy from the documentation and paste into your ruby.
|
6
12
|
|
7
13
|
= Installation
|
8
14
|
gem install flickrrb
|
@@ -23,5 +29,4 @@ It tries to map the methods described in {the official api documentation}[http:/
|
|
23
29
|
end
|
24
30
|
|
25
31
|
== Todo
|
26
|
-
* Maybe use JSON instead of xml responses.
|
27
32
|
* OAuth.
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
require 'rake/rdoctask'
|
3
3
|
|
4
|
+
require 'flickrrb'
|
5
|
+
|
4
6
|
|
5
7
|
Rake::TestTask.new do |t|
|
6
8
|
t.pattern = 'test/*.rb'
|
@@ -11,3 +13,12 @@ RDoc::Task.new do |rd|
|
|
11
13
|
end
|
12
14
|
|
13
15
|
task 'default' => ['test']
|
16
|
+
|
17
|
+
|
18
|
+
namespace "flickr" do
|
19
|
+
|
20
|
+
desc "Get an access token"
|
21
|
+
task "authorise" do
|
22
|
+
Flickr::OAuthCient.authorize
|
23
|
+
end
|
24
|
+
end
|
data/lib/flickrrb.rb
CHANGED
@@ -2,7 +2,6 @@ require 'json'
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'cgi'
|
5
|
-
require 'rexml/document'
|
6
5
|
|
7
6
|
class APIException < StandardError; end
|
8
7
|
|
@@ -21,15 +20,15 @@ class Flickr
|
|
21
20
|
|
22
21
|
def method_missing name, *args
|
23
22
|
unless args.empty? || args.first.class == Hash
|
24
|
-
|
25
|
-
|
23
|
+
@method.clear
|
24
|
+
fail APIException, "Args must be a hash"
|
26
25
|
end
|
27
26
|
|
28
27
|
m = FlickrMethod.new(name, args.first)
|
29
28
|
@method << m
|
30
29
|
unless args.empty?
|
31
30
|
p @method if @debug
|
32
|
-
begin
|
31
|
+
begin # FIXME
|
33
32
|
command = build_command
|
34
33
|
@method.clear
|
35
34
|
@flickr_client.request(command)
|
@@ -141,7 +140,8 @@ class Flickr
|
|
141
140
|
:location,
|
142
141
|
:geoperms,
|
143
142
|
:urls,
|
144
|
-
:media
|
143
|
+
:media,
|
144
|
+
:permissions].each {|a| attr_accessor a}
|
145
145
|
|
146
146
|
def initialize data
|
147
147
|
super
|
@@ -199,7 +199,7 @@ class Flickr
|
|
199
199
|
p j if @debug
|
200
200
|
m = j.match(/^jsonFlickrApi\((.+)\)$/)
|
201
201
|
|
202
|
-
|
202
|
+
fail APIException, "Invalid response from Flickr" if m.nil?
|
203
203
|
|
204
204
|
data = JSON.parse m[1]
|
205
205
|
|
@@ -210,7 +210,8 @@ class Flickr
|
|
210
210
|
resp = self.send(k, data)
|
211
211
|
end
|
212
212
|
else
|
213
|
-
|
213
|
+
# FIXME Fail in send
|
214
|
+
fail APIException, "#{data['code']}: #{data['message']}"
|
214
215
|
end
|
215
216
|
|
216
217
|
resp
|
@@ -220,7 +221,7 @@ class Flickr
|
|
220
221
|
# This is a bit ugly!
|
221
222
|
code = xml.elements['rsp'].elements['err'].attributes['code']
|
222
223
|
message = xml.elements['rsp'].elements['err'].attributes['msg']
|
223
|
-
|
224
|
+
fail APIException, "#{code}: #{message}"
|
224
225
|
end
|
225
226
|
|
226
227
|
def stat data
|
@@ -278,5 +279,62 @@ class Flickr
|
|
278
279
|
end
|
279
280
|
end
|
280
281
|
|
282
|
+
require 'oauth'
|
283
|
+
|
284
|
+
class OAuthCient
|
285
|
+
def initialize params = {}
|
286
|
+
flickr_url = URI.parse "http://api.flickr.com/"
|
287
|
+
|
288
|
+
consumer = OAuth::Consumer.new(params[:consumer_key], params[:consumer_secret],
|
289
|
+
site: "http://api.flickr.com/",
|
290
|
+
request_token_path: "/services/oauth/request_token",
|
291
|
+
access_token_path: "/services/oauth/access_token",
|
292
|
+
authorize_path: "/services/oauth/authorize")
|
293
|
+
|
294
|
+
access_keys = {oauth_token: params[:access_token],
|
295
|
+
oauth_token_secret: params[:access_secret]}
|
296
|
+
|
297
|
+
@access = OAuth::AccessToken.from_hash(consumer, access_keys)
|
298
|
+
end
|
299
|
+
|
300
|
+
def get path
|
301
|
+
@access.get path
|
302
|
+
end
|
303
|
+
|
304
|
+
# def post path, params, headers = {}
|
305
|
+
# @access.post path, params, headers
|
306
|
+
# end
|
307
|
+
|
308
|
+
def self.authorize
|
309
|
+
print "Enter consumer key: "
|
310
|
+
consumer_key = $stdin.gets.chomp
|
311
|
+
|
312
|
+
print "Enter consumer secret: "
|
313
|
+
consumer_secret = $stdin.gets.chomp
|
314
|
+
|
315
|
+
|
316
|
+
consumer = OAuth::Consumer.new(consumer_key, consumer_secret,
|
317
|
+
site: 'http://www.flickr.com', # Note www
|
318
|
+
request_token_path: "/services/oauth/request_token",
|
319
|
+
access_token_path: "/services/oauth/access_token",
|
320
|
+
authorize_path: "/services/oauth/authorize")
|
321
|
+
|
322
|
+
request_token = consumer.get_request_token
|
323
|
+
p "\nGo to this url and click 'Authorize' to get the token:"
|
324
|
+
p request_token.authorize_url
|
325
|
+
print "\nEnter token: "
|
326
|
+
token = $stdin.gets.chomp
|
327
|
+
|
328
|
+
access_token = request_token.get_access_token(:oauth_verifier => token)
|
329
|
+
|
330
|
+
p "\nAuthorisation complete! Use the following params to access Flickr:\n\n"
|
331
|
+
p "consumer_key = '#{consumer.key}'"
|
332
|
+
p "consumer_secret = '#{consumer.secret}'"
|
333
|
+
p "access_token = '#{access_token.token}'"
|
334
|
+
p "access_secret = '#{access_token.secret}'"
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
338
|
+
|
281
339
|
end
|
282
340
|
|
data/test/flickrrb_test.rb
CHANGED
@@ -3,8 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
|
3
3
|
class Test_Flickr < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@http_client = MiniTest::Mock.new
|
6
|
-
|
7
|
-
@flickr = Flickr.new :api_key => api_key, :debug => false, :http => @http_client
|
6
|
+
@flickr = Flickr.new :api_key => "api_key", :debug => false, :http => @http_client
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_api_key_exception
|
data/test/groups_test.rb
CHANGED
@@ -3,8 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
|
3
3
|
class GroupsTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@http_client = MiniTest::Mock.new
|
6
|
-
|
7
|
-
@flickr = Flickr.new :api_key => api_key, :debug => false, :http => @http_client
|
6
|
+
@flickr = Flickr.new :api_key => "api_key", :debug => false, :http => @http_client
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_group
|
data/test/people_test.rb
CHANGED
@@ -3,8 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
|
3
3
|
class PeopleTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@http_client = MiniTest::Mock.new
|
6
|
-
|
7
|
-
@flickr = Flickr.new :api_key => api_key, :debug => false, :http => @http_client
|
6
|
+
@flickr = Flickr.new :api_key => "api_key", :debug => false, :http => @http_client
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_get_info
|
data/test/photos_test.rb
CHANGED
@@ -3,8 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
|
3
3
|
class PhotosTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@http_client = MiniTest::Mock.new
|
6
|
-
|
7
|
-
@flickr = Flickr.new :api_key => api_key, :debug => false, :http => @http_client
|
6
|
+
@flickr = Flickr.new :api_key => "api_key", :debug => false, :http => @http_client
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_photo
|
data/test/test_helper.rb
CHANGED
@@ -20,16 +20,16 @@ class MiniTest::Unit::TestCase
|
|
20
20
|
def flickr_commands
|
21
21
|
{
|
22
22
|
:bad_api_key => ["/services/rest/?method=flickr.photos.getInfo&api_key=bad_key&photo_id=1848466274&format=json"],
|
23
|
-
:bad_args => ["/services/rest/?method=flickr.people.getInfo&api_key=
|
23
|
+
:bad_args => ["/services/rest/?method=flickr.people.getInfo&api_key=api_key&xxxx=12656878%40N06&format=json"],
|
24
24
|
|
25
|
-
:photos_get_info => ["/services/rest/?method=flickr.photos.getInfo&api_key=
|
26
|
-
:photos_get_sizes => ["/services/rest/?method=flickr.photos.getSizes&api_key=
|
25
|
+
:photos_get_info => ["/services/rest/?method=flickr.photos.getInfo&api_key=api_key&photo_id=1848466274&format=json"],
|
26
|
+
:photos_get_sizes => ["/services/rest/?method=flickr.photos.getSizes&api_key=api_key&photo_id=1848466274&format=json"],
|
27
27
|
|
28
|
-
:people_get_info => ["/services/rest/?method=flickr.people.getInfo&api_key=
|
29
|
-
:people_get_info_not_found => ["/services/rest/?method=flickr.people.getInfo&api_key=
|
30
|
-
:people_by_user_name => ["/services/rest/?method=flickr.people.findByUsername&api_key=
|
28
|
+
:people_get_info => ["/services/rest/?method=flickr.people.getInfo&api_key=api_key&user_id=12656878%40N06&format=json"],
|
29
|
+
:people_get_info_not_found => ["/services/rest/?method=flickr.people.getInfo&api_key=api_key&user_id=xxxx&format=json"],
|
30
|
+
:people_by_user_name => ["/services/rest/?method=flickr.people.findByUsername&api_key=api_key&username=Henry+Maddocks&format=json"],
|
31
31
|
|
32
|
-
:groups_pools_get_photos => ["/services/rest/?method=flickr.groups.pools.getPhotos&api_key=
|
32
|
+
:groups_pools_get_photos => ["/services/rest/?method=flickr.groups.pools.getPhotos&api_key=api_key&user_id=12656878%40N06&group_id=99404851%40N00&format=json"]
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickrrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-04 00:00:00.000000000 +12:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: oauth
|
17
|
+
requirement: &2161887080 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2161887080
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: simplecov
|
28
|
+
requirement: &2161886520 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2161886520
|
15
37
|
description: A simple interface to the Flickr public API.
|
16
|
-
email:
|
38
|
+
email: hmaddocks@me.com
|
17
39
|
executables: []
|
18
40
|
extensions: []
|
19
41
|
extra_rdoc_files: []
|
@@ -28,7 +50,7 @@ files:
|
|
28
50
|
- test/photos_test.rb
|
29
51
|
- test/test_helper.rb
|
30
52
|
has_rdoc: true
|
31
|
-
homepage:
|
53
|
+
homepage: https://github.com/hmaddocks/flickrrb
|
32
54
|
licenses: []
|
33
55
|
post_install_message:
|
34
56
|
rdoc_options: []
|