Class: FlickrSync::Cli
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- FlickrSync::Cli
- Defined in:
- lib/flickr_sync/cli.rb
Instance Attribute Summary collapse
-
#preferences ⇒ Object
readonly
Returns the value of attribute preferences.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Instance Method Summary collapse
- #access_secret ⇒ Object
- #access_token ⇒ Object
- #api_key ⇒ Object
- #execute ⇒ Object
- #has_authenticated? ⇒ Boolean
- #shared_secret ⇒ Object
- #store_authentication(token) ⇒ Object
Instance Attribute Details
#preferences ⇒ Object (readonly)
Returns the value of attribute preferences.
8 9 10 |
# File 'lib/flickr_sync/cli.rb', line 8 def preferences @preferences end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
9 10 11 |
# File 'lib/flickr_sync/cli.rb', line 9 def prompt @prompt end |
Instance Method Details
#access_secret ⇒ Object
36 37 38 |
# File 'lib/flickr_sync/cli.rb', line 36 def access_secret preferences[:access_secret] end |
#access_token ⇒ Object
32 33 34 |
# File 'lib/flickr_sync/cli.rb', line 32 def access_token preferences[:access_token] end |
#api_key ⇒ Object
14 15 16 |
# File 'lib/flickr_sync/cli.rb', line 14 def api_key preferences[:api_key] ||= prompt.answer 'What is your Flickr API key' end |
#execute ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/flickr_sync/cli.rb', line 40 def execute @preferences = FlickrSync::Preferences.new @prompt = FlickrSync::Prompt.new STDIN, STDOUT FlickRaw.api_key = api_key FlickRaw.shared_secret = shared_secret unless has_authenticated? token = flickr.get_request_token auth_url = flickr.(token['oauth_token'], :perms => 'delete') auth_url.to_launcher verify = prompt.answer 'What was the number' store_authentication flickr.get_access_token token['oauth_token'], token['oauth_token_secret'], verify end flickr.access_token = access_token flickr.access_secret = access_secret flickr.test.login written_path = File.join directory_path, 'written.txt' duplicates_path = File.join directory_path, 'duplicates.txt' allfiles = `find "#{directory_path}"`.split("\n").select {|p| ['.jpg', '.gif', '.m4v'].include? File.extname(p).downcase} puts "Found #{allfiles.count} image files" writtenfiles = load_list written_path puts "Found #{writtenfiles.count} previously sent files" newfiles = allfiles - writtenfiles puts "Found #{newfiles.count} files to send" newfiles.each_with_index do |file, index| path = Pathname.new file puts "#{path} (#{index+1}/#{newfiles.count})" skip_upload = false # unless optimistic? # results = Fleakr.search :user_id => user.id, :text => path.basename.to_s.split('.').first # unless results.empty? # ids = results.map {|r| r.id }.join ',' # puts "Found #{results.size} results on flickr: #{ids}" # results.each {|r| r.small.url.to_launcher } # file.to_launcher # if prompt.ask('Had the photo already been uploaded', true) # skip_upload = true # if results.size > 1 # File.open(duplicates_path, 'a') {|f| f.puts "#{file},#{ids}"} if prompt.ask('Are these all duplicates', true) # end # end # end # end if skip_upload puts 'skipping upload' else puts 'uploading photo' flickr.upload_photo file, is_public: 0, is_family: 1, hidden: 2 end File.open(written_path, 'a') {|f| f.puts file } end end |
#has_authenticated? ⇒ Boolean
22 23 24 |
# File 'lib/flickr_sync/cli.rb', line 22 def has_authenticated? preferences[:access_token] end |
#shared_secret ⇒ Object
18 19 20 |
# File 'lib/flickr_sync/cli.rb', line 18 def shared_secret preferences[:shared_secret] ||= prompt.answer 'What is your Flickr Shared Secret' end |
#store_authentication(token) ⇒ Object
26 27 28 29 30 |
# File 'lib/flickr_sync/cli.rb', line 26 def store_authentication token preferences[:username] = token['username'] preferences[:access_token] = token['oauth_token'] preferences[:access_secret] = token['oauth_token_secret'] end |