Module: FlickRaw

Defined in:
lib/flickraw.rb

Defined Under Namespace

Classes: FailedResponse, Flickr, Request, Response, ResponseList

Constant Summary collapse

VERSION =
'0.8.5'
FLICKR_HOST =
'api.flickr.com'.freeze
REST_PATH =
'/services/rest/?'.freeze
UPLOAD_PATH =
'/services/upload/'.freeze
REPLACE_PATH =
'/services/replace/'.freeze
AUTH_PATH =
'http://flickr.com/services/auth/?'.freeze
PHOTO_SOURCE_URL =
'http://farm%s.static.flickr.com/%s/%s_%s%s.%s'.freeze
URL_PROFILE =
'http://www.flickr.com/people/'.freeze
URL_PHOTOSTREAM =
'http://www.flickr.com/photos/'.freeze
URL_SHORT =
'http://flic.kr/p/'.freeze
BASE58_ALPHABET =
"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ".freeze

Class Method Summary collapse

Class Method Details

.api_keyObject

Your flickr API key, see www.flickr.com/services/api/keys for more information



267
# File 'lib/flickraw.rb', line 267

def api_key; FlickRawOptions['api_key'] end

.api_key=(key) ⇒ Object



268
# File 'lib/flickraw.rb', line 268

def api_key=(key); FlickRawOptions['api_key'] = key end

.api_sig(hsh) ⇒ Object

Returns the signature of hsh. This is meant to be passed in the api_sig parameter.



284
285
286
# File 'lib/flickraw.rb', line 284

def api_sig(hsh)
  Digest::MD5.hexdigest(FlickRaw.shared_secret + hsh.sort{|a, b| a[0].to_s <=> b[0].to_s }.flatten.join)
end

.auth_url(args = {}) ⇒ Object

Returns the flickr auth URL.



275
276
277
278
279
280
281
# File 'lib/flickraw.rb', line 275

def auth_url(args={})
  full_args = {:api_key => api_key, :perms => 'read'}
  args.each {|k, v| full_args[k.to_sym] = v }
  full_args[:api_sig] = api_sig(full_args) if shared_secret

  AUTH_PATH + full_args.collect { |a, v| "#{a}=#{v}" }.join('&')
end

.base58(id) ⇒ Object



289
290
291
292
293
294
295
296
297
298
# File 'lib/flickraw.rb', line 289

def base58(id)
  id = id.to_i
  alphabet = BASE58_ALPHABET.split(//)
  base = alphabet.length
  begin
    id, m = id.divmod(base)
    r = alphabet[m] + (r || '')
  end while id > 0
  r
end

.shared_secretObject

The shared secret of api_key, see www.flickr.com/services/api/keys for more information



271
# File 'lib/flickraw.rb', line 271

def shared_secret; FlickRawOptions['shared_secret'] end

.shared_secret=(key) ⇒ Object



272
# File 'lib/flickraw.rb', line 272

def shared_secret=(key); FlickRawOptions['shared_secret'] = key end

.url(r) ⇒ Object



300
# File 'lib/flickraw.rb', line 300

def url(r);   PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "",   "jpg"]   end

.url_b(r) ⇒ Object



304
# File 'lib/flickraw.rb', line 304

def url_b(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_b", "jpg"] end

.url_m(r) ⇒ Object



301
# File 'lib/flickraw.rb', line 301

def url_m(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_m", "jpg"] end

.url_o(r) ⇒ Object



306
# File 'lib/flickraw.rb', line 306

def url_o(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.originalsecret, "_o", r.originalformat] end

.url_photopage(r) ⇒ Object



308
# File 'lib/flickraw.rb', line 308

def url_photopage(r); url_photostream(r) + r.id end

.url_photoset(r) ⇒ Object



310
# File 'lib/flickraw.rb', line 310

def url_photoset(r); url_photosets(r) + r.id end

.url_photosets(r) ⇒ Object



309
# File 'lib/flickraw.rb', line 309

def url_photosets(r); url_photostream(r) + "sets/" end

.url_photostream(r) ⇒ Object



315
316
317
318
319
320
321
322
323
324
# File 'lib/flickraw.rb', line 315

def url_photostream(r)
  URL_PHOTOSTREAM +
    if r.respond_to?(:pathalias) and r.pathalias
      r.pathalias
    elsif r.owner.respond_to?(:nsid)
      r.owner.nsid
    else
      r.owner
    end + "/"
end

.url_profile(r) ⇒ Object



307
# File 'lib/flickraw.rb', line 307

def url_profile(r); URL_PROFILE + (r.owner.respond_to?(:nsid) ? r.owner.nsid : r.owner) + "/" end

.url_s(r) ⇒ Object



302
# File 'lib/flickraw.rb', line 302

def url_s(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_s", "jpg"] end

.url_short(r) ⇒ Object



311
# File 'lib/flickraw.rb', line 311

def url_short(r); URL_SHORT + base58(r.id) end

.url_short_m(r) ⇒ Object



312
# File 'lib/flickraw.rb', line 312

def url_short_m(r); URL_SHORT + "img/" + base58(r.id) + "_m.jpg" end

.url_short_s(r) ⇒ Object



313
# File 'lib/flickraw.rb', line 313

def url_short_s(r); URL_SHORT + "img/" + base58(r.id) + ".jpg" end

.url_short_t(r) ⇒ Object



314
# File 'lib/flickraw.rb', line 314

def url_short_t(r); URL_SHORT + "img/" + base58(r.id) + "_t.jpg" end

.url_t(r) ⇒ Object



303
# File 'lib/flickraw.rb', line 303

def url_t(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_t", "jpg"] end

.url_z(r) ⇒ Object



305
# File 'lib/flickraw.rb', line 305

def url_z(r); PHOTO_SOURCE_URL % [r.farm, r.server, r.id, r.secret, "_z", "jpg"] end