Class: SkydriveProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/skydrive_proxy.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SkydriveProxy

Returns a new instance of SkydriveProxy.



4
5
6
# File 'lib/skydrive_proxy.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#_call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/skydrive_proxy.rb', line 18

def _call(env)
  params = Rack::Utils.parse_query(env["QUERY_STRING"])
  api_key = ApiKey.where(access_token: params['access_token']).first
  if api_key
    user = api_key.user
    uri = "#{user.token.personal_url}_api/Web/GetFileByServerRelativeUrl('#{params['file']}')"
    [200, {"Content-Type" => "text/plain"}, [uri]]
  else
    [401, {"Content-Type" => "text/plain"}, []]
  end
end

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/skydrive_proxy.rb', line 8

def call(env)
  path = env["REQUEST_PATH"]
  if path =~ /^\/download\/.+/
    dup._call(env)
  else
    @status, @headers, @response = @app.call(env)
    [@status, @headers, self]
  end
end

#each(&block) ⇒ Object



30
31
32
# File 'lib/skydrive_proxy.rb', line 30

def each(&block)
  @response.each(&block)
end