Rb1drv

Build Status

Rb1drv is a Ruby SDK for Microsoft OneDrive service, providing a simple interface to access files inside OneDrive.

Rb1drv allows you to list directories, upload or download files, etc.

To use the command line application, install rb1drv-tools gem instead.

Further functionalities can be added to the library upon requests.

Rb1drv uses the latest Microsoft OAuth2 + Graph API at the time it is written, while there are not many other libraries available for reference (e.g. official OneDrive SDK still uses old OAuth2 API instead of new OAuth2 v2.0 API). Feel free to take this as an unoffical reference implementation and write your own SDK.

Installation

Add this line to your application's Gemfile:

gem 'rb1drv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rb1drv

Usage

You will have to register a new application on Microsoft Application Registration Portal before using the API. Read more at OneDrive API Docs.

od = OneDrive.new('a2b3c4d5-your-app-id', 'C8V3{your-app-secret(', 'https://your-callback/url')

To start using OneDrive library, instanciate the class with your application information.


od.root
od.get('/Folder1')
od.get('/File1.avi')

Use OneDrive#root or OneDrive#get to get a drive item.


od.root.children
od.root.children.grep(OneDriveDir)

Use OneDriveDir#children to get contents of a directory.


od.get('/File1.avi').save_as('/tmp/test.avi', overwrite: true) do |event, stat|
  puts "Downloaded #{stat[:progress]} of #{stat[:total]}" if event == :progress
end

Use OneDriveFile#save_as to download a file.


od.get('/Folder1').upload('/tmp/test.avi', overwrite: true, target_name: 'party.avi') do |event, stat|
  puts "Uploading #{stat[:progress]} of #{stat[:total]} for segment #{stat[:from]}-#{stat[:to]}" if event == :progress
  puts "Uploaded segment #{stat[:from]}-#{stat[:to]}" if event == :finish_segment
end

Use OneDriveDir#upload to upload a file to target directory.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/msg7086/rb1drv.

License

The gem is available as open source under the terms of the MIT License.