browse-everything 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjFkMzhlOTI5ZmE2NWViNTM1ZGE1ZGZmM2E4NGI4ZDMzMWVhMDE3Mw==
5
+ data.tar.gz: !binary |-
6
+ ZTY1NzA0OGZkMjMyZWQ3YTY2ZDYwMjg3MWQ1ZDgwNmU1NDU2N2JkMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTQ2OGI4MDAwMTczNTdjMTZmZDhkNzAwOGY0MjlhNjVmZTlkMDFiY2ZmNGZk
10
+ ZGYyYzA0Yzk3ZmVkN2ExYmMwY2FmYTIwYjY5MjFmY2E2N2QwOTI0MmM5N2Fm
11
+ YzE1YzdhOTg0ZWVjOTZjMGNmMThkYzVjODkxNmMxNjQ3MmQyYTI=
12
+ data.tar.gz: !binary |-
13
+ NGJmMDBlODBmMDA4MDY1YTI5MjY2OTdkYmViYzIyNTc5ODlkMDJlZDY3ZmEw
14
+ YjcxYjM1ZmU1YzFjNDhjMDc0NmZjNWU2ZDRkNTAzNDA4NjJlMDYzYzJlNGEz
15
+ NmU0MzE0Yzk4ZDRjODg5OGZmZTA5MmJmMzU2NWYyZmQ0YzE1YTM=
data/.travis.yml CHANGED
@@ -3,4 +3,7 @@ rvm:
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
5
  notifications:
6
- irc: "irc.freenode.org#projecthydra"
6
+ irc: "irc.freenode.org#projecthydra"
7
+ env:
8
+ global:
9
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.3.0 (2014-03-24)
2
+ - Additional response parameters
3
+ - Refresh token fixes for Box, SkyDrive, and Google Drive
4
+
1
5
  ### 0.2.0 (2013-12-03)
2
6
  - Bootstrap 2/3 cross-compatibility
3
7
 
data/README.md CHANGED
@@ -61,7 +61,7 @@ You must register your application with each cloud provider separately:
61
61
 
62
62
  ### CSS and JavaScript Modifications
63
63
 
64
- Add `@import "browse_everything` to your application.css.scss
64
+ Add `@import "browse_everything";` to your application.css.scss
65
65
 
66
66
  Add `//= require browse_everything` to your application.js
67
67
 
@@ -149,6 +149,7 @@ is a plain object with the following properties:
149
149
  | url | The URL of the selected remote file. |
150
150
  | auth_header | Any headers that need to be added to the request in order to access the remote file. |
151
151
  | expires | The expiration date/time of the specified URL. |
152
+ | file_name | The base name (filename.ext) of the selected file. |
152
153
 
153
154
  ### Examples
154
155
 
@@ -4,6 +4,8 @@ class BrowseEverythingController < ActionController::Base
4
4
  layout 'browse_everything'
5
5
  helper BrowseEverythingHelper
6
6
 
7
+ after_filter {session["#{provider_name}_token"] = provider.token unless provider.nil? }
8
+
7
9
  def index
8
10
  render :layout => !request.xhr?
9
11
  end
@@ -35,7 +35,7 @@ module BrowseEverything
35
35
  end
36
36
 
37
37
  def link_for(path)
38
- path
38
+ [path, { file_name: File.basename(path) }]
39
39
  end
40
40
 
41
41
  def authorized?
@@ -41,10 +41,10 @@ module BrowseEverything
41
41
 
42
42
  def link_for(path)
43
43
  file = box_client.file(path)
44
- file.create_shared_link
45
- link = file.shared_link
46
- extras = link.unshared_at.nil? ? {} : { expires: link.unshared_at }
47
- [link.download_url,extras]
44
+ download_url = file.download_url
45
+ auth_header = {'Authorization' => "Bearer #{@token}"}
46
+ extras = { auth_header: auth_header, expires: 1.hour.from_now, file_name:file.name }
47
+ [download_url,extras]
48
48
  end
49
49
 
50
50
  def details(f)
@@ -57,11 +57,12 @@ module BrowseEverything
57
57
 
58
58
  def authorized?
59
59
  #false
60
- @token.present?
60
+ @token.present? and @token[:token].present?
61
61
  end
62
62
 
63
63
  def connect(params,data)
64
- @token = oauth_client.get_access_token(params[:code]).token
64
+ access_token=oauth_client.get_access_token(params[:code])
65
+ @token = {token: access_token.token, refresh_token: access_token.refresh_token}
65
66
  end
66
67
 
67
68
  private
@@ -75,13 +76,45 @@ module BrowseEverything
75
76
  #todo error checking here
76
77
  end
77
78
 
79
+ def token_expired?(token)
80
+ begin
81
+ return false unless @token.present? and @token[:token].present?
82
+ new_session = RubyBox::Session.new({
83
+ client_id: config[:client_id],
84
+ client_secret: config[:client_secret],
85
+ access_token: token
86
+ })
87
+ result = new_session.get( "#{RubyBox::API_URL}/users/me" )
88
+ (result["status"] != 200)
89
+ rescue RubyBox::AuthError => e
90
+ Rails.logger.error("AuthError occured when checking token. Exception #{e.class.name} : #{e.message}. token as expired and need to refresh it")
91
+ return true
92
+ end
93
+ end
94
+
95
+ def refresh_token
96
+ refresh_token = @token[:refresh_token]
97
+ token = @token[:token]
98
+ session = RubyBox::Session.new({
99
+ client_id: config[:client_id],
100
+ client_secret: config[:client_secret],
101
+ access_token: token
102
+ })
103
+ access_token = session.refresh_token(refresh_token)
104
+ @token = {token: access_token.token, refresh_token: access_token.refresh_token}
105
+ end
106
+
78
107
  def box_client
108
+ refresh_token if token_expired?(@token[:token])
109
+ token = @token[:token]
110
+ refresh_token = @token[:refresh_token]
79
111
  session = RubyBox::Session.new({
80
112
  client_id: config[:client_id],
81
113
  client_secret: config[:client_secret],
82
- access_token: @token
114
+ access_token: token,
115
+ refresh_token: refresh_token
83
116
  })
84
- RubyBox::Client.new(session)
117
+ RubyBox::Client.new(session)
85
118
  end
86
119
 
87
120
  end
@@ -38,7 +38,7 @@ module BrowseEverything
38
38
  end
39
39
 
40
40
  def link_for(path)
41
- [client.media(path)['url'], { expires: 4.hours.from_now }]
41
+ [client.media(path)['url'], { expires: 4.hours.from_now, file_name: File.basename(path) }]
42
42
  end
43
43
 
44
44
  def details(path)
@@ -50,7 +50,7 @@ module BrowseEverything
50
50
  end
51
51
 
52
52
  def link_for(path)
53
- "file://#{File.expand_path(path)}"
53
+ ["file://#{File.expand_path(path)}", { file_name: File.basename(path) }]
54
54
  end
55
55
 
56
56
  def authorized?
@@ -61,7 +61,8 @@ module BrowseEverything
61
61
  api_result = oauth_client.execute(api_method: api_method, parameters: {fileId: id})
62
62
  download_url = JSON.parse(api_result.response.body)["downloadUrl"]
63
63
  auth_header = {'Authorization' => "Bearer #{oauth_client.authorization.access_token.to_s}"}
64
- [download_url,{ auth_header: auth_header, expires: 1.hour.from_now }]
64
+ extras = { auth_header: auth_header, expires: 1.hour.from_now, file_name:api_result.data.title }
65
+ [download_url, extras]
65
66
  end
66
67
 
67
68
  def auth_link
@@ -83,6 +84,25 @@ module BrowseEverything
83
84
 
84
85
  private
85
86
 
87
+ #As per issue http://stackoverflow.com/questions/12572723/rails-google-client-api-unable-to-exchange-a-refresh-token-for-access-token
88
+
89
+ #patch start
90
+ def token_expired?(token)
91
+ client=@client
92
+ result = client.execute( api_method: drive.files.list, parameters: {} )
93
+ (result.status != 200)
94
+ end
95
+
96
+ def exchange_refresh_token( refresh_token )
97
+ client=oauth_client
98
+ client.authorization.grant_type = 'refresh_token'
99
+ client.authorization.refresh_token = refresh_token
100
+ client.authorization.fetch_access_token!
101
+ client.authorization
102
+ client
103
+ end
104
+ #patch end
105
+
86
106
  def oauth_client
87
107
  if @client.nil?
88
108
  callback = connector_response_url(config[:url_options])
@@ -92,6 +112,9 @@ module BrowseEverything
92
112
  @client.authorization.scope = "https://www.googleapis.com/auth/drive"
93
113
  @client.authorization.redirect_uri = callback
94
114
  @client.authorization.update_token!(@token) if @token.present?
115
+ #Patch start
116
+ @client = exchange_refresh_token(@token["refresh_token"]) if @token.present? && token_expired?(@token)
117
+ #Patch end
95
118
  end
96
119
  #todo error checking here
97
120
  @client
@@ -47,7 +47,7 @@ module BrowseEverything
47
47
 
48
48
  def link_for(path)
49
49
  response = Skydrive::Client.new(rehydrate_token).get("/#{real_id(path)}/")
50
- [response.download_link, {expires: 1.hour.from_now}]
50
+ [response.download_link, {expires: 1.hour.from_now, file_name: File.basename(path)}]
51
51
  end
52
52
 
53
53
 
@@ -1,3 +1,3 @@
1
1
  module BrowseEverything
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -22,7 +22,7 @@ describe BrowseEverything::Driver::Base do
22
22
  specify { subject.details('/path/to/foo.txt').should be_nil }
23
23
  end
24
24
  context "#link_for" do
25
- specify { subject.link_for('/path/to/foo.txt').should == '/path/to/foo.txt' }
25
+ specify { subject.link_for('/path/to/foo.txt').should == ['/path/to/foo.txt', { file_name: 'foo.txt' }] }
26
26
  end
27
27
  end
28
28
 
@@ -80,6 +80,6 @@ describe BrowseEverything::Driver::FileSystem do
80
80
 
81
81
  describe "#link_for('/path/to/file')" do
82
82
  subject { provider.link_for('/path/to/file') }
83
- it { should == "file:///path/to/file" }
83
+ it { should == ["file:///path/to/file", {:file_name=>"file"}] }
84
84
  end
85
85
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browse-everything
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Carolyn Cole
@@ -13,12 +12,11 @@ authors:
13
12
  autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
- date: 2013-12-03 00:00:00.000000000 Z
15
+ date: 2014-03-24 00:00:00.000000000 Z
17
16
  dependencies:
18
17
  - !ruby/object:Gem::Dependency
19
18
  name: rails
20
19
  requirement: !ruby/object:Gem::Requirement
21
- none: false
22
20
  requirements:
23
21
  - - ! '>='
24
22
  - !ruby/object:Gem::Version
@@ -26,7 +24,6 @@ dependencies:
26
24
  type: :runtime
27
25
  prerelease: false
28
26
  version_requirements: !ruby/object:Gem::Requirement
29
- none: false
30
27
  requirements:
31
28
  - - ! '>='
32
29
  - !ruby/object:Gem::Version
@@ -34,7 +31,6 @@ dependencies:
34
31
  - !ruby/object:Gem::Dependency
35
32
  name: sass-rails
36
33
  requirement: !ruby/object:Gem::Requirement
37
- none: false
38
34
  requirements:
39
35
  - - ! '>='
40
36
  - !ruby/object:Gem::Version
@@ -42,7 +38,6 @@ dependencies:
42
38
  type: :runtime
43
39
  prerelease: false
44
40
  version_requirements: !ruby/object:Gem::Requirement
45
- none: false
46
41
  requirements:
47
42
  - - ! '>='
48
43
  - !ruby/object:Gem::Version
@@ -50,7 +45,6 @@ dependencies:
50
45
  - !ruby/object:Gem::Dependency
51
46
  name: bootstrap-sass
52
47
  requirement: !ruby/object:Gem::Requirement
53
- none: false
54
48
  requirements:
55
49
  - - ! '>='
56
50
  - !ruby/object:Gem::Version
@@ -58,7 +52,6 @@ dependencies:
58
52
  type: :runtime
59
53
  prerelease: false
60
54
  version_requirements: !ruby/object:Gem::Requirement
61
- none: false
62
55
  requirements:
63
56
  - - ! '>='
64
57
  - !ruby/object:Gem::Version
@@ -66,7 +59,6 @@ dependencies:
66
59
  - !ruby/object:Gem::Dependency
67
60
  name: font-awesome-rails
68
61
  requirement: !ruby/object:Gem::Requirement
69
- none: false
70
62
  requirements:
71
63
  - - ! '>='
72
64
  - !ruby/object:Gem::Version
@@ -74,7 +66,6 @@ dependencies:
74
66
  type: :runtime
75
67
  prerelease: false
76
68
  version_requirements: !ruby/object:Gem::Requirement
77
- none: false
78
69
  requirements:
79
70
  - - ! '>='
80
71
  - !ruby/object:Gem::Version
@@ -82,7 +73,6 @@ dependencies:
82
73
  - !ruby/object:Gem::Dependency
83
74
  name: google_drive
84
75
  requirement: !ruby/object:Gem::Requirement
85
- none: false
86
76
  requirements:
87
77
  - - ! '>='
88
78
  - !ruby/object:Gem::Version
@@ -90,7 +80,6 @@ dependencies:
90
80
  type: :runtime
91
81
  prerelease: false
92
82
  version_requirements: !ruby/object:Gem::Requirement
93
- none: false
94
83
  requirements:
95
84
  - - ! '>='
96
85
  - !ruby/object:Gem::Version
@@ -98,7 +87,6 @@ dependencies:
98
87
  - !ruby/object:Gem::Dependency
99
88
  name: dropbox-sdk
100
89
  requirement: !ruby/object:Gem::Requirement
101
- none: false
102
90
  requirements:
103
91
  - - ! '>='
104
92
  - !ruby/object:Gem::Version
@@ -106,7 +94,6 @@ dependencies:
106
94
  type: :runtime
107
95
  prerelease: false
108
96
  version_requirements: !ruby/object:Gem::Requirement
109
- none: false
110
97
  requirements:
111
98
  - - ! '>='
112
99
  - !ruby/object:Gem::Version
@@ -114,7 +101,6 @@ dependencies:
114
101
  - !ruby/object:Gem::Dependency
115
102
  name: skydrive
116
103
  requirement: !ruby/object:Gem::Requirement
117
- none: false
118
104
  requirements:
119
105
  - - ! '>='
120
106
  - !ruby/object:Gem::Version
@@ -122,7 +108,6 @@ dependencies:
122
108
  type: :runtime
123
109
  prerelease: false
124
110
  version_requirements: !ruby/object:Gem::Requirement
125
- none: false
126
111
  requirements:
127
112
  - - ! '>='
128
113
  - !ruby/object:Gem::Version
@@ -130,7 +115,6 @@ dependencies:
130
115
  - !ruby/object:Gem::Dependency
131
116
  name: ruby-box
132
117
  requirement: !ruby/object:Gem::Requirement
133
- none: false
134
118
  requirements:
135
119
  - - ! '>='
136
120
  - !ruby/object:Gem::Version
@@ -138,7 +122,6 @@ dependencies:
138
122
  type: :runtime
139
123
  prerelease: false
140
124
  version_requirements: !ruby/object:Gem::Requirement
141
- none: false
142
125
  requirements:
143
126
  - - ! '>='
144
127
  - !ruby/object:Gem::Version
@@ -146,7 +129,6 @@ dependencies:
146
129
  - !ruby/object:Gem::Dependency
147
130
  name: google-api-client
148
131
  requirement: !ruby/object:Gem::Requirement
149
- none: false
150
132
  requirements:
151
133
  - - ! '>='
152
134
  - !ruby/object:Gem::Version
@@ -154,7 +136,6 @@ dependencies:
154
136
  type: :runtime
155
137
  prerelease: false
156
138
  version_requirements: !ruby/object:Gem::Requirement
157
- none: false
158
139
  requirements:
159
140
  - - ! '>='
160
141
  - !ruby/object:Gem::Version
@@ -162,7 +143,6 @@ dependencies:
162
143
  - !ruby/object:Gem::Dependency
163
144
  name: rspec
164
145
  requirement: !ruby/object:Gem::Requirement
165
- none: false
166
146
  requirements:
167
147
  - - ! '>='
168
148
  - !ruby/object:Gem::Version
@@ -170,7 +150,6 @@ dependencies:
170
150
  type: :development
171
151
  prerelease: false
172
152
  version_requirements: !ruby/object:Gem::Requirement
173
- none: false
174
153
  requirements:
175
154
  - - ! '>='
176
155
  - !ruby/object:Gem::Version
@@ -178,7 +157,6 @@ dependencies:
178
157
  - !ruby/object:Gem::Dependency
179
158
  name: rspec-rails
180
159
  requirement: !ruby/object:Gem::Requirement
181
- none: false
182
160
  requirements:
183
161
  - - ! '>='
184
162
  - !ruby/object:Gem::Version
@@ -186,7 +164,6 @@ dependencies:
186
164
  type: :development
187
165
  prerelease: false
188
166
  version_requirements: !ruby/object:Gem::Requirement
189
- none: false
190
167
  requirements:
191
168
  - - ! '>='
192
169
  - !ruby/object:Gem::Version
@@ -194,7 +171,6 @@ dependencies:
194
171
  - !ruby/object:Gem::Dependency
195
172
  name: simplecov
196
173
  requirement: !ruby/object:Gem::Requirement
197
- none: false
198
174
  requirements:
199
175
  - - ! '>='
200
176
  - !ruby/object:Gem::Version
@@ -202,7 +178,6 @@ dependencies:
202
178
  type: :development
203
179
  prerelease: false
204
180
  version_requirements: !ruby/object:Gem::Requirement
205
- none: false
206
181
  requirements:
207
182
  - - ! '>='
208
183
  - !ruby/object:Gem::Version
@@ -210,7 +185,6 @@ dependencies:
210
185
  - !ruby/object:Gem::Dependency
211
186
  name: bundler
212
187
  requirement: !ruby/object:Gem::Requirement
213
- none: false
214
188
  requirements:
215
189
  - - ~>
216
190
  - !ruby/object:Gem::Version
@@ -218,7 +192,6 @@ dependencies:
218
192
  type: :development
219
193
  prerelease: false
220
194
  version_requirements: !ruby/object:Gem::Requirement
221
- none: false
222
195
  requirements:
223
196
  - - ~>
224
197
  - !ruby/object:Gem::Version
@@ -226,7 +199,6 @@ dependencies:
226
199
  - !ruby/object:Gem::Dependency
227
200
  name: pry
228
201
  requirement: !ruby/object:Gem::Requirement
229
- none: false
230
202
  requirements:
231
203
  - - ! '>='
232
204
  - !ruby/object:Gem::Version
@@ -234,7 +206,6 @@ dependencies:
234
206
  type: :development
235
207
  prerelease: false
236
208
  version_requirements: !ruby/object:Gem::Requirement
237
- none: false
238
209
  requirements:
239
210
  - - ! '>='
240
211
  - !ruby/object:Gem::Version
@@ -242,7 +213,6 @@ dependencies:
242
213
  - !ruby/object:Gem::Dependency
243
214
  name: rake
244
215
  requirement: !ruby/object:Gem::Requirement
245
- none: false
246
216
  requirements:
247
217
  - - ! '>='
248
218
  - !ruby/object:Gem::Version
@@ -250,7 +220,6 @@ dependencies:
250
220
  type: :development
251
221
  prerelease: false
252
222
  version_requirements: !ruby/object:Gem::Requirement
253
- none: false
254
223
  requirements:
255
224
  - - ! '>='
256
225
  - !ruby/object:Gem::Version
@@ -258,7 +227,6 @@ dependencies:
258
227
  - !ruby/object:Gem::Dependency
259
228
  name: webmock
260
229
  requirement: !ruby/object:Gem::Requirement
261
- none: false
262
230
  requirements:
263
231
  - - ! '>='
264
232
  - !ruby/object:Gem::Version
@@ -266,7 +234,6 @@ dependencies:
266
234
  type: :development
267
235
  prerelease: false
268
236
  version_requirements: !ruby/object:Gem::Requirement
269
- none: false
270
237
  requirements:
271
238
  - - ! '>='
272
239
  - !ruby/object:Gem::Version
@@ -274,7 +241,6 @@ dependencies:
274
241
  - !ruby/object:Gem::Dependency
275
242
  name: vcr
276
243
  requirement: !ruby/object:Gem::Requirement
277
- none: false
278
244
  requirements:
279
245
  - - ! '>='
280
246
  - !ruby/object:Gem::Version
@@ -282,7 +248,6 @@ dependencies:
282
248
  type: :development
283
249
  prerelease: false
284
250
  version_requirements: !ruby/object:Gem::Requirement
285
- none: false
286
251
  requirements:
287
252
  - - ! '>='
288
253
  - !ruby/object:Gem::Version
@@ -290,7 +255,6 @@ dependencies:
290
255
  - !ruby/object:Gem::Dependency
291
256
  name: sqlite3
292
257
  requirement: !ruby/object:Gem::Requirement
293
- none: false
294
258
  requirements:
295
259
  - - ! '>='
296
260
  - !ruby/object:Gem::Version
@@ -298,7 +262,6 @@ dependencies:
298
262
  type: :development
299
263
  prerelease: false
300
264
  version_requirements: !ruby/object:Gem::Requirement
301
- none: false
302
265
  requirements:
303
266
  - - ! '>='
304
267
  - !ruby/object:Gem::Version
@@ -377,33 +340,26 @@ files:
377
340
  homepage: https://github.com/projecthydra/browse-everything
378
341
  licenses:
379
342
  - Apache 2
343
+ metadata: {}
380
344
  post_install_message:
381
345
  rdoc_options: []
382
346
  require_paths:
383
347
  - lib
384
348
  required_ruby_version: !ruby/object:Gem::Requirement
385
- none: false
386
349
  requirements:
387
350
  - - ! '>='
388
351
  - !ruby/object:Gem::Version
389
352
  version: '0'
390
- segments:
391
- - 0
392
- hash: 1393661968678573604
393
353
  required_rubygems_version: !ruby/object:Gem::Requirement
394
- none: false
395
354
  requirements:
396
355
  - - ! '>='
397
356
  - !ruby/object:Gem::Version
398
357
  version: '0'
399
- segments:
400
- - 0
401
- hash: 1393661968678573604
402
358
  requirements: []
403
359
  rubyforge_project:
404
- rubygems_version: 1.8.23
360
+ rubygems_version: 2.2.2
405
361
  signing_key:
406
- specification_version: 3
362
+ specification_version: 4
407
363
  summary: AJAX/Rails engine file browser for cloud storage services
408
364
  test_files:
409
365
  - spec/fixtures/file_system/dir_1/dir_3/file_3.m4v