Class: FlickrSync::Cli
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- FlickrSync::Cli
- Defined in:
- lib/flickr_sync/cli.rb
Constant Summary collapse
- IMAGES_ONLY =
%w{.jpg .gif .m4v}
- IMAGES_AND_VIDEO =
IMAGES_ONLY + %w{.mp4 .mov}
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.
11 12 13 |
# File 'lib/flickr_sync/cli.rb', line 11 def preferences @preferences end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
12 13 14 |
# File 'lib/flickr_sync/cli.rb', line 12 def prompt @prompt end |
Instance Method Details
#access_secret ⇒ Object
40 41 42 |
# File 'lib/flickr_sync/cli.rb', line 40 def access_secret preferences[:access_secret] end |
#access_token ⇒ Object
36 37 38 |
# File 'lib/flickr_sync/cli.rb', line 36 def access_token preferences[:access_token] end |
#api_key ⇒ Object
18 19 20 |
# File 'lib/flickr_sync/cli.rb', line 18 def api_key preferences[:api_key] ||= prompt.answer 'What is your Flickr API key' end |
#execute ⇒ Object
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 98 99 100 101 102 103 |
# File 'lib/flickr_sync/cli.rb', line 44 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' file_extensions = video? ? IMAGES_AND_VIDEO : IMAGES_ONLY allfiles = `find "#{directory_path}"`.split("\n").select {|p| file_extensions.include? File.extname(p).downcase} puts "Found #{allfiles.count} #{video? ? 'image/video' : '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
26 27 28 |
# File 'lib/flickr_sync/cli.rb', line 26 def has_authenticated? preferences[:access_token] end |
#shared_secret ⇒ Object
22 23 24 |
# File 'lib/flickr_sync/cli.rb', line 22 def shared_secret preferences[:shared_secret] ||= prompt.answer 'What is your Flickr Shared Secret' end |
#store_authentication(token) ⇒ Object
30 31 32 33 34 |
# File 'lib/flickr_sync/cli.rb', line 30 def store_authentication token preferences[:username] = token['username'] preferences[:access_token] = token['oauth_token'] preferences[:access_secret] = token['oauth_token_secret'] end |