Class: DropboxExt::ItemsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DropboxExt::ItemsController
- Defined in:
- app/controllers/dropbox_ext/items_controller.rb
Instance Method Summary collapse
Instance Method Details
#dropbox ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/controllers/dropbox_ext/items_controller.rb', line 6 def dropbox if @dropbox return @dropbox end require 'dropbox' @dropbox = Dropbox::Client.new(params[:dbt]) end |
#sync ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/dropbox_ext/items_controller.rb', line 36 def sync items = params[:items] auth_params = params[:auth_params] if items && items.length > 0 payload = { "items" => items } payload["auth_params"] = auth_params if auth_params != nil folder = "/#{Time.current.year}/#{DateTime.now.strftime("%B")}" filename = "#{DateTime.now.strftime("%B %d, %Y").sub(',', '')}.txt" dropbox.upload("#{folder}/#{filename}", "#{JSON.pretty_generate(payload.as_json)}", {:mode => "overwrite"}) end self.sync_decrypt_file() render :json => {:success => true} end |
#sync_decrypt_file ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/dropbox_ext/items_controller.rb', line 15 def sync_decrypt_file begin existing = dropbox.search("", "decrypt") if existing.length > 0 file = existing[0] days_old = (Time.now - file.client_modified).to_i / (24 * 60 * 60) if days_old < 14 return end end require 'open-uri' content = open('https://raw.githubusercontent.com/standardfile/decrypt-html-page/master/decrypt.html').read dropbox.upload("/decrypt.html", content, {:mode => "overwrite"}) rescue end end |