Class: Flickr::OAuthCient

Inherits:
Object
  • Object
show all
Defined in:
lib/flickrrb.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ OAuthCient

Returns a new instance of OAuthCient.



285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/flickrrb.rb', line 285

def initialize params = {}
  flickr_url = URI.parse "http://api.flickr.com/"

  consumer = OAuth::Consumer.new(params[:consumer_key], params[:consumer_secret],
                                 site:                  "http://api.flickr.com/",
                                 request_token_path:    "/services/oauth/request_token",
                                 access_token_path:     "/services/oauth/access_token",
                                 authorize_path:        "/services/oauth/authorize")

  access_keys = {oauth_token:           params[:access_token], 
                 oauth_token_secret:    params[:access_secret]}

  @access = OAuth::AccessToken.from_hash(consumer, access_keys)
end

Class Method Details

.authorizeObject

def post path, params, headers = {}

  @access.post path, params, headers
end


308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/flickrrb.rb', line 308

def self.authorize
  print "Enter consumer key: "
  consumer_key = $stdin.gets.chomp

  print "Enter consumer secret: "
  consumer_secret = $stdin.gets.chomp
  
  
  consumer = OAuth::Consumer.new(consumer_key,          consumer_secret,
                                 site:                  'http://www.flickr.com', # Note www
                                 request_token_path:    "/services/oauth/request_token",
                                 access_token_path:     "/services/oauth/access_token",
                                 authorize_path:        "/services/oauth/authorize")
  
  request_token = consumer.get_request_token
  p "\nGo to this url and click 'Authorize' to get the token:"
  p request_token.authorize_url
  print "\nEnter token: "
  token = $stdin.gets.chomp
  
  access_token  = request_token.get_access_token(:oauth_verifier => token)
  
  p "\nAuthorisation complete! Use the following params to access Flickr:\n\n"
  p "consumer_key     = '#{consumer.key}'"
  p "consumer_secret  = '#{consumer.secret}'"
  p "access_token     = '#{access_token.token}'"
  p "access_secret    = '#{access_token.secret}'"
end

Instance Method Details

#get(path) ⇒ Object



300
301
302
# File 'lib/flickrrb.rb', line 300

def get path
  @access.get path
end