-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting passing OAuth2 access_token string directly in GoogleDrive…
….login_with_oauth. #12
- Loading branch information
Showing
5 changed files
with
84 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Author: Hiroshi Ichikawa <http://gimite.net/> | ||
# The license of this source is "New BSD Licence" | ||
|
||
require "net/https" | ||
require "uri" | ||
Net::HTTP.version_1_2 | ||
|
||
|
||
module GoogleDrive | ||
|
||
class BasicFetcher #:nodoc: | ||
|
||
def initialize(proxy) | ||
if proxy | ||
@proxy = proxy | ||
elsif ENV["http_proxy"] && !ENV["http_proxy"].empty? | ||
proxy_url = URI.parse(ENV["http_proxy"]) | ||
@proxy = Net::HTTP.Proxy(proxy_url.host, proxy_url.port) | ||
else | ||
@proxy = Net::HTTP | ||
end | ||
end | ||
|
||
def request_raw(method, url, data, extra_header, auth) | ||
uri = URI.parse(url) | ||
http = @proxy.new(uri.host, uri.port) | ||
http.use_ssl = true | ||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
http.start() do | ||
path = uri.path + (uri.query ? "?#{uri.query}" : "") | ||
header = auth_header(auth).merge(extra_header) | ||
if method == :delete || method == :get | ||
return http.__send__(method, path, header) | ||
else | ||
return http.__send__(method, path, data, header) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def auth_header(auth) | ||
return {} | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,24 @@ | ||
# Author: Hiroshi Ichikawa <http://gimite.net/> | ||
# The license of this source is "New BSD Licence" | ||
|
||
require "rubygems" | ||
require "oauth2" | ||
require "google_drive/basic_fetcher" | ||
|
||
|
||
module GoogleDrive | ||
|
||
class OAuth2Fetcher #:nodoc: | ||
class OAuth2Fetcher < BasicFetcher #:nodoc: | ||
|
||
class Response | ||
|
||
def initialize(raw_res) | ||
@raw_res = raw_res | ||
end | ||
|
||
def code | ||
return @raw_res.status.to_s() | ||
end | ||
|
||
def body | ||
return @raw_res.body | ||
end | ||
|
||
def [](name) | ||
return @raw_res.headers[name] | ||
end | ||
|
||
def initialize(auth_token, proxy) | ||
super(proxy) | ||
@auth_token = auth_token | ||
end | ||
|
||
def initialize(oauth2_token) | ||
@oauth2_token = oauth2_token | ||
end | ||
|
||
def request_raw(method, url, data, extra_header, auth) | ||
if method == :delete || method == :get | ||
raw_res = @oauth2_token.request(method, url, {:headers => extra_header}) | ||
else | ||
raw_res = @oauth2_token.request(method, url, {:headers => extra_header, :body => data}) | ||
end | ||
return Response.new(raw_res) | ||
private | ||
|
||
def auth_header(auth) | ||
return {"Authorization" => "Bearer %s" % @auth_token} | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters