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.
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 |
Instance Method Details
#access_secret ⇒ Object
35 36 37 |
# File 'lib/flickr_sync/cli.rb', line 35 def access_secret preferences[:access_secret] end |
#access_token ⇒ Object
31 32 33 |
# File 'lib/flickr_sync/cli.rb', line 31 def access_token preferences[:access_token] end |
#api_key ⇒ Object
13 14 15 |
# File 'lib/flickr_sync/cli.rb', line 13 def api_key preferences[:api_key] ||= prompt.answer 'What is your Flickr API key' end |
#execute ⇒ Object
39 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 |
# File 'lib/flickr_sync/cli.rb', line 39 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
21 22 23 |
# File 'lib/flickr_sync/cli.rb', line 21 def has_authenticated? preferences[:access_token] end |
#shared_secret ⇒ Object
17 18 19 |
# File 'lib/flickr_sync/cli.rb', line 17 def shared_secret preferences[:shared_secret] ||= prompt.answer 'What is your Flickr Shared Secret' end |
#store_authentication(token) ⇒ Object
25 26 27 28 29 |
# File 'lib/flickr_sync/cli.rb', line 25 def store_authentication token preferences[:username] = token['username'] preferences[:access_token] = token['oauth_token'] preferences[:access_secret] = token['oauth_token_secret'] end |