flickraw 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.rdoc +1 -1
- data/examples/auth.rb +1 -1
- data/lib/flickraw.rb +2 -2
- data/lib/flickraw/api.rb +43 -41
- data/lib/flickraw/oauth.rb +43 -44
- data/lib/flickraw/request.rb +37 -38
- data/lib/flickraw/response.rb +53 -49
- data/lib/flickraw/util.rb +0 -1
- data/test/test_request.rb +4 -0
- metadata +12 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 160c81f7e624a74d0659ac6af8c2113e31eddb1dca007aa8c476473473805070
|
4
|
+
data.tar.gz: 33fe9c9c542955b211d8127f3b093b48a4a2cb7e37ccdc3949abd59444c5a112
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de6bfc36428610b9d7d090a6b8e70a6c36d70ecf36eeae6023717eb4481096d75c52c7435118576b565ef529aa88110b9edf5ea00a9d88e89fa34afed1b72522
|
7
|
+
data.tar.gz: 76c6fc51e76ff719bffe5da9c80ec9bcdf9b5a57668b61d2d8bc5ea3dc563a88050b85e24f51292f969b914f4014a0f08fc7c73d183eeb6427f5e39a66c1f560
|
data/README.rdoc
CHANGED
@@ -62,7 +62,7 @@ This will recreate the documentation by fetching the methods descriptions from f
|
|
62
62
|
token = flickr.get_request_token
|
63
63
|
auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
|
64
64
|
|
65
|
-
puts "Open this url in your
|
65
|
+
puts "Open this url in your browser to complete the authentication process : #{auth_url}"
|
66
66
|
puts "Copy here the number given when you complete the process."
|
67
67
|
verify = gets.strip
|
68
68
|
|
data/examples/auth.rb
CHANGED
@@ -11,7 +11,7 @@ FlickRaw.shared_secret=SHARED_SECRET
|
|
11
11
|
token = flickr.get_request_token
|
12
12
|
auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
|
13
13
|
|
14
|
-
puts "Open this url in your
|
14
|
+
puts "Open this url in your browser to complete the authentication process : #{auth_url}"
|
15
15
|
puts "Copy here the number given when you complete the process."
|
16
16
|
verify = gets.strip
|
17
17
|
|
data/lib/flickraw.rb
CHANGED
data/lib/flickraw/api.rb
CHANGED
@@ -2,11 +2,11 @@ module FlickRaw
|
|
2
2
|
END_POINT='http://api.flickr.com/services'.freeze
|
3
3
|
END_POINT2='http://www.flickr.com/services'.freeze
|
4
4
|
END_POINT_SECURE='https://api.flickr.com/services'.freeze
|
5
|
-
|
5
|
+
|
6
6
|
FLICKR_OAUTH_REQUEST_TOKEN=(END_POINT2 + '/oauth/request_token').freeze
|
7
7
|
FLICKR_OAUTH_AUTHORIZE=(END_POINT2 + '/oauth/authorize').freeze
|
8
8
|
FLICKR_OAUTH_ACCESS_TOKEN=(END_POINT2 + '/oauth/access_token').freeze
|
9
|
-
|
9
|
+
|
10
10
|
FLICKR_OAUTH_REQUEST_TOKEN_SECURE=(END_POINT_SECURE + '/oauth/request_token').freeze
|
11
11
|
FLICKR_OAUTH_AUTHORIZE_SECURE=(END_POINT_SECURE + '/oauth/authorize').freeze
|
12
12
|
FLICKR_OAUTH_ACCESS_TOKEN_SECURE=(END_POINT_SECURE + '/oauth/access_token').freeze
|
@@ -14,7 +14,7 @@ module FlickRaw
|
|
14
14
|
REST_PATH=(END_POINT + '/rest/').freeze
|
15
15
|
UPLOAD_PATH=(END_POINT + '/upload/').freeze
|
16
16
|
REPLACE_PATH=(END_POINT + '/replace/').freeze
|
17
|
-
|
17
|
+
|
18
18
|
REST_PATH_SECURE=(END_POINT_SECURE + '/rest/').freeze
|
19
19
|
UPLOAD_PATH_SECURE=(END_POINT_SECURE + '/upload/').freeze
|
20
20
|
REPLACE_PATH_SECURE=(END_POINT_SECURE + '/replace/').freeze
|
@@ -30,10 +30,10 @@ module FlickRaw
|
|
30
30
|
class Flickr < Request
|
31
31
|
# Authenticated access token
|
32
32
|
attr_accessor :access_token
|
33
|
-
|
33
|
+
|
34
34
|
# Authenticated access token secret
|
35
35
|
attr_accessor :access_secret
|
36
|
-
|
36
|
+
|
37
37
|
def self.build(methods); methods.each { |m| build_request m } end
|
38
38
|
|
39
39
|
def initialize(api_key: FlickRaw.api_key,
|
@@ -51,17 +51,17 @@ module FlickRaw
|
|
51
51
|
@oauth_consumer.ca_path = FlickRaw.ca_path
|
52
52
|
@oauth_consumer.user_agent = USER_AGENT
|
53
53
|
@access_token = @access_secret = nil
|
54
|
-
|
54
|
+
|
55
55
|
Flickr.build(call('flickr.reflection.getMethods')) if Flickr.flickr_objects.empty?
|
56
56
|
super self
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
# This is the central method. It does the actual request to the flickr server.
|
60
60
|
#
|
61
61
|
# Raises FailedResponse if the response status is _failed_.
|
62
62
|
def call(req, args={}, &block)
|
63
63
|
oauth_args = args.delete(:oauth) || {}
|
64
|
-
rest_path = FlickRaw.secure ? REST_PATH_SECURE :
|
64
|
+
rest_path = FlickRaw.secure ? REST_PATH_SECURE : REST_PATH
|
65
65
|
http_response = @oauth_consumer.post_form(rest_path, @access_secret, {:oauth_token => @access_token}.merge(oauth_args), build_args(args, req))
|
66
66
|
process_response(req, http_response.body)
|
67
67
|
end
|
@@ -73,7 +73,7 @@ module FlickRaw
|
|
73
73
|
flickr_oauth_request_token = FlickRaw.secure ? FLICKR_OAUTH_REQUEST_TOKEN_SECURE : FLICKR_OAUTH_REQUEST_TOKEN
|
74
74
|
@oauth_consumer.request_token(flickr_oauth_request_token, args)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
# Get the oauth authorize url.
|
78
78
|
#
|
79
79
|
# auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
|
@@ -125,19 +125,19 @@ module FlickRaw
|
|
125
125
|
code = response[/code="([^"]+)"/, 1]
|
126
126
|
raise FailedResponse.new(msg, code, req)
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
type = response[/<(\w+)/, 1]
|
130
130
|
h = {
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
'secret' => response[/secret="([^"]+)"/, 1],
|
132
|
+
'originalsecret' => response[/originalsecret="([^"]+)"/, 1],
|
133
|
+
'_content' => response[/>([^<]+)<\//, 1]
|
134
134
|
}.delete_if {|k,v| v.nil? }
|
135
|
-
|
135
|
+
|
136
136
|
Response.build h, type
|
137
137
|
else
|
138
|
-
json = JSON.load(response.empty? ?
|
138
|
+
json = JSON.load(response.empty? ? '{}' : response)
|
139
139
|
raise FailedResponse.new(json['message'], json['code'], req) if json.delete('stat') == 'fail'
|
140
|
-
type, json = json.to_a.first if json.size == 1 and json.all? {|k,v| v.is_a? Hash}
|
140
|
+
type, json = json.to_a.first if json.size == 1 and json.all? { |k,v| v.is_a? Hash }
|
141
141
|
|
142
142
|
Response.build json, type
|
143
143
|
end
|
@@ -152,7 +152,7 @@ module FlickRaw
|
|
152
152
|
args['photo'] = open(file, 'rb')
|
153
153
|
close_after = true
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
http_response = @oauth_consumer.post_multipart(method, @access_secret, {:oauth_token => @access_token}.merge(oauth_args), args)
|
157
157
|
args['photo'].close if close_after
|
158
158
|
process_response(method, http_response.body)
|
@@ -162,26 +162,26 @@ module FlickRaw
|
|
162
162
|
class << self
|
163
163
|
# Your flickr API key, see http://www.flickr.com/services/api/keys for more information
|
164
164
|
attr_accessor :api_key
|
165
|
-
|
165
|
+
|
166
166
|
# The shared secret of _api_key_, see http://www.flickr.com/services/api/keys for more information
|
167
167
|
attr_accessor :shared_secret
|
168
|
-
|
168
|
+
|
169
169
|
# Use a proxy
|
170
170
|
attr_accessor :proxy
|
171
|
-
|
171
|
+
|
172
172
|
# Use ssl connection
|
173
173
|
attr_accessor :secure
|
174
174
|
|
175
175
|
# Check the server certificate (ssl connection only)
|
176
176
|
attr_accessor :check_certificate
|
177
|
-
|
177
|
+
|
178
178
|
# Set path of a CA certificate file in PEM format (ssl connection only)
|
179
179
|
attr_accessor :ca_file
|
180
180
|
|
181
181
|
# Set path to a directory of CA certificate files in PEM format (ssl connection only)
|
182
182
|
attr_accessor :ca_path
|
183
183
|
|
184
|
-
BASE58_ALPHABET=
|
184
|
+
BASE58_ALPHABET='123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.freeze
|
185
185
|
def base58(id)
|
186
186
|
id = id.to_i
|
187
187
|
alphabet = BASE58_ALPHABET.split(//)
|
@@ -193,35 +193,37 @@ module FlickRaw
|
|
193
193
|
r
|
194
194
|
end
|
195
195
|
|
196
|
-
def url(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
197
|
-
def url_m(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
198
|
-
def url_s(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
199
|
-
def url_t(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
200
|
-
def url_b(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
201
|
-
def url_z(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
202
|
-
def url_q(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
203
|
-
def url_n(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
204
|
-
def url_c(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret,
|
205
|
-
def
|
206
|
-
def
|
196
|
+
def url(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '', 'jpg'] end
|
197
|
+
def url_m(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_m', 'jpg'] end
|
198
|
+
def url_s(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_s', 'jpg'] end
|
199
|
+
def url_t(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_t', 'jpg'] end
|
200
|
+
def url_b(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_b', 'jpg'] end
|
201
|
+
def url_z(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_z', 'jpg'] end
|
202
|
+
def url_q(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_q', 'jpg'] end
|
203
|
+
def url_n(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_n', 'jpg'] end
|
204
|
+
def url_c(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_c', 'jpg'] end
|
205
|
+
def url_h(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_h', 'jpg'] end
|
206
|
+
def url_k(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, '_k', 'jpg'] end
|
207
|
+
def url_o(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.originalsecret, '_o', r.originalformat] end
|
208
|
+
def url_profile(r); URL_PROFILE + (r.owner.respond_to?(:nsid) ? r.owner.nsid : r.owner) + '/' end
|
207
209
|
def url_photopage(r); url_photostream(r) + r.id end
|
208
|
-
def url_photosets(r); url_photostream(r) +
|
210
|
+
def url_photosets(r); url_photostream(r) + 'sets/' end
|
209
211
|
def url_photoset(r); url_photosets(r) + r.id end
|
210
212
|
def url_short(r); URL_SHORT + base58(r.id) end
|
211
|
-
def url_short_m(r); URL_SHORT +
|
212
|
-
def url_short_s(r); URL_SHORT +
|
213
|
-
def url_short_t(r); URL_SHORT +
|
214
|
-
def url_short_q(r); URL_SHORT +
|
215
|
-
def url_short_n(r); URL_SHORT +
|
213
|
+
def url_short_m(r); URL_SHORT + 'img/' + base58(r.id) + '_m.jpg' end
|
214
|
+
def url_short_s(r); URL_SHORT + 'img/' + base58(r.id) + '.jpg' end
|
215
|
+
def url_short_t(r); URL_SHORT + 'img/' + base58(r.id) + '_t.jpg' end
|
216
|
+
def url_short_q(r); URL_SHORT + 'img/' + base58(r.id) + '_q.jpg' end
|
217
|
+
def url_short_n(r); URL_SHORT + 'img/' + base58(r.id) + '_n.jpg' end
|
216
218
|
def url_photostream(r)
|
217
219
|
URL_PHOTOSTREAM +
|
218
|
-
if r.respond_to?(:pathalias)
|
220
|
+
if r.respond_to?(:pathalias) && r.pathalias
|
219
221
|
r.pathalias
|
220
222
|
elsif r.owner.respond_to?(:nsid)
|
221
223
|
r.owner.nsid
|
222
224
|
else
|
223
225
|
r.owner
|
224
|
-
end +
|
226
|
+
end + '/'
|
225
227
|
end
|
226
228
|
end
|
227
229
|
end
|
data/lib/flickraw/oauth.rb
CHANGED
@@ -13,78 +13,78 @@ module FlickRaw
|
|
13
13
|
|
14
14
|
class << self
|
15
15
|
def encode_value(v)
|
16
|
-
v = v.to_s.encode(
|
16
|
+
v = v.to_s.encode('utf-8').force_encoding('ascii-8bit') if RUBY_VERSION >= '1.9'
|
17
17
|
v.to_s
|
18
18
|
end
|
19
19
|
|
20
20
|
def escape(s)
|
21
|
-
encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/)
|
22
|
-
special.unpack("C*").map{|i| sprintf("%%%02X", i) }.join
|
23
|
-
|
21
|
+
encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/) do |special|
|
22
|
+
special.unpack("C*").map { |i| sprintf("%%%02X", i) }.join
|
23
|
+
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def parse_response(text); Hash[text.split(
|
26
|
+
def parse_response(text); Hash[text.split('&').map { |s| s.split('=') }] end
|
27
27
|
|
28
28
|
def signature_base_string(method, url, params)
|
29
|
-
params_norm = params.map {|k,v| escape(k)
|
30
|
-
method.to_s.upcase
|
29
|
+
params_norm = params.map { |k,v| "#{escape(k)}=#{escape(v)}" }.sort.join('&')
|
30
|
+
"#{method.to_s.upcase}&#{escape(url)}&#{escape(params_norm)}"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def sign_plaintext(method, url, params, token_secret, consumer_secret)
|
34
|
-
escape(consumer_secret)
|
34
|
+
"#{escape(consumer_secret)}&#{escape(token_secret)}"
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def sign_rsa_sha1(method, url, params, token_secret, consumer_secret)
|
38
38
|
text = signature_base_string(method, url, params)
|
39
39
|
key = OpenSSL::PKey::RSA.new(consumer_secret)
|
40
40
|
digest = OpenSSL::Digest::SHA1.new
|
41
41
|
[key.sign(digest, text)].pack('m0').gsub(/\n$/,'')
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def sign_hmac_sha1(method, url, params, token_secret, consumer_secret)
|
45
45
|
text = signature_base_string(method, url, params)
|
46
|
-
key = escape(consumer_secret)
|
46
|
+
key = "#{escape(consumer_secret)}&#{escape(token_secret)}"
|
47
47
|
digest = OpenSSL::Digest::SHA1.new
|
48
48
|
[OpenSSL::HMAC.digest(digest, key, text)].pack('m0').gsub(/\n$/,'')
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def gen_timestamp; Time.now.to_i end
|
52
52
|
def gen_nonce; [OpenSSL::Random.random_bytes(32)].pack('m0').gsub(/\n$/,'') end
|
53
53
|
def gen_default_params
|
54
|
-
{ :oauth_version => "1.0", :oauth_signature_method =>
|
54
|
+
{ :oauth_version => "1.0", :oauth_signature_method => 'HMAC-SHA1',
|
55
55
|
:oauth_nonce => gen_nonce, :oauth_timestamp => gen_timestamp }
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def authorization_header(url, params)
|
59
|
-
params_norm = params.map {|k,v| %(#{escape(k)}="#{escape(v)}")}.sort.join(
|
59
|
+
params_norm = params.map { |k, v| %(#{escape(k)}="#{escape(v)}")}.sort.join(', ')
|
60
60
|
%(OAuth realm="#{url.to_s}", #{params_norm})
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
attr_accessor :user_agent
|
65
65
|
attr_reader :proxy
|
66
66
|
attr_accessor :check_certificate
|
67
67
|
attr_accessor :ca_file
|
68
68
|
attr_accessor :ca_path
|
69
69
|
def proxy=(url); @proxy = URI.parse(url || '') end
|
70
|
-
|
70
|
+
|
71
71
|
def initialize(consumer_key, consumer_secret)
|
72
72
|
@consumer_key, @consumer_secret = consumer_key, consumer_secret
|
73
73
|
self.proxy = nil
|
74
74
|
end
|
75
75
|
|
76
76
|
def request_token(url, oauth_params = {})
|
77
|
-
r = post_form(url, nil, {:oauth_callback =>
|
77
|
+
r = post_form(url, nil, {:oauth_callback => 'oob'}.merge(oauth_params))
|
78
78
|
OAuthClient.parse_response(r.body)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
def authorize_url(url, oauth_params = {})
|
82
|
-
params_norm = oauth_params.map {|k,v| OAuthClient.escape(k)
|
83
|
-
url =
|
84
|
-
url.query = url.query ? url.query
|
82
|
+
params_norm = oauth_params.map { |k,v| "#{OAuthClient.escape(k)}=#{OAuthClient.escape(v)}" }.sort.join('&')
|
83
|
+
url = URI.parse(url)
|
84
|
+
url.query = url.query ? "#{url.query}&#{params_norm}" : params_norm
|
85
85
|
url.to_s
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def access_token(url, token_secret, oauth_params = {})
|
89
89
|
r = post_form(url, token_secret, oauth_params)
|
90
90
|
OAuthClient.parse_response(r.body)
|
@@ -92,32 +92,32 @@ module FlickRaw
|
|
92
92
|
|
93
93
|
def post_form(url, token_secret, oauth_params = {}, params = {})
|
94
94
|
encoded_params = Hash[*params.map {|k,v| [OAuthClient.encode_value(k), OAuthClient.encode_value(v)]}.flatten]
|
95
|
-
post(url, token_secret, oauth_params, params) {|request| request.form_data = encoded_params}
|
95
|
+
post(url, token_secret, oauth_params, params) { |request| request.form_data = encoded_params }
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def post_multipart(url, token_secret, oauth_params = {}, params = {})
|
99
99
|
post(url, token_secret, oauth_params, params) {|request|
|
100
100
|
boundary = "FlickRaw#{OAuthClient.gen_nonce}"
|
101
101
|
request['Content-type'] = "multipart/form-data, boundary=#{boundary}"
|
102
102
|
|
103
103
|
request.body = ''
|
104
|
-
params.each
|
104
|
+
params.each do |k, v|
|
105
105
|
if v.respond_to? :read
|
106
106
|
basename = File.basename(v.path.to_s) if v.respond_to? :path
|
107
107
|
basename ||= File.basename(v.base_uri.to_s) if v.respond_to? :base_uri
|
108
108
|
basename ||= "unknown"
|
109
109
|
request.body << "--#{boundary}\r\n" <<
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
"Content-Disposition: form-data; name=\"#{OAuthClient.encode_value(k)}\"; filename=\"#{OAuthClient.encode_value(basename)}\"\r\n" <<
|
111
|
+
"Content-Transfer-Encoding: binary\r\n" <<
|
112
|
+
"Content-Type: image/jpeg\r\n\r\n" <<
|
113
|
+
v.read << "\r\n"
|
114
114
|
else
|
115
115
|
request.body << "--#{boundary}\r\n" <<
|
116
|
-
|
117
|
-
|
116
|
+
"Content-Disposition: form-data; name=\"#{OAuthClient.encode_value(k)}\"\r\n\r\n" <<
|
117
|
+
"#{OAuthClient.encode_value(v)}\r\n"
|
118
118
|
end
|
119
|
-
|
120
|
-
|
119
|
+
end
|
120
|
+
|
121
121
|
request.body << "--#{boundary}--"
|
122
122
|
}
|
123
123
|
end
|
@@ -125,11 +125,11 @@ module FlickRaw
|
|
125
125
|
private
|
126
126
|
def sign(method, url, params, token_secret = nil)
|
127
127
|
case params[:oauth_signature_method]
|
128
|
-
when
|
128
|
+
when 'HMAC-SHA1'
|
129
129
|
OAuthClient.sign_hmac_sha1(method, url, params, token_secret, @consumer_secret)
|
130
|
-
when
|
130
|
+
when 'RSA-SHA1'
|
131
131
|
OAuthClient.sign_rsa_sha1(method, url, params, token_secret, @consumer_secret)
|
132
|
-
when
|
132
|
+
when 'PLAINTEXT'
|
133
133
|
OAuthClient.sign_plaintext(method, url, params, token_secret, @consumer_secret)
|
134
134
|
else
|
135
135
|
raise UnknownSignatureMethod, params[:oauth_signature_method]
|
@@ -140,9 +140,9 @@ module FlickRaw
|
|
140
140
|
url = URI.parse(url)
|
141
141
|
default_oauth_params = OAuthClient.gen_default_params
|
142
142
|
default_oauth_params[:oauth_consumer_key] = @consumer_key
|
143
|
-
default_oauth_params[:oauth_signature_method] =
|
143
|
+
default_oauth_params[:oauth_signature_method] = 'PLAINTEXT' if url.scheme == 'https'
|
144
144
|
oauth_params = default_oauth_params.merge(oauth_params)
|
145
|
-
params_signed = params.reject {|k,v| v.respond_to? :read}.merge(oauth_params)
|
145
|
+
params_signed = params.reject { |k,v| v.respond_to? :read }.merge(oauth_params)
|
146
146
|
oauth_params[:oauth_signature] = sign(:post, url, params_signed, token_secret)
|
147
147
|
|
148
148
|
http = Net::HTTP.new(url.host, url.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
|
@@ -150,18 +150,17 @@ module FlickRaw
|
|
150
150
|
http.verify_mode = (@check_certificate ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE)
|
151
151
|
http.ca_file = @ca_file
|
152
152
|
http.ca_path = @ca_path
|
153
|
-
r = http.start
|
153
|
+
r = http.start do |agent|
|
154
154
|
request = Net::HTTP::Post.new(url.path)
|
155
155
|
request['User-Agent'] = @user_agent if @user_agent
|
156
156
|
request['Authorization'] = OAuthClient.authorization_header(url, oauth_params)
|
157
157
|
|
158
158
|
yield request
|
159
159
|
agent.request(request)
|
160
|
-
|
161
|
-
|
160
|
+
end
|
161
|
+
|
162
162
|
raise FailedResponse.new(r.body) if r.is_a? Net::HTTPClientError
|
163
163
|
r
|
164
164
|
end
|
165
165
|
end
|
166
|
-
|
167
166
|
end
|
data/lib/flickraw/request.rb
CHANGED
@@ -1,50 +1,49 @@
|
|
1
1
|
module FlickRaw
|
2
|
-
class Request
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
class Request
|
3
|
+
def initialize(flickr = nil) # :nodoc:
|
4
|
+
@flickr = flickr
|
5
|
+
|
6
|
+
self.class.flickr_objects.each {|name|
|
7
|
+
klass = self.class.const_get name.capitalize
|
8
|
+
instance_variable_set "@#{name}", klass.new(@flickr)
|
9
|
+
}
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def self.build_request(req) # :nodoc:
|
13
|
+
method_nesting = req.split '.'
|
14
|
+
raise "'#{@name}' : Method name mismatch" if method_nesting.shift != request_name.split('.').last
|
15
|
+
|
16
|
+
if method_nesting.size > 1
|
17
|
+
name = method_nesting.first
|
18
|
+
class_name = name.capitalize
|
19
|
+
if flickr_objects.include? name
|
20
|
+
klass = const_get(class_name)
|
21
|
+
else
|
22
|
+
klass = Class.new Request
|
23
|
+
const_set(class_name, klass)
|
24
|
+
attr_reader name
|
25
|
+
flickr_objects << name
|
26
|
+
end
|
15
27
|
|
16
|
-
|
17
|
-
name = method_nesting.first
|
18
|
-
class_name = name.capitalize
|
19
|
-
if flickr_objects.include? name
|
20
|
-
klass = const_get(class_name)
|
28
|
+
klass.build_request method_nesting.join('.')
|
21
29
|
else
|
22
|
-
|
23
|
-
|
24
|
-
attr_reader name
|
25
|
-
flickr_objects << name
|
26
|
-
end
|
27
|
-
|
28
|
-
klass.build_request method_nesting.join('.')
|
29
|
-
else
|
30
|
-
req = method_nesting.first
|
31
|
-
module_eval %{
|
30
|
+
req = method_nesting.first
|
31
|
+
module_eval %{
|
32
32
|
def #{req}(*args, &block)
|
33
33
|
@flickr.call("#{request_name}.#{req}", *args, &block)
|
34
34
|
end
|
35
|
-
|
36
|
-
|
35
|
+
} if Util.safe_for_eval?(req)
|
36
|
+
flickr_methods << req
|
37
|
+
end
|
37
38
|
end
|
38
|
-
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
# List the flickr subobjects of this object
|
41
|
+
def self.flickr_objects; @flickr_objects ||= [] end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# Returns the prefix of the request corresponding to this class.
|
47
|
-
def self.request_name; name.downcase.gsub(/::/, '.').sub(/[^\.]+\./, '') end
|
48
|
-
end
|
43
|
+
# List the flickr methods of this object
|
44
|
+
def self.flickr_methods; @flickr_methods ||= [] end
|
49
45
|
|
46
|
+
# Returns the prefix of the request corresponding to this class.
|
47
|
+
def self.request_name; name.downcase.gsub(/::/, '.').sub(/[^\.]+\./, '') end
|
48
|
+
end
|
50
49
|
end
|
data/lib/flickraw/response.rb
CHANGED
@@ -1,58 +1,62 @@
|
|
1
1
|
module FlickRaw
|
2
|
-
class Response
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
class Response
|
3
|
+
def self.build(h, type) # :nodoc:
|
4
|
+
if h.is_a? Response
|
5
|
+
h
|
6
|
+
elsif type =~ /s$/ and (a = h[$`]).is_a? Array
|
7
|
+
ResponseList.new(h, type, a.collect { |e| Response.build(e, $`) })
|
8
|
+
elsif h.keys == ['_content']
|
9
|
+
h['_content']
|
10
|
+
else
|
11
|
+
Response.new(h, type)
|
12
|
+
end
|
12
13
|
end
|
13
|
-
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
attr_reader :flickr_type
|
16
|
+
def initialize(h, type) # :nodoc:
|
17
|
+
@flickr_type, @h = type, {}
|
18
|
+
methods = 'class << self;'
|
19
|
+
h.each do |k, v|
|
20
|
+
@h[k] = case v
|
21
|
+
when Hash then Response.build(v, k)
|
22
|
+
when Array then v.collect { |e| Response.build(e, k) }
|
23
|
+
else v
|
24
|
+
end
|
25
|
+
methods << "def #{k}; @h['#{k}'] end;" if Util.safe_for_eval?(k)
|
24
26
|
end
|
25
|
-
methods <<
|
26
|
-
|
27
|
-
|
27
|
+
eval methods << 'end'
|
28
|
+
end
|
29
|
+
def [](k); @h[k] end
|
30
|
+
def to_s; @h['_content'] || super end
|
31
|
+
def inspect; @h.inspect end
|
32
|
+
def to_hash; @h end
|
33
|
+
def marshal_dump; [@h, @flickr_type] end
|
34
|
+
def marshal_load(data); initialize(*data) end
|
28
35
|
end
|
29
|
-
def [](k); @h[k] end
|
30
|
-
def to_s; @h["_content"] || super end
|
31
|
-
def inspect; @h.inspect end
|
32
|
-
def to_hash; @h end
|
33
|
-
def marshal_dump; [@h, @flickr_type] end
|
34
|
-
def marshal_load(data); initialize(*data) end
|
35
|
-
end
|
36
|
-
|
37
|
-
class ResponseList < Response
|
38
|
-
include Enumerable
|
39
|
-
def initialize(h, t, a); super(h, t); @a = a end
|
40
|
-
def [](k); k.is_a?(Fixnum) ? @a[k] : super(k) end
|
41
|
-
def each; @a.each{|e| yield e} end
|
42
|
-
def to_a; @a end
|
43
|
-
def inspect; @a.inspect end
|
44
|
-
def size; @a.size end
|
45
|
-
def marshal_dump; [@h, @flickr_type, @a] end
|
46
|
-
alias length size
|
47
|
-
end
|
48
36
|
|
49
|
-
class
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
37
|
+
class ResponseList < Response
|
38
|
+
include Enumerable
|
39
|
+
def initialize(h, t, a); super(h, t); @a = a end
|
40
|
+
def [](k); k.is_a?(Integer) ? @a[k] : super(k) end
|
41
|
+
def each
|
42
|
+
@a.each { |e| yield e }
|
43
|
+
end
|
44
|
+
def to_a; @a end
|
45
|
+
def inspect; @a.inspect end
|
46
|
+
def size; @a.size end
|
47
|
+
def map!
|
48
|
+
@a = @a.map { |e| yield e }
|
49
|
+
end
|
50
|
+
def marshal_dump; [@h, @flickr_type, @a] end
|
51
|
+
alias length size
|
55
52
|
end
|
56
|
-
end
|
57
53
|
|
54
|
+
class FailedResponse < Error
|
55
|
+
attr_reader :code
|
56
|
+
alias :msg :message
|
57
|
+
def initialize(msg, code, req)
|
58
|
+
@code = code
|
59
|
+
super("'#{req}' - #{msg}")
|
60
|
+
end
|
61
|
+
end
|
58
62
|
end
|
data/lib/flickraw/util.rb
CHANGED
data/test/test_request.rb
CHANGED
@@ -11,6 +11,7 @@ class TestReqeust < Test::Unit::TestCase
|
|
11
11
|
def test_flickr_api_is_accessible_via_methods
|
12
12
|
# Reset FlickRaw (was initialized in test/helper.rb) so the request methods
|
13
13
|
# are properly built
|
14
|
+
old_flickraw = $flickraw
|
14
15
|
$flickraw = nil
|
15
16
|
FlickRaw::Request.instance_variable_set(:@flickr_objects, nil)
|
16
17
|
|
@@ -18,6 +19,9 @@ class TestReqeust < Test::Unit::TestCase
|
|
18
19
|
|
19
20
|
assert_equal true, flickr.methods.include?(:fully)
|
20
21
|
assert_equal true, flickr.fully.methods.include?(:legal)
|
22
|
+
|
23
|
+
# Fix for failing subsequent tests
|
24
|
+
$flickraw = old_flickraw
|
21
25
|
end
|
22
26
|
|
23
27
|
def test_invalid_keys_are_skipped
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickraw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mael Clerambault
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: mael@clerambault.fr
|
@@ -16,28 +16,28 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- LICENSE
|
20
|
+
- README.rdoc
|
19
21
|
- examples/auth.rb
|
20
22
|
- examples/interestingness.rb
|
21
23
|
- examples/search.rb
|
22
24
|
- examples/sinatra.rb
|
23
25
|
- examples/upload.rb
|
24
26
|
- examples/web_oauth.rb
|
25
|
-
-
|
26
|
-
-
|
27
|
-
- test/test_request.rb
|
28
|
-
- test/test_response.rb
|
29
|
-
- test/test_upload.rb
|
27
|
+
- flickraw_rdoc.rb
|
28
|
+
- lib/flickraw.rb
|
30
29
|
- lib/flickraw/api.rb
|
31
30
|
- lib/flickraw/error.rb
|
32
31
|
- lib/flickraw/oauth.rb
|
33
32
|
- lib/flickraw/request.rb
|
34
33
|
- lib/flickraw/response.rb
|
35
34
|
- lib/flickraw/util.rb
|
36
|
-
- lib/flickraw.rb
|
37
|
-
- flickraw_rdoc.rb
|
38
|
-
- LICENSE
|
39
|
-
- README.rdoc
|
40
35
|
- rakefile
|
36
|
+
- test/helper.rb
|
37
|
+
- test/test.rb
|
38
|
+
- test/test_request.rb
|
39
|
+
- test/test_response.rb
|
40
|
+
- test/test_upload.rb
|
41
41
|
homepage: http://hanklords.github.com/flickraw/
|
42
42
|
licenses:
|
43
43
|
- MIT
|
@@ -57,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
|
61
|
-
rubygems_version: 2.0.14
|
60
|
+
rubygems_version: 3.0.2
|
62
61
|
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api
|