Class: Boar::Providers::SkyDrive
- Defined in:
- lib/boar/providers/sky_drive.rb
Constant Summary collapse
- SCOPES =
"wl.skydrive_update,wl.offline_access"
Class Method Summary collapse
- .authorized_client(configuration, params) ⇒ Object
- .client(configuration, callback_url = nil) ⇒ Object
Instance Method Summary collapse
- #get_credentials(authorizer, request, response) ⇒ Object
- #redirect_for_authentication(authorizer, configuration) ⇒ Object
- #search_file(path, params) ⇒ Object
Methods inherited from Base
Class Method Details
.authorized_client(configuration, params) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/boar/providers/sky_drive.rb', line 56 def self.(configuration, params) # Get a new access token token = Boar::Providers::SkyDrive.client(configuration).get_access_token_from_hash(configuration[:access_token], {:refresh_token => configuration[:refresh_token]}) params[:provider].update_credentials({access_token: token.token, refresh_token: token.refresh_token}, params) # Create the client Skydrive::Client.new(token) end |
.client(configuration, callback_url = nil) ⇒ Object
52 53 54 |
# File 'lib/boar/providers/sky_drive.rb', line 52 def self.client(configuration, callback_url = nil) ::Skydrive::Oauth::Client.new(configuration[:client_id], configuration[:client_secret], callback_url, Boar::Providers::SkyDrive::SCOPES) end |
Instance Method Details
#get_credentials(authorizer, request, response) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/boar/providers/sky_drive.rb', line 19 def get_credentials(, request, response) begin raise Clavem::Exceptions::AuthorizationDenied if request.query["error"].present? || request.query["code"].blank? token = @client.get_access_token(request.query["code"]) {access_token: token.token, refresh_token: token.refresh_token} rescue RuntimeError nil end end |
#redirect_for_authentication(authorizer, configuration) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/boar/providers/sky_drive.rb', line 12 def redirect_for_authentication(, configuration) .ip = configuration[:domain] @client = Boar::Providers::SkyDrive.client(configuration, .callback_url) @client. end |
#search_file(path, params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/boar/providers/sky_drive.rb', line 29 def search_file(path, params) rv = nil # Split path Lazier.load_pathname filename = File.basename(path) tree = Pathname.new(File.dirname(path)).components # Initialize client client = Boar::Providers::SkyDrive.(params[:single], params) # Find the last folder current = client.my_skydrive tree.each do |folder| current = search_entry(current, folder, true) break if !current end # We have the container, query for the file rv = search_entry(current, filename) if current rv ? {"id" => rv.id} : nil end |