Class: Skydrive::FilesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Skydrive::FilesController
- Defined in:
- app/controllers/skydrive/files_controller.rb
Instance Method Summary collapse
Instance Method Details
#download ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/skydrive/files_controller.rb', line 43 def download api_key = ApiKey.where(access_token: params[:token]).first if api_key user = api_key.user uri = "#{user.token.personal_url}_api/Web/GetFileByServerRelativeUrl('#{params[:file].gsub(/ /, '%20')}')/$value" = { filename: ::File.basename(params[:file]), type: MimeMagic::by_extension(params[:file].match(/\.[a-z]+$/)) } data = open(uri, { "Authorization" => "Bearer #{user.token.access_token}"}, &:read) send_data(data, ) else render status: 401 end end |
#ensure_valid_skydrive_token ⇒ Object
9 10 11 12 13 14 |
# File 'app/controllers/skydrive/files_controller.rb', line 9 def ensure_valid_skydrive_token unless current_user.valid_skydrive_token? head :unauthorized return end end |
#index ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/skydrive/files_controller.rb', line 16 def index uri = params[:uri] uri = nil if uri == 'root' || uri == 'undefined' has_parent = true unless uri.present? personal_url = current_user.token.personal_url data = skydrive_client.api_call(personal_url + "_api/web/lists/Documents/") uri = data['RootFolder']['__deferred']['uri'] has_parent = false end folder = skydrive_client.get_folder_and_files(uri) folder.parent_uri = nil unless has_parent tp = IMS::LTI::ToolProvider.new(nil, nil, current_api_key.params) tp.extend IMS::LTI::Extensions::Content::ToolProvider # Update the files with the correct homework submission url folder.files.each do |file| file.update_content_type_data( tp.accepted_file_extensions ) file_download_url = download_url(token: current_api_key.access_token, file: file.server_relative_url) file.homework_submission_url = tp.file_content_return_url(file_download_url, file.name) file. = false unless tp.content_return_url.present? end render json: folder end |