one_drive 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb21d7ac41488e380327302fd30850a9fadceed
4
- data.tar.gz: 686bdc3a7041fd5b809a989e15192d50baaa3fa5
3
+ metadata.gz: bfde019139370bb07e616302ea584b75d42aa336
4
+ data.tar.gz: d265a39c310a3d5849ec2a9b5ae5571f4953f461
5
5
  SHA512:
6
- metadata.gz: 4e8a3e8d90a502efa0497ca92cd5506c87fbb6f7a1d2fec2b360bd3c279cb37ed8df5d186073480a41060bd0bc419ce289970391a196bca9e81882a85a075170
7
- data.tar.gz: 6a876bf4359604f1d8f778158d7afa91cf94b5fe7811578232ad3c0ffa203957295842d646557484ff720a9943f43cc71d0c0cefc795d4c825905d877be48016
6
+ metadata.gz: b4d2c291f46763c5b6420886f3898c969143dd3469c94ec15692b238082facbd979000078de1ac994c0ffd434407fda89e1b0279f1efa7aa5781c49b496dc1c3
7
+ data.tar.gz: ec1d0e9ef5d319345a158235814ec9d3972e0d1b90b13baa30ba867538c9c36769bba76f28218a5092ec41e15a13865699d716a78d227caab9fd3613e5bbf6d9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- one_drive (0.0.2)
4
+ one_drive (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # OneDrive
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/one_drive`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Welcome to your new gem one_drive!
4
+ You can use this gem to list your Microsoft OneDrive drives and read and write them.
5
+ To experiment with that code, run `bin/console` for an interactive prompt.
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,7 +23,42 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ 1. Initialize
27
+
28
+ ` @one_drive = OneDrive::V1.new(client_id, redirect_uri, scope) `
29
+
30
+ 2. Generate code url to get refresh_token
31
+
32
+ ` @one_drive.code_url `
33
+
34
+ Or Directly generate token url
35
+
36
+ ` @one_drive.token_url `
37
+
38
+ Visit the url to generate the token
39
+
40
+ 3. Set your token which you get on visiting the above url
41
+
42
+ ` @one_drive.set_token token `
43
+ Note: only token is required you can leave expires_in and token_type as blank for expires_in=3600 and token_type='bearer'
44
+
45
+ 4. List out all your drives
46
+
47
+ ` @drives = @one_drive.get_drives `
48
+
49
+ After calling the last function you can fetch last drive list which you fetched by calling
50
+
51
+ ` @one_drive.drives `
52
+ 5. Search
53
+
54
+ 6. Download Item
55
+
56
+ 7. Recent Drive
57
+
58
+ 8. Special Folder
59
+
60
+ 9. My Drive
61
+
26
62
 
27
63
  ## Development
28
64
 
@@ -1,13 +1,26 @@
1
1
  require "one_drive/version"
2
2
  require "httparty"
3
3
  module OneDrive
4
+ class OneDriveExceptions < StandardError
5
+ attr_reader :detail
6
+ def initialize(message="OneDriveExceptions", detail="")
7
+ @detail = detail
8
+ super(message)
9
+ end
10
+ end
11
+
4
12
  class V1
5
- attr_accessor :client_id,:scope,:redirect_uri,:code,:token,:drives,:items,:current_drive,:current_item,:expires_in,:token_type
13
+ attr_accessor :client_id,:scope,:redirect_uri,:code,:token,:drives,:items,:current_drive,
14
+ :current_item,:expires_in,:token_type,:my_drive,:recent_drive,:special_drive,:special_items,
15
+ :item
6
16
  def initialize(client_id,redirect_uri,scope='files.read')
7
17
  @client_id = client_id
8
18
  @scope = scope
9
19
  @redirect_uri = redirect_uri
10
20
  end
21
+ def base_api_url
22
+ "https://graph.microsoft.com/v1.0"
23
+ end
11
24
  def token_url
12
25
  # OAuth URI token
13
26
  # GET https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={client_id}&scope={scope}
@@ -27,6 +40,47 @@ module OneDrive
27
40
  # client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}
28
41
  # &refresh_token={refresh_token}&grant_type=refresh_token
29
42
  end
43
+ # Get a drive by ID
44
+ def get_drive drive_id
45
+ url = base_api_url + "/drives/#{drive_id}"
46
+ @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body)
47
+ end
48
+ # Get a user's OneDrive
49
+ def get_users_drive id_or_user_principal_name
50
+ url = base_api_url + "/users/#{id_or_user_principal_name}/drive"
51
+ @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body)
52
+ end
53
+ # Get a current user's OneDrive
54
+ def get_my_drive
55
+ url = base_api_url + "/me/drive"
56
+ @my_drive = JSON.parse(HTTParty.get(url,headers: set_headers).body)
57
+ end
58
+ # Get the document library for a site
59
+ def get_library_for_site site_id
60
+ url = base_api_url + "/sites/#{site_id}/drive"
61
+ @drives = JSON.parse(HTTParty.get(url,headers: set_headers).body)
62
+ end
63
+ # Get a special folder by name
64
+ def get_special_folder_by_name name
65
+ url = base_api_url + "/me/drive/special/#{name}"
66
+ @special_drive = JSON.parse(HTTParty.get(url,headers: set_headers).body)
67
+ end
68
+ # Get children of a special folder
69
+ def get_children_of_special_folder name
70
+ url = base_api_url + "/me/drive/special/#{name}/children"
71
+ @special_items = JSON.parse(HTTParty.get(url,headers: set_headers).body)
72
+ end
73
+ # List items shared with the signed-in user
74
+ def items_shared_with_me
75
+ url = base_api_url + "/me/drive/sharedWithMe"
76
+ @shared_items = JSON.parse(HTTParty.get(url,headers: set_headers).body)
77
+ end
78
+ # GET /drives/{remoteItem-driveId}/items/{remoteItem-id}
79
+
80
+ def recent
81
+ url = base_api_url + '/me/drive/recent'
82
+ @recent_drive = JSON.parse(HTTParty.get(url,headers: set_headers).body)
83
+ end
30
84
  def get_drives type = nil,id=nil
31
85
  # GET /me/drives
32
86
  # GET /users/{userId}/drives
@@ -54,7 +108,8 @@ module OneDrive
54
108
  def set_code code
55
109
  @code = code
56
110
  end
57
- def get_item
111
+ def get_item options={}
112
+ url = "https://graph.microsoft.com/v1.0"
58
113
  # Get item
59
114
  # GET /drives/{drive-id}/items/{item-id}
60
115
  # GET /drives/{drive-id}/root:/{item-path}
@@ -66,8 +121,46 @@ module OneDrive
66
121
  # GET /sites/{siteId}/drive/root:/{item-path}
67
122
  # GET /users/{userId}/drive/items/{itemId}
68
123
  # GET /users/{userId}/drive/root:/{item-path}
124
+ if options.include? :drive_id
125
+ url = "/drives/#{options[:drive_id]}/"
126
+ elsif options.include? :group_id
127
+ url = "/groups/#{options[:group_id]}/"
128
+ elsif options.include? :site_id
129
+ url = "/sites/#{options[:site_id]}/"
130
+ elsif options.include? :user_id
131
+ url = "/users/#{options[:user_id]}/"
132
+ else
133
+ url = "/me/drive/"
134
+ end
135
+ if options.include? :item_id
136
+ url = url + "items/#{options[:item_id]}"
137
+ elsif options.include? :item_path
138
+ url = url + "root:/#{options[:item_path]}"
139
+ else
140
+ return "OneDrive URL is not valid"
141
+ end
142
+ @items = JSON.parse(HTTParty.get(url,headers: set_headers).body)
143
+ end
144
+ def search options ={}
145
+ if options.include? :drive_id
146
+ # GET /drives/{drive-id}/root/search(q='{search-text}')
147
+ url = base_api_url + "/drives/#{options[:drive_id]}/root/search(q='#{options[:search_text]}')"
148
+ elsif options.include? :group_id
149
+ # GET /groups/{group-id}/drive/root/search(q='{search-text}')
150
+ url = base_api_url + "/groups/#{options[:group_id]}/drive/root/search(q='#{options[:search_text]}')"
151
+ elsif options.include? :site_id
152
+ # GET /sites/{site-id}/drive/root/search(q='{search-text}')
153
+ url = base_api_url + "/sites/#{options[:site_id]}/drive/root/search(q='#{options[:search_text]}')"
154
+ elsif options.include? :user_id
155
+ # GET /users/{user-id}/drive/root/search(q='{search-text}')
156
+ url = base_api_url + "/users/#{options[:user_id]}/drive/root/search(q='#{options[:search_text]}')"
157
+ else
158
+ # GET /me/drive/root/search(q='{search-text}')
159
+ url = base_api_url + "/me/drive/root/search(q='#{options[:search_text]}')"
160
+ end
161
+ @items = JSON.parse(HTTParty.get(url,headers: set_headers).body)
69
162
  end
70
- def download
163
+ def download options ={}
71
164
  # Download
72
165
  # GET /drives/{drive-id}/items/{item-id}/content
73
166
  # GET /groups/{group-id}/drive/items/{item-id}/content
@@ -77,17 +170,61 @@ module OneDrive
77
170
  # GET /users/{userId}/drive/items/{item-id}/content
78
171
  # GET /drive/items/{item-id}/content?format={format}
79
172
  # GET /drive/root:/{path and filename}:/content?format={format}
173
+ url = "https://graph.microsoft.com/v1.0"
174
+ if options.include? :drive_id
175
+ url = url + "/drives/#{options[:drive_id]}/"
176
+ elsif options.include? :group_id
177
+ url = url + "/groups/#{options[:group_id]}/drive/"
178
+ elsif options.include? :site_id
179
+ url = url + "/sites/#{options[:site_id]}/drive/"
180
+ elsif options.include? :user_id
181
+ url = url + "/users/#{options[:user_id]}/drive/"
182
+ else
183
+ url = url + "/me/drive/"
184
+ end
185
+ if options.include? :item_id
186
+ url = url + "items/#{options[:item_id]}/content"
187
+ elsif options.include? :item_path
188
+ url = url + "root:/#{options[:item_path]}:/content"
189
+ else
190
+ return "OneDrive URL : Item id is not valid"
191
+ end
192
+ if options.include? :format
193
+ url = url + "?format=#{options[:format]}"
194
+ end
195
+ @item = (HTTParty.get(url,headers: set_headers).body)
80
196
  end
81
- def get_list
197
+ def get_list options={}
198
+ url = "https://graph.microsoft.com/v1.0"
199
+ p '------------------------'
82
200
  # Find Children
83
201
  # GET /drives/{drive-id}/items/{item-id}/children
84
202
  # GET /groups/{group-id}/drive/items/{item-id}/children
85
203
  # GET /me/drive/items/{item-id}/children
86
204
  # GET /sites/{site-id}/drive/items/{item-id}/children
87
205
  # GET /users/{user-id}/drive/items/{item-id}/children
206
+ if options.include? :drive_id
207
+ url = url + "/drives/#{options[:drive_id]}/"
208
+ elsif options.include? :group_id
209
+ url = url + "/groups/#{options[:group_id]}/"
210
+ elsif options.include? :site_id
211
+ url = url + "/sites/#{options[:site_id]}/"
212
+ elsif options.include? :user_id
213
+ url = url + "/users/#{options[:user_id]}/"
214
+ else
215
+ url = url + "/me/drive/"
216
+ end
217
+ if options.include? :item_id
218
+ url = url + "items/#{options[:item_id]}/children"
219
+ else
220
+ return "OneDrive URL : Item id is not valid"
221
+ end
222
+ p url
223
+ @items = JSON.parse(HTTParty.get(url,headers: set_headers).body)
88
224
  end
89
225
  def set_headers
90
226
  {"Content-Type"=> 'application/json',"Authorization"=>"bearer #{@token}"}
91
227
  end
228
+
92
229
  end
93
230
  end
@@ -1,3 +1,3 @@
1
1
  module OneDrive
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-17 00:00:00.000000000 Z
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler