flickraw 0.9.6 → 0.9.7
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.
- checksums.yaml +7 -0
- data/examples/upload.rb +1 -1
- data/examples/web_oauth.rb +2 -2
- data/lib/flickraw.rb +2 -1
- data/lib/flickraw/api.rb +16 -4
- data/lib/flickraw/error.rb +3 -0
- data/lib/flickraw/oauth.rb +6 -6
- data/lib/flickraw/response.rb +1 -1
- data/test/test.rb +14 -13
- metadata +14 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 851e439d2bb948eb0ecbd3a6b2804fe830ead230
|
4
|
+
data.tar.gz: 377698252b1f918e76e2f5872828e5d19e0d3f90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: acb89952f574296b48e1e1e6415a47baa21c4ec7ebcfbe00a3a96b54ba5a3c2acc326f23f78cd426a1f5f01df6fbd1e7960c8c0966b71e98b2fc622e2f50f752
|
7
|
+
data.tar.gz: 3a21201017f86c5a626bdb0d843e1f0005972c137495f9ce8ef622890c955b531f96d303497e8f3230b2c72f469e9757090ef533a634a49ef44d0428a250fb9c
|
data/examples/upload.rb
CHANGED
data/examples/web_oauth.rb
CHANGED
@@ -30,11 +30,11 @@ end
|
|
30
30
|
def callback
|
31
31
|
flickr = FlickRaw::Flickr.new
|
32
32
|
|
33
|
-
|
33
|
+
request_token = # Retrieve from cache or session etc - see above
|
34
34
|
oauth_token = params[:oauth_token]
|
35
35
|
oauth_verifier = params[:oauth_verifier]
|
36
36
|
|
37
|
-
raw_token = flickr.
|
37
|
+
raw_token = flickr.get_access_token(request_token['oauth_token'], request_token['oauth_token_secret'], oauth_verifier)
|
38
38
|
# raw_token is a hash like this {"user_nsid"=>"92023420%40N00", "oauth_token_secret"=>"XXXXXX", "username"=>"boncey", "fullname"=>"Darren%20Greaves", "oauth_token"=>"XXXXXX"}
|
39
39
|
# Use URI.unescape on the nsid and name parameters
|
40
40
|
|
data/lib/flickraw.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'flickraw/error'
|
2
3
|
require 'flickraw/oauth'
|
3
4
|
require 'flickraw/request'
|
4
5
|
require 'flickraw/response'
|
5
6
|
require 'flickraw/api'
|
6
7
|
|
7
8
|
module FlickRaw
|
8
|
-
VERSION='0.9.
|
9
|
+
VERSION='0.9.7'
|
9
10
|
USER_AGENT = "FlickRaw/#{VERSION}"
|
10
11
|
end
|
11
12
|
|
data/lib/flickraw/api.rb
CHANGED
@@ -24,6 +24,8 @@ module FlickRaw
|
|
24
24
|
URL_PHOTOSTREAM='http://www.flickr.com/photos/'.freeze
|
25
25
|
URL_SHORT='http://flic.kr/p/'.freeze
|
26
26
|
|
27
|
+
class FlickrAppNotConfigured < Error; end
|
28
|
+
|
27
29
|
# Root class of the flickr api hierarchy.
|
28
30
|
class Flickr < Request
|
29
31
|
# Authenticated access token
|
@@ -35,7 +37,9 @@ module FlickRaw
|
|
35
37
|
def self.build(methods); methods.each { |m| build_request m } end
|
36
38
|
|
37
39
|
def initialize # :nodoc:
|
38
|
-
|
40
|
+
if FlickRaw.api_key.nil? or FlickRaw.shared_secret.nil?
|
41
|
+
raise FlickrAppNotConfigured.new("No API key or secret defined!")
|
42
|
+
end
|
39
43
|
@oauth_consumer = OAuthClient.new(FlickRaw.api_key, FlickRaw.shared_secret)
|
40
44
|
@oauth_consumer.proxy = FlickRaw.proxy
|
41
45
|
@oauth_consumer.user_agent = USER_AGENT
|
@@ -49,8 +53,9 @@ module FlickRaw
|
|
49
53
|
#
|
50
54
|
# Raises FailedResponse if the response status is _failed_.
|
51
55
|
def call(req, args={}, &block)
|
56
|
+
oauth_args = args.delete(:oauth) || {}
|
52
57
|
rest_path = FlickRaw.secure ? REST_PATH_SECURE : REST_PATH
|
53
|
-
http_response = @oauth_consumer.post_form(rest_path, @access_secret, {:oauth_token => @access_token}, build_args(args, req))
|
58
|
+
http_response = @oauth_consumer.post_form(rest_path, @access_secret, {:oauth_token => @access_token}.merge(oauth_args), build_args(args, req))
|
54
59
|
process_response(req, http_response.body)
|
55
60
|
end
|
56
61
|
|
@@ -132,10 +137,17 @@ module FlickRaw
|
|
132
137
|
end
|
133
138
|
|
134
139
|
def upload_flickr(method, file, args={})
|
140
|
+
oauth_args = args.delete(:oauth) || {}
|
135
141
|
args = build_args(args)
|
136
|
-
|
142
|
+
if file.respond_to? :read
|
143
|
+
args['photo'] = file
|
144
|
+
else
|
145
|
+
args['photo'] = open(file, 'rb')
|
146
|
+
close_after = true
|
147
|
+
end
|
137
148
|
|
138
|
-
http_response = @oauth_consumer.post_multipart(method, @access_secret, {:oauth_token => @access_token}, args)
|
149
|
+
http_response = @oauth_consumer.post_multipart(method, @access_secret, {:oauth_token => @access_token}.merge(oauth_args), args)
|
150
|
+
args['photo'].close if close_after
|
139
151
|
process_response(method, http_response.body)
|
140
152
|
end
|
141
153
|
end
|
data/lib/flickraw/oauth.rb
CHANGED
@@ -3,8 +3,8 @@ require 'net/https'
|
|
3
3
|
|
4
4
|
module FlickRaw
|
5
5
|
class OAuthClient
|
6
|
-
class UnknownSignatureMethod <
|
7
|
-
class FailedResponse <
|
6
|
+
class UnknownSignatureMethod < Error; end
|
7
|
+
class FailedResponse < Error
|
8
8
|
def initialize(str)
|
9
9
|
@response = OAuthClient.parse_response(str)
|
10
10
|
super(@response['oauth_problem'])
|
@@ -18,8 +18,8 @@ module FlickRaw
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def escape(s)
|
21
|
-
encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/) {
|
22
|
-
|
21
|
+
encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/) { |special|
|
22
|
+
special.unpack("C*").map{|i| sprintf("%%%02X", i) }.join
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
@@ -100,8 +100,8 @@ module FlickRaw
|
|
100
100
|
request.body = ''
|
101
101
|
params.each { |k, v|
|
102
102
|
if v.respond_to? :read
|
103
|
-
basename = File.basename(v.path
|
104
|
-
basename ||= File.basename(v.base_uri
|
103
|
+
basename = File.basename(v.path.to_s) if v.respond_to? :path
|
104
|
+
basename ||= File.basename(v.base_uri.to_s) if v.respond_to? :base_uri
|
105
105
|
basename ||= "unknown"
|
106
106
|
request.body << "--#{boundary}\r\n" <<
|
107
107
|
"Content-Disposition: form-data; name=\"#{OAuthClient.encode_value(k)}\"; filename=\"#{OAuthClient.encode_value(basename)}\"\r\n" <<
|
data/lib/flickraw/response.rb
CHANGED
data/test/test.rb
CHANGED
@@ -8,7 +8,7 @@ require 'helper'
|
|
8
8
|
|
9
9
|
class Basic < Test::Unit::TestCase
|
10
10
|
def test_request
|
11
|
-
flickr_objects = %w{activity auth blogs collections commons contacts
|
11
|
+
flickr_objects = %w{activity auth blogs cameras collections commons contacts
|
12
12
|
favorites galleries groups interestingness machinetags panda
|
13
13
|
people photos photosets places prefs push reflection stats tags
|
14
14
|
test urls
|
@@ -33,6 +33,8 @@ class Basic < Test::Unit::TestCase
|
|
33
33
|
flickr.blogs.getList
|
34
34
|
flickr.blogs.getServices
|
35
35
|
flickr.blogs.postPhoto
|
36
|
+
flickr.cameras.getBrandModels
|
37
|
+
flickr.cameras.getBrands
|
36
38
|
flickr.collections.getInfo
|
37
39
|
flickr.collections.getTree
|
38
40
|
flickr.commons.getInstitutions
|
@@ -55,7 +57,18 @@ class Basic < Test::Unit::TestCase
|
|
55
57
|
flickr.galleries.getListForPhoto
|
56
58
|
flickr.galleries.getPhotos
|
57
59
|
flickr.groups.browse
|
60
|
+
flickr.groups.discuss.replies.add
|
61
|
+
flickr.groups.discuss.replies.delete
|
62
|
+
flickr.groups.discuss.replies.edit
|
63
|
+
flickr.groups.discuss.replies.getInfo
|
64
|
+
flickr.groups.discuss.replies.getList
|
65
|
+
flickr.groups.discuss.topics.add
|
66
|
+
flickr.groups.discuss.topics.getInfo
|
67
|
+
flickr.groups.discuss.topics.getList
|
58
68
|
flickr.groups.getInfo
|
69
|
+
flickr.groups.join
|
70
|
+
flickr.groups.joinRequest
|
71
|
+
flickr.groups.leave
|
59
72
|
flickr.groups.members.getList
|
60
73
|
flickr.groups.pools.add
|
61
74
|
flickr.groups.pools.getContext
|
@@ -262,18 +275,6 @@ class Basic < Test::Unit::TestCase
|
|
262
275
|
assert list.any? {|g| g.nsid == "51035612836@N01"}
|
263
276
|
end
|
264
277
|
|
265
|
-
# panda
|
266
|
-
def test_panda_getList
|
267
|
-
pandas = flickr.panda.getList
|
268
|
-
assert_equal ["ling ling", "hsing hsing", "wang wang"], pandas.to_a
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_panda_getPhotos
|
272
|
-
pandas = flickr.panda.getPhotos :panda_name => "wang wang"
|
273
|
-
assert_equal "wang wang", pandas.panda
|
274
|
-
assert_respond_to pandas[0], :title
|
275
|
-
end
|
276
|
-
|
277
278
|
# people
|
278
279
|
def test_people_findByEmail
|
279
280
|
user = flickr.people.findByEmail :find_email => "flickraw@yahoo.com"
|
metadata
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickraw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mael Clerambault
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description:
|
15
|
-
email:
|
14
|
+
email: mael@clerambault.fr
|
16
15
|
executables: []
|
17
16
|
extensions: []
|
18
17
|
extra_rdoc_files: []
|
@@ -24,39 +23,40 @@ files:
|
|
24
23
|
- examples/upload.rb
|
25
24
|
- examples/web_oauth.rb
|
26
25
|
- test/helper.rb
|
27
|
-
- test/test.rb
|
28
26
|
- test/test_upload.rb
|
29
|
-
-
|
27
|
+
- test/test.rb
|
28
|
+
- lib/flickraw/request.rb
|
30
29
|
- lib/flickraw/api.rb
|
30
|
+
- lib/flickraw/error.rb
|
31
31
|
- lib/flickraw/oauth.rb
|
32
|
-
- lib/flickraw/request.rb
|
33
32
|
- lib/flickraw/response.rb
|
33
|
+
- lib/flickraw.rb
|
34
34
|
- flickraw_rdoc.rb
|
35
35
|
- LICENSE
|
36
36
|
- README.rdoc
|
37
37
|
- rakefile
|
38
38
|
homepage: http://hanklords.github.com/flickraw/
|
39
|
-
licenses:
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
40
42
|
post_install_message:
|
41
43
|
rdoc_options: []
|
42
44
|
require_paths:
|
43
45
|
- lib
|
44
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
47
|
requirements:
|
47
|
-
- -
|
48
|
+
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
50
|
version: '0'
|
50
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version:
|
58
|
+
rubygems_version: 2.0.3
|
59
59
|
signing_key:
|
60
|
-
specification_version:
|
60
|
+
specification_version: 4
|
61
61
|
summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api
|
62
62
|
test_files: []
|