lib/flickr_airlift.rb in flickr_airlift-0.0.4 vs lib/flickr_airlift.rb in flickr_airlift-0.0.5

- old
+ new

@@ -4,35 +4,12 @@ module FlickrAirlift def self.download begin - # Setup - FlickRaw.api_key = "d4d152785af1b0ea68a5a2d173c75707" - FlickRaw.shared_secret = "b9da0b4f99507dd0" - frob = flickr.auth.getFrob - auth_url = FlickRaw.auth_url :frob => frob, :perms => 'read' + establish_session - puts " " - if system("which open") - puts "opening your browser..." - sleep 1 - puts "Come back and press Enter when you are finished" - sleep 2 - system("open '#{auth_url}'") - else - puts "Open this url in your process to complete the authication process:" - puts auth_url - puts "Press Enter when you are finished." - end - STDIN.getc - - # Authentication - auth = flickr.auth.getToken :frob => frob - login = flickr.test.login - puts "You are now authenticated as #{login.username} with token #{auth.token}" - # Prompt puts "Exactly who's photos would you like to archive?:" scraped_user = STDIN.gets scraped_user = scraped_user.strip @@ -63,8 +40,47 @@ end rescue FlickRaw::FailedResponse => e puts e.msg end + end + + def self.upload(relative_url) + establish_session("write") + image_file_names = Dir.entries(".").find_all{ |file_name| file_name.include?(".jpg") || file_name.include?(".jpeg") || file_name.include?(".gif") || file_name.include?(".png") } + + puts "Uploading #{image_file_names.length} files:" + sleep 1 + image_file_names.each_with_index do |file_name, index| + puts " Uploading (#{index+1} of #{image_file_names.length}): #{file_name}" + flickr.upload_photo File.join(relative_url, file_name), :title => file_name.split(".").first + end + # TODO: Go to page + end + + def self.establish_session(permission = "read") + FlickRaw.api_key = "d4d152785af1b0ea68a5a2d173c75707" + FlickRaw.shared_secret = "b9da0b4f99507dd0" + frob = flickr.auth.getFrob + auth_url = FlickRaw.auth_url :frob => frob, :perms => permission + + puts " " + if system("which open") + puts "opening your browser..." + sleep 1 + puts "Come back and press Enter when you are finished" + sleep 2 + system("open '#{auth_url}'") + else + puts "Open this url in your process to complete the authication process:" + puts auth_url + puts "Press Enter when you are finished." + end + STDIN.getc + + # Authentication + auth = flickr.auth.getToken :frob => frob + login = flickr.test.login + puts "You are now authenticated as #{login.username} with token #{auth.token}" end end \ No newline at end of file