objectiveflickr 0.9.4 → 0.9.5
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/History.txt +30 -0
- data/lib/objectiveflickr/flickr_invocation.rb +47 -18
- data/lib/objectiveflickr/flickr_photo.rb +34 -9
- data/lib/objectiveflickr/version.rb +1 -1
- data/test/objectiveflickr_test.rb +13 -3
- metadata +12 -3
data/History.txt
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
2007-01-29 (0.9.5):
|
|
2
|
+
* Supports Flickr's new photo URL scheme (announced January 19, 2007):
|
|
3
|
+
http://www.flickr.com/services/api/misc.urls.html
|
|
4
|
+
|
|
5
|
+
Flickr now requires API users to use the "originalsecret" and
|
|
6
|
+
"originalformat" to retrieve the original photo--when it is
|
|
7
|
+
accessible to the request maker (auth'ed or not) at all.
|
|
8
|
+
|
|
9
|
+
In order for this to work, you must supply an extra "extras"
|
|
10
|
+
parameter, set to "original_format", when you're calling
|
|
11
|
+
flickr.photo.search (the originalsecret will be returned back
|
|
12
|
+
along the way), for example:
|
|
13
|
+
|
|
14
|
+
f.call("flickr.photo.search", ..., :extras=>"original_format")
|
|
15
|
+
|
|
16
|
+
For more information on flickr.photo.search, please refer to
|
|
17
|
+
http://www.flickr.com/services/api/flickr.photos.search.html
|
|
18
|
+
|
|
19
|
+
* :type key in module FlickrPhoto's helper methods is now
|
|
20
|
+
deprecated, replaced by :format for the sake of naming consistency.
|
|
21
|
+
|
|
22
|
+
* The change of Flickr's photo URL scheme has the implication that
|
|
23
|
+
url_from_element_id, hash_from_element_id and element_id_from_hash
|
|
24
|
+
will not work correctly with original photos. I'm still
|
|
25
|
+
considering encoding the extra originalformat and originalsecret
|
|
26
|
+
values in the element_id scheme, but I'm reluctant since it seems
|
|
27
|
+
that Flickr is doing its due to protect users' photos, which I
|
|
28
|
+
think is the right thing to do.
|
|
29
|
+
|
|
30
|
+
|
|
1
31
|
2007-01-08 (0.9.4):
|
|
2
32
|
* Fixed a serious defect where API parameters, such as search text,
|
|
3
33
|
must be URL-escaped. There's a catch if you tried previously to use
|
|
@@ -47,8 +47,12 @@ class FlickrInvocation
|
|
|
47
47
|
# call will automatically be signed, and the call will be
|
|
48
48
|
# treated by Flickr as an authenticated call
|
|
49
49
|
def call(method, params=nil)
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if params && params[:post]
|
|
51
|
+
rsp = FlickrResponse.new Net::HTTP.post_form(URI.parse(REST_ENDPOINT), post_params(method, params)).body
|
|
52
|
+
else
|
|
53
|
+
url = method_url(method, params)
|
|
54
|
+
rsp = FlickrResponse.new Net::HTTP.get(URI.parse(url))
|
|
55
|
+
end
|
|
52
56
|
|
|
53
57
|
if @options[:raise_exception_on_error] && rsp.error?
|
|
54
58
|
raise RuntimeError, rsp
|
|
@@ -61,9 +65,18 @@ class FlickrInvocation
|
|
|
61
65
|
# to complete the Flickr authentication process (Flickr then uses
|
|
62
66
|
# the callback address you've set previously to pass the
|
|
63
67
|
# authentication frob back to your web app)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
#
|
|
69
|
+
# New in 0.9.5: frob parameter for desktop applications
|
|
70
|
+
# http://www.flickr.com/services/api/auth.howto.desktop.html
|
|
71
|
+
def login_url(permission, frob=nil)
|
|
72
|
+
if frob
|
|
73
|
+
sig = api_sig(:api_key => @api_key, :perms => permission.to_s, :frob=> frob)
|
|
74
|
+
url = "#{AUTH_ENDPOINT}?api_key=#{@api_key}&perms=#{permission}&frob=#{frob}&api_sig=#{sig}"
|
|
75
|
+
else
|
|
76
|
+
sig = api_sig(:api_key => @api_key, :perms => permission.to_s)
|
|
77
|
+
url = "#{AUTH_ENDPOINT}?api_key=#{@api_key}&perms=#{permission}&api_sig=#{sig}"
|
|
78
|
+
end
|
|
79
|
+
url
|
|
67
80
|
end
|
|
68
81
|
|
|
69
82
|
# DEPRECATED--Use FlickrPhoto.url_from_hash(params)
|
|
@@ -103,12 +116,39 @@ class FlickrInvocation
|
|
|
103
116
|
|
|
104
117
|
private
|
|
105
118
|
def method_url(method, params=nil)
|
|
119
|
+
url = "#{REST_ENDPOINT}?api_key=#{@api_key}&method=#{method}"
|
|
106
120
|
p = params || {}
|
|
121
|
+
sign_params(method, p)
|
|
107
122
|
|
|
123
|
+
p.keys.each { |k| url += "&#{k.to_s}=#{CGI.escape(p[k].to_s)}" }
|
|
124
|
+
url
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def post_params(method, params)
|
|
128
|
+
p = params ? params.clone : {}
|
|
129
|
+
p.delete :post
|
|
130
|
+
sign_params(method, p)
|
|
131
|
+
|
|
132
|
+
# since we're using Net::HTTP.post_form to do the call,
|
|
133
|
+
# CGI escape is already done for us, so, no escape here
|
|
134
|
+
# p.keys.each { |k| p[k] = CGI.escape(p[k].to_s) }
|
|
135
|
+
p
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def api_sig(params)
|
|
139
|
+
sigstr = @shared_secret
|
|
140
|
+
params.keys.sort { |x, y| x.to_s <=> y.to_s }.each do |k|
|
|
141
|
+
sigstr += k.to_s
|
|
142
|
+
sigstr += params[k].to_s
|
|
143
|
+
end
|
|
144
|
+
Digest::MD5.hexdigest(sigstr)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# we add json parameter here, telling Flickr we want json!
|
|
148
|
+
def sign_params(method, p)
|
|
108
149
|
p[:format] = 'json'
|
|
109
150
|
p[:nojsoncallback] = 1
|
|
110
151
|
|
|
111
|
-
url = "#{REST_ENDPOINT}?api_key=#{@api_key}&method=#{method}"
|
|
112
152
|
if p[:auth] || p["auth"] || p[:auth_token] || p["auth_token"]
|
|
113
153
|
p.delete(:auth)
|
|
114
154
|
p.delete("auth")
|
|
@@ -118,17 +158,6 @@ class FlickrInvocation
|
|
|
118
158
|
p["api_sig"] = api_sig(sigp)
|
|
119
159
|
end
|
|
120
160
|
|
|
121
|
-
p
|
|
122
|
-
url
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
private
|
|
126
|
-
def api_sig(params)
|
|
127
|
-
sigstr = @shared_secret
|
|
128
|
-
params.keys.sort { |x, y| x.to_s <=> y.to_s }.each do |k|
|
|
129
|
-
sigstr += k.to_s
|
|
130
|
-
sigstr += params[k].to_s
|
|
131
|
-
end
|
|
132
|
-
Digest::MD5.hexdigest(sigstr)
|
|
161
|
+
p
|
|
133
162
|
end
|
|
134
163
|
end
|
|
@@ -31,7 +31,14 @@ module FlickrPhoto
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# This utility method returns the URL of a Flickr photo using
|
|
34
|
-
# the keys :farm, :server, :id, :secret, :size and :
|
|
34
|
+
# the keys :farm, :server, :id, :secret, :size and :format
|
|
35
|
+
#
|
|
36
|
+
# The :type key that is used in ObjectiveFlickr prior to 0.9.5
|
|
37
|
+
# is deprecated. It is still supported, but support will be removed
|
|
38
|
+
# in 0.9.6.
|
|
39
|
+
#
|
|
40
|
+
# Since January 2007, Flickr requires API libraries to support
|
|
41
|
+
# :originalsecret and :originalformat
|
|
35
42
|
def self.url_from_hash(params)
|
|
36
43
|
self.url_from_normalized_hash(self.normalize_parameter(params))
|
|
37
44
|
end
|
|
@@ -42,13 +49,13 @@ module FlickrPhoto
|
|
|
42
49
|
# use in a div
|
|
43
50
|
def self.element_id_from_hash(params, prefix='photo')
|
|
44
51
|
p = self.normalize_parameter(params)
|
|
45
|
-
[prefix, p[:server], p[:id], p[:secret], p[:farm], p[:size], p[:
|
|
52
|
+
[prefix, p[:server], p[:id], p[:secret], p[:farm], p[:size], p[:format]].join("-")
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
# This utility method breaks apart the photo id into Flickr photo
|
|
49
56
|
# keys and returns the photo URL
|
|
50
57
|
def self.url_from_element_id(uid)
|
|
51
|
-
self.url_from_normalized_hash(self.
|
|
58
|
+
self.url_from_normalized_hash(self.hash_from_element_id(uid))
|
|
52
59
|
end
|
|
53
60
|
|
|
54
61
|
# This utility method breaks apart the photo id into Flickr photo
|
|
@@ -59,7 +66,7 @@ module FlickrPhoto
|
|
|
59
66
|
p = uid.split("-")
|
|
60
67
|
{
|
|
61
68
|
:server=>p[1], :id=>p[2], :secret=>p[3],
|
|
62
|
-
:farm=>p[4], :size=>p[5], :
|
|
69
|
+
:farm=>p[4], :size=>p[5], :format=>p[6],
|
|
63
70
|
}
|
|
64
71
|
end
|
|
65
72
|
|
|
@@ -80,21 +87,39 @@ module FlickrPhoto
|
|
|
80
87
|
|
|
81
88
|
private
|
|
82
89
|
def self.url_from_normalized_hash(p)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
if p[:size]=="o" && p[:originalformat] && p[:originalsecret]
|
|
91
|
+
url = "#{photo_url_base(p[:farm])}/#{p[:server]}/#{p[:id]}_#{p[:originalsecret]}"
|
|
92
|
+
url += "_o"
|
|
93
|
+
url += ".#{p[:originalformat]}"
|
|
94
|
+
else
|
|
95
|
+
url = "#{photo_url_base(p[:farm])}/#{p[:server]}/#{p[:id]}_#{p[:secret]}"
|
|
96
|
+
url += "_#{p[:size]}" if p[:size].length > 0
|
|
97
|
+
url += ".#{p[:format]}"
|
|
98
|
+
end
|
|
86
99
|
end
|
|
87
100
|
|
|
88
101
|
private
|
|
89
102
|
def self.normalize_parameter(params)
|
|
90
|
-
{
|
|
103
|
+
h = {
|
|
91
104
|
:farm => (params[:farm] || params["farm"] || "").to_s,
|
|
92
105
|
:server => (params[:server] || params["server"] || "").to_s,
|
|
93
106
|
:id => (params[:id] || params["id"] || "").to_s,
|
|
94
107
|
:secret => (params[:secret] || params["secret"] || "").to_s,
|
|
95
108
|
:size => (params[:size] || params["size"] || "").to_s,
|
|
96
|
-
:
|
|
109
|
+
:format => (params[:format] || params["format"] || params[:type] || params["type"] || "jpg").to_s
|
|
97
110
|
}
|
|
111
|
+
|
|
112
|
+
os = params[:originalsecret] || params["originalsecret"]
|
|
113
|
+
if os
|
|
114
|
+
h[:originalsecret] = os.to_s
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
of = params[:originalformat] || params["originalformat"]
|
|
118
|
+
if of
|
|
119
|
+
h[:originalformat] = of.to_s
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
h
|
|
98
123
|
end
|
|
99
124
|
|
|
100
125
|
private
|
|
@@ -21,9 +21,10 @@ class ObjectiveFlickrTest < Test::Unit::TestCase
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def test_echo_escaped_characters
|
|
24
|
-
r = @f.call("flickr.test.echo", :text=>"漢字 @ < > lorem ipsum")
|
|
24
|
+
r = @f.call("flickr.test.echo", :text=>"漢字 @ < > & lorem ipsum")
|
|
25
|
+
puts r.to_yaml
|
|
25
26
|
assert(r.ok?, "response should be ok")
|
|
26
|
-
assert_equal(
|
|
27
|
+
assert_equal("漢字 @ < > & lorem ipsum", r["text"]["_content"], "CJKV, HTML entities and other characters should be properly URL-escaped")
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
|
|
@@ -75,10 +76,19 @@ class ObjectiveFlickrTest < Test::Unit::TestCase
|
|
|
75
76
|
|
|
76
77
|
assert_equal(FlickrPhoto.url_from_element_id(uid), "http://farm321.static.flickr.com/1234/5678_90_b.jpg", "URL helper failed")
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
# type is deprecated
|
|
80
|
+
# params[:type] = 'jpg'
|
|
81
|
+
|
|
82
|
+
params[:format] = 'jpg'
|
|
79
83
|
h = FlickrPhoto.hash_from_element_id(uid)
|
|
80
84
|
assert_equal(h, params, "hash_from_element_id failed")
|
|
81
85
|
|
|
86
|
+
|
|
87
|
+
params[:originalformat] = 'png'
|
|
88
|
+
params[:originalsecret] = '9999'
|
|
89
|
+
params[:size] = 'o'
|
|
90
|
+
assert_equal("http://farm321.static.flickr.com/1234/5678_9999_o.png", FlickrPhoto.url_from_hash(params), "URL helper failed")
|
|
91
|
+
|
|
82
92
|
end
|
|
83
93
|
|
|
84
94
|
def test_buddy_icons
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
|
-
rubygems_version: 0.9.
|
|
2
|
+
rubygems_version: 0.9.1
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: objectiveflickr
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.9.
|
|
7
|
-
date: 2007-
|
|
6
|
+
version: 0.9.5
|
|
7
|
+
date: 2007-02-14 00:00:00 +08:00
|
|
8
8
|
summary: objectiveflickr is a minimalistic Flickr API library that uses REST-style calls and receives JSON response blocks, resulting in very concise code. Named so in order to echo another Flickr library of mine, under the same name, developed for Objective-C.
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|
|
@@ -63,3 +63,12 @@ dependencies:
|
|
|
63
63
|
- !ruby/object:Gem::Version
|
|
64
64
|
version: 0.0.0
|
|
65
65
|
version:
|
|
66
|
+
- !ruby/object:Gem::Dependency
|
|
67
|
+
name: hoe
|
|
68
|
+
version_requirement:
|
|
69
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 1.1.7
|
|
74
|
+
version:
|