flickraw 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -118,7 +118,7 @@ If you need to have several users authenticated at the same time in your applica
118
118
 
119
119
  There are some helpers to build flickr urls :
120
120
 
121
- === url, url_m, url_s, url_t, url_b, url_z, url_o
121
+ === url, url_m, url_s, url_t, url_b, url_z, url_q, url_n, url_c, url_o
122
122
 
123
123
  info = flickr.photos.getInfo(:photo_id => "3839885270")
124
124
  FlickRaw.url_b(info) # => "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg"
@@ -0,0 +1,52 @@
1
+ require 'flickraw'
2
+
3
+ # A short howto for web flow authentication on the flickr website.
4
+ # This would live inside a rails controller or alternative framework equivalent
5
+ # Error handling left out for clarity :-)
6
+ # Added by Darren Greaves (https://github.com/boncey/)
7
+ #
8
+ # You need an API key first, see http://www.flickr.com/services/api/keys/
9
+ API_KEY=''
10
+ SHARED_SECRET=''
11
+
12
+ # This is the URL Flickr will redirect your users to once they agree to access
13
+ @callback_url='http://localhost:3000/auth_controller/callback'
14
+
15
+ FlickRaw.api_key=API_KEY
16
+ FlickRaw.shared_secret=SHARED_SECRET
17
+
18
+ # Users should hit this method to get the link which sends them to flickr
19
+ def auth
20
+ flickr = FlickRaw::Flickr.new
21
+ token = flickr.get_request_token(:oauth_callback => URI.escape(@callback_url))
22
+ # You'll need to store the token somewhere for when the user is returned to the callback method
23
+ # I stick mine in memcache with their session key as the cache key
24
+
25
+ @auth_url = flickr.get_authorize_url(token['oauth_token'], :perms => 'delete')
26
+ # Stick @auth_url in your template for users to click
27
+ end
28
+
29
+ # Your users browser will be redirected here from Flickr (see @callback_url above)
30
+ def callback
31
+ flickr = FlickRaw::Flickr.new
32
+
33
+ token = # Retrieve from cache or session etc - see above
34
+ oauth_token = params[:oauth_token]
35
+ oauth_verifier = params[:oauth_verifier]
36
+
37
+ raw_token = flickr.get_oauth_token(request_token['oauth_token'], request_token['oauth_token_secret'], oauth_verifier)
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
+ # Use URI.unescape on the nsid and name parameters
40
+
41
+ oauth_token = raw_token["oauth_token"]
42
+ oauth_token_secret = raw_token["oauth_token_secret"]
43
+
44
+ # Store the oauth_token and oauth_token_secret in session or database
45
+ # and attach to a Flickraw instance before calling any methods requiring authentication
46
+
47
+ # Attach the tokens to your flickr instance - you can now make authenticated calls with the flickr object
48
+ flickr.access_token = oauth_token
49
+ flickr.access_secret =[oauth_token_secret
50
+
51
+ end
52
+
@@ -5,7 +5,7 @@ require 'flickraw/response'
5
5
  require 'flickraw/api'
6
6
 
7
7
  module FlickRaw
8
- VERSION='0.9.5'
8
+ VERSION='0.9.6'
9
9
  USER_AGENT = "FlickRaw/#{VERSION}"
10
10
  end
11
11
 
@@ -19,7 +19,7 @@ module FlickRaw
19
19
  UPLOAD_PATH_SECURE=(END_POINT_SECURE + '/upload/').freeze
20
20
  REPLACE_PATH_SECURE=(END_POINT_SECURE + '/replace/').freeze
21
21
 
22
- PHOTO_SOURCE_URL='http://farm%s.static.flickr.com/%s/%s_%s%s.%s'.freeze
22
+ PHOTO_SOURCE_URL='http://farm%s.staticflickr.com/%s/%s_%s%s.%s'.freeze
23
23
  URL_PROFILE='http://www.flickr.com/people/'.freeze
24
24
  URL_PHOTOSTREAM='http://www.flickr.com/photos/'.freeze
25
25
  URL_SHORT='http://flic.kr/p/'.freeze
@@ -102,13 +102,8 @@ module FlickRaw
102
102
 
103
103
  private
104
104
  def build_args(args={}, method = nil)
105
- full_args = {'format' => 'json', 'nojsoncallback' => '1'}
106
- full_args['method'] = method if method
107
- args.each {|k, v|
108
- v = v.to_s.encode("utf-8").force_encoding("ascii-8bit") if RUBY_VERSION >= "1.9"
109
- full_args[k.to_s] = v
110
- }
111
- full_args
105
+ args['method'] = method if method
106
+ args.merge('format' => 'json', 'nojsoncallback' => '1')
112
107
  end
113
108
 
114
109
  def process_response(req, response)
@@ -176,6 +171,9 @@ module FlickRaw
176
171
  def url_t(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_t", "jpg"] end
177
172
  def url_b(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_b", "jpg"] end
178
173
  def url_z(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_z", "jpg"] end
174
+ def url_q(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_q", "jpg"] end
175
+ def url_n(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_n", "jpg"] end
176
+ def url_c(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_c", "jpg"] end
179
177
  def url_o(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.originalsecret, "_o", r.originalformat] end
180
178
  def url_profile(r); URL_PROFILE + (r.owner.respond_to?(:nsid) ? r.owner.nsid : r.owner) + "/" end
181
179
  def url_photopage(r); url_photostream(r) + r.id end
@@ -185,6 +183,8 @@ module FlickRaw
185
183
  def url_short_m(r); URL_SHORT + "img/" + base58(r.id) + "_m.jpg" end
186
184
  def url_short_s(r); URL_SHORT + "img/" + base58(r.id) + ".jpg" end
187
185
  def url_short_t(r); URL_SHORT + "img/" + base58(r.id) + "_t.jpg" end
186
+ def url_short_q(r); URL_SHORT + "img/" + base58(r.id) + "_q.jpg" end
187
+ def url_short_n(r); URL_SHORT + "img/" + base58(r.id) + "_n.jpg" end
188
188
  def url_photostream(r)
189
189
  URL_PHOTOSTREAM +
190
190
  if r.respond_to?(:pathalias) and r.pathalias
@@ -12,9 +12,14 @@ module FlickRaw
12
12
  end
13
13
 
14
14
  class << self
15
+ def encode_value(v)
16
+ v = v.to_s.encode("utf-8").force_encoding("ascii-8bit") if RUBY_VERSION >= "1.9"
17
+ v.to_s
18
+ end
19
+
15
20
  def escape(s)
16
- s.to_s.dup.gsub(/[^a-zA-Z0-9\-\.\_\~]/) {
17
- sprintf("%%%02X", $&.unpack("C")[0])
21
+ encode_value(s).gsub(/[^a-zA-Z0-9\-\.\_\~]/) {
22
+ $&.unpack("C*").map{|i| sprintf("%%%02X", i) }.join
18
23
  }
19
24
  end
20
25
 
@@ -83,7 +88,8 @@ module FlickRaw
83
88
  end
84
89
 
85
90
  def post_form(url, token_secret, oauth_params = {}, params = {})
86
- post(url, token_secret, oauth_params, params) {|request| request.form_data = params}
91
+ encoded_params = Hash[*params.map {|k,v| [OAuthClient.encode_value(k), OAuthClient.encode_value(v)]}.flatten]
92
+ post(url, token_secret, oauth_params, params) {|request| request.form_data = encoded_params}
87
93
  end
88
94
 
89
95
  def post_multipart(url, token_secret, oauth_params = {}, params = {})
@@ -97,16 +103,15 @@ module FlickRaw
97
103
  basename = File.basename(v.path).to_s if v.respond_to? :path
98
104
  basename ||= File.basename(v.base_uri).to_s if v.respond_to? :base_uri
99
105
  basename ||= "unknown"
100
- basename = basename.encode("utf-8").force_encoding("ascii-8bit") if RUBY_VERSION >= "1.9"
101
106
  request.body << "--#{boundary}\r\n" <<
102
- "Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{basename}\"\r\n" <<
107
+ "Content-Disposition: form-data; name=\"#{OAuthClient.encode_value(k)}\"; filename=\"#{OAuthClient.encode_value(basename)}\"\r\n" <<
103
108
  "Content-Transfer-Encoding: binary\r\n" <<
104
109
  "Content-Type: image/jpeg\r\n\r\n" <<
105
110
  v.read << "\r\n"
106
111
  else
107
112
  request.body << "--#{boundary}\r\n" <<
108
- "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n" <<
109
- "#{v}\r\n"
113
+ "Content-Disposition: form-data; name=\"#{OAuthClient.encode_value(k)}\"\r\n\r\n" <<
114
+ "#{OAuthClient.encode_value(v)}\r\n"
110
115
  end
111
116
  }
112
117
 
@@ -28,6 +28,7 @@ class Basic < Test::Unit::TestCase
28
28
  flickr.auth.getFrob
29
29
  flickr.auth.getFullToken
30
30
  flickr.auth.getToken
31
+ flickr.auth.oauth.checkToken
31
32
  flickr.auth.oauth.getAccessToken
32
33
  flickr.blogs.getList
33
34
  flickr.blogs.getServices
@@ -38,6 +39,7 @@ class Basic < Test::Unit::TestCase
38
39
  flickr.contacts.getList
39
40
  flickr.contacts.getListRecentlyUploaded
40
41
  flickr.contacts.getPublicList
42
+ flickr.contacts.getTaggingSuggestions
41
43
  flickr.favorites.add
42
44
  flickr.favorites.getContext
43
45
  flickr.favorites.getList
@@ -71,7 +73,9 @@ class Basic < Test::Unit::TestCase
71
73
  flickr.panda.getPhotos
72
74
  flickr.people.findByEmail
73
75
  flickr.people.findByUsername
76
+ flickr.people.getGroups
74
77
  flickr.people.getInfo
78
+ flickr.people.getLimits
75
79
  flickr.people.getPhotos
76
80
  flickr.people.getPhotosOf
77
81
  flickr.people.getPublicGroups
@@ -127,6 +131,11 @@ class Basic < Test::Unit::TestCase
127
131
  flickr.photos.setPerms
128
132
  flickr.photos.setSafetyLevel
129
133
  flickr.photos.setTags
134
+ flickr.photos.suggestions.approveSuggestion
135
+ flickr.photos.suggestions.getList
136
+ flickr.photos.suggestions.rejectSuggestion
137
+ flickr.photos.suggestions.removeSuggestion
138
+ flickr.photos.suggestions.suggestLocation
130
139
  flickr.photos.transform.rotate
131
140
  flickr.photos.upload.checkTickets
132
141
  flickr.photosets.addPhoto
@@ -173,16 +182,16 @@ class Basic < Test::Unit::TestCase
173
182
  flickr.push.unsubscribe
174
183
  flickr.reflection.getMethodInfo
175
184
  flickr.reflection.getMethods
185
+ flickr.stats.getCSVFiles
176
186
  flickr.stats.getCollectionDomains
177
187
  flickr.stats.getCollectionReferrers
178
188
  flickr.stats.getCollectionStats
179
- flickr.stats.getCSVFiles
180
189
  flickr.stats.getPhotoDomains
181
190
  flickr.stats.getPhotoReferrers
191
+ flickr.stats.getPhotoStats
182
192
  flickr.stats.getPhotosetDomains
183
193
  flickr.stats.getPhotosetReferrers
184
194
  flickr.stats.getPhotosetStats
185
- flickr.stats.getPhotoStats
186
195
  flickr.stats.getPhotostreamDomains
187
196
  flickr.stats.getPhotostreamReferrers
188
197
  flickr.stats.getPhotostreamStats
@@ -195,6 +204,7 @@ class Basic < Test::Unit::TestCase
195
204
  flickr.tags.getListUser
196
205
  flickr.tags.getListUserPopular
197
206
  flickr.tags.getListUserRaw
207
+ flickr.tags.getMostFrequentlyUsed
198
208
  flickr.tags.getRelated
199
209
  flickr.test.echo
200
210
  flickr.test.login
@@ -407,11 +417,15 @@ class Basic < Test::Unit::TestCase
407
417
  id = "3839885270"
408
418
  info = flickr.photos.getInfo(:photo_id => id)
409
419
 
410
- assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06.jpg", FlickRaw.url(info)
411
- assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_m.jpg", FlickRaw.url_m(info)
412
- assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_s.jpg", FlickRaw.url_s(info)
413
- assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_t.jpg", FlickRaw.url_t(info)
414
- assert_equal "http://farm3.static.flickr.com/2485/3839885270_6fb8b54e06_b.jpg", FlickRaw.url_b(info)
420
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06.jpg", FlickRaw.url(info)
421
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_m.jpg", FlickRaw.url_m(info)
422
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_s.jpg", FlickRaw.url_s(info)
423
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_t.jpg", FlickRaw.url_t(info)
424
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_b.jpg", FlickRaw.url_b(info)
425
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_z.jpg", FlickRaw.url_z(info)
426
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_q.jpg", FlickRaw.url_q(info)
427
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_n.jpg", FlickRaw.url_n(info)
428
+ assert_equal "http://farm3.staticflickr.com/2485/3839885270_6fb8b54e06_c.jpg", FlickRaw.url_c(info)
415
429
 
416
430
  assert_equal "http://www.flickr.com/people/41650587@N02/", FlickRaw.url_profile(info)
417
431
  assert_equal "http://www.flickr.com/photos/41650587@N02/", FlickRaw.url_photostream(info)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickraw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-04 00:00:00.000000000 Z
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: maelclerambault@yahoo.fr
@@ -22,14 +22,15 @@ files:
22
22
  - examples/search.rb
23
23
  - examples/sinatra.rb
24
24
  - examples/upload.rb
25
- - test/test_upload.rb
26
- - test/test.rb
25
+ - examples/web_oauth.rb
27
26
  - test/helper.rb
27
+ - test/test.rb
28
+ - test/test_upload.rb
28
29
  - lib/flickraw.rb
30
+ - lib/flickraw/api.rb
29
31
  - lib/flickraw/oauth.rb
30
- - lib/flickraw/response.rb
31
32
  - lib/flickraw/request.rb
32
- - lib/flickraw/api.rb
33
+ - lib/flickraw/response.rb
33
34
  - flickraw_rdoc.rb
34
35
  - LICENSE
35
36
  - README.rdoc
@@ -54,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  version: '0'
55
56
  requirements: []
56
57
  rubyforge_project:
57
- rubygems_version: 1.8.10
58
+ rubygems_version: 1.8.23
58
59
  signing_key:
59
60
  specification_version: 3
60
61
  summary: Flickr library with a syntax close to the syntax described on http://www.flickr.com/services/api