onedrive_for_business 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/bin/console +7 -0
- data/bin/setup +5 -0
- data/lib/onedrive_for_business/drive.rb +62 -0
- data/lib/onedrive_for_business/file.rb +9 -0
- data/lib/onedrive_for_business/folder.rb +64 -0
- data/lib/onedrive_for_business/identity.rb +11 -0
- data/lib/onedrive_for_business/identity_set.rb +11 -0
- data/lib/onedrive_for_business/image_facet.rb +9 -0
- data/lib/onedrive_for_business/item.rb +25 -0
- data/lib/onedrive_for_business/item_reference.rb +13 -0
- data/lib/onedrive_for_business/util.rb +12 -0
- data/lib/onedrive_for_business/version.rb +3 -0
- data/lib/onedrive_for_business.rb +7 -0
- data/onedrive_for_business.gemspec +24 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42b3102308f53a67bc856d692a0c99bbcf059098
|
4
|
+
data.tar.gz: be0cf8a6e58b85982332592919f2d2efa40892fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f957149c445cdba1772cef65a05723f736833368b116818c101230e45da9916596f1c2f152a26b74b8d5c8c79e7a54154b520e83c0a8ed92fba9a858f2db2393
|
7
|
+
data.tar.gz: 988f29a7a3f267fe35daa162495b18782d2cc1f2528101dac405a9b3a72c8b9aed1743defc136b7270d017534c8a16a59b39d0824f26b67efca3d43740b5fb10
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# OneDriveForBusiness
|
2
|
+
|
3
|
+
A wrapper library around the [Office 365 Files Api](https://msdn.microsoft.com/en-us/office/office365/api/files-rest-operations).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'onedrive_for_business'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install onedrive_for_business
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
29
|
+
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aj-michael/onedrive_for_business.
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
[MIT](http://ajmichael.mit-license.org/)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative './util'
|
2
|
+
|
3
|
+
module OneDriveForBusiness
|
4
|
+
class Drive
|
5
|
+
include Util
|
6
|
+
|
7
|
+
# @return Drive
|
8
|
+
def initialize(tenant, access_token)
|
9
|
+
@url = "https://#{tenant}-my.sharepoint.com/_api/v1.0/me/drive"
|
10
|
+
@access_token = access_token
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :access_token
|
14
|
+
attr_reader :url
|
15
|
+
|
16
|
+
# @return String
|
17
|
+
def id
|
18
|
+
fetch_properties! unless @id
|
19
|
+
@id
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return Identity
|
23
|
+
def owner
|
24
|
+
fetch_properties! unless @owner
|
25
|
+
@owner
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return Drive::Quota
|
29
|
+
def quota
|
30
|
+
fetch_properties! unless @quota
|
31
|
+
@quota
|
32
|
+
end
|
33
|
+
|
34
|
+
class Quota
|
35
|
+
def initialize(fields)
|
36
|
+
@deleted = fields['deleted']
|
37
|
+
@remaining = fields['remaining']
|
38
|
+
@state = fields['state']
|
39
|
+
@total = fields['total']
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :deleted
|
43
|
+
attr_reader :remaining
|
44
|
+
attr_reader :state
|
45
|
+
attr_reader :total
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def fetch_properties!
|
51
|
+
resp = http(url).get(url, 'authorization' => "Bearer #{@access_token}")
|
52
|
+
if resp.code.to_i != 200
|
53
|
+
# TODO(aj-michael) Add better error.
|
54
|
+
fail "Unauthorized request: #{resp.body}."
|
55
|
+
end
|
56
|
+
resp_hash = JSON.parse(resp.body)
|
57
|
+
@id = resp_hash['id']
|
58
|
+
@quota = Drive::Quota.new(resp_hash['quota'])
|
59
|
+
@owner = Identity.new(resp_hash['owner'])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative './item'
|
2
|
+
require_relative './util'
|
3
|
+
|
4
|
+
module OneDriveForBusiness
|
5
|
+
class Folder < Item
|
6
|
+
include Util
|
7
|
+
|
8
|
+
class << self
|
9
|
+
include Util
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return Folder
|
13
|
+
def self.create_with_parent_id!(drive, parent_id, name)
|
14
|
+
url = "#{drive.url}/files/#{parent_id}/children/#{name}"
|
15
|
+
resp =
|
16
|
+
http(url).put(url, nil, 'authorization' => "Bearer #{drive.access_token}")
|
17
|
+
Folder.new(drive, JSON.parse(resp.body))
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return Folder
|
21
|
+
def self.create_with_path!(drive, path)
|
22
|
+
url = "#{drive.url}/files/getbypath('#{path}')"
|
23
|
+
resp = http(url).put(
|
24
|
+
url, nil, 'authorization' => "Bearer #{drive.access_token}")
|
25
|
+
Folder.new(drive, JSON.parse(resp.body))
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return Folder
|
29
|
+
def self.get_by_id(drive, id)
|
30
|
+
url = "#{drive.url}/files/#{id}"
|
31
|
+
resp = http(url).get(
|
32
|
+
url, 'authorization' => "Bearer #{drive.access_token}")
|
33
|
+
Folder.new(drive, JSON.parse(resp.body))
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return Folder
|
37
|
+
def self.get_by_path(drive, path)
|
38
|
+
url = "#{drive.url}/files/getbypath('#{path}')"
|
39
|
+
resp = http(url).get(
|
40
|
+
url, 'authorization' => "Bearer #{drive.access_token}")
|
41
|
+
Folder.new(drive, JSON.parse(resp.body))
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(drive, fields)
|
45
|
+
@child_count = fields['childCount']
|
46
|
+
@children = fields['children']
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_reader :child_count # FixNum
|
51
|
+
attr_reader :children # Array[Item]
|
52
|
+
|
53
|
+
def contents
|
54
|
+
@contents ||= contents!
|
55
|
+
end
|
56
|
+
|
57
|
+
def contents!
|
58
|
+
url = "#{drive.url}/Files/#{id}/children"
|
59
|
+
resp = http(url).get(
|
60
|
+
url, 'authorization' => "Bearer #{drive.access_token}")
|
61
|
+
File.new(drive, JSON.parse(resp.body))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module OneDriveForBusiness
|
2
|
+
class IdentitySet
|
3
|
+
def initialize(fields)
|
4
|
+
@application = Identity.new(fields['application']) if fields['application']
|
5
|
+
@user = Identity.new(fields['user']) if fields['user']
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :application # OneDriveForBusiness::Identity
|
9
|
+
attr_reader :user # OneDriveForBusiness::Identity
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OneDriveForBusiness
|
2
|
+
class Item
|
3
|
+
def initialize(drive, fields)
|
4
|
+
@drive = drive
|
5
|
+
@id = fields['id']
|
6
|
+
@name = fields['name']
|
7
|
+
@e_tag = fields['eTag']
|
8
|
+
@created_by = IdentitySet.new(fields['createdBy']) if fields.include? 'createdBy'
|
9
|
+
@last_modified_by = IdentitySet.new(fields['lastModifiedBy']) if fields.include? 'lastModifiedBy'
|
10
|
+
@date_time_created = fields['dateTimeCreated']
|
11
|
+
@date_time_last_modified = fields['dateTimeLastModified']
|
12
|
+
@size = fields['size']
|
13
|
+
@parent_reference = ItemReference.new(fields['parentReference']) if fields.include? 'parentReference'
|
14
|
+
@web_url = fields['webUrl']
|
15
|
+
@type = fields['type']
|
16
|
+
end
|
17
|
+
|
18
|
+
FIELDS = [:id, :name, :e_tag, :created_by, :last_modified_by,
|
19
|
+
:date_time_created, :date_time_last_modified,
|
20
|
+
:size, :parent_reference, :web_url, :type]
|
21
|
+
FIELDS.each { |f| attr_reader f }
|
22
|
+
|
23
|
+
attr_reader :drive
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module OneDriveForBusiness
|
2
|
+
class ItemReference
|
3
|
+
def initialize(fields)
|
4
|
+
@drive_id = fields['driveId']
|
5
|
+
@id = fields['id']
|
6
|
+
@path = fields['path']
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :drive_id # String
|
10
|
+
attr_reader :id # String
|
11
|
+
attr_reader :path # String
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'onedrive_for_business/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "onedrive_for_business"
|
8
|
+
spec.version = OneDriveForBusiness::VERSION
|
9
|
+
spec.authors = ["Adam Michael"]
|
10
|
+
spec.email = ["adam@ajmichael.net"]
|
11
|
+
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.summary = %q{Access your OneDrive for Business storage.}
|
15
|
+
spec.homepage = "https://github.com/aj-michael/onedrive_for_business"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onedrive_for_business
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Michael
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- adam@ajmichael.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/onedrive_for_business.rb
|
56
|
+
- lib/onedrive_for_business/drive.rb
|
57
|
+
- lib/onedrive_for_business/file.rb
|
58
|
+
- lib/onedrive_for_business/folder.rb
|
59
|
+
- lib/onedrive_for_business/identity.rb
|
60
|
+
- lib/onedrive_for_business/identity_set.rb
|
61
|
+
- lib/onedrive_for_business/image_facet.rb
|
62
|
+
- lib/onedrive_for_business/item.rb
|
63
|
+
- lib/onedrive_for_business/item_reference.rb
|
64
|
+
- lib/onedrive_for_business/util.rb
|
65
|
+
- lib/onedrive_for_business/version.rb
|
66
|
+
- onedrive_for_business.gemspec
|
67
|
+
homepage: https://github.com/aj-michael/onedrive_for_business
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.4.8
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Access your OneDrive for Business storage.
|
91
|
+
test_files: []
|