Class: Garb::DataRequest
- Inherits:
-
Object
- Object
- Garb::DataRequest
- Defined in:
- lib/garb/data_request.rb
Defined Under Namespace
Classes: ClientError
Instance Method Summary collapse
-
#initialize(session, base_url, parameters = {}) ⇒ DataRequest
constructor
A new instance of DataRequest.
- #oauth_user_request ⇒ Object
- #query_string ⇒ Object
- #send_request ⇒ Object
- #single_user_request(auth = 'GoogleLogin') ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(session, base_url, parameters = {}) ⇒ DataRequest
Returns a new instance of DataRequest.
5 6 7 8 9 |
# File 'lib/garb/data_request.rb', line 5 def initialize(session, base_url, parameters={}) @session = session @base_url = base_url @parameters = parameters end |
Instance Method Details
#oauth_user_request ⇒ Object
38 39 40 |
# File 'lib/garb/data_request.rb', line 38 def oauth_user_request @session.access_token.get("#{uri}#{query_string}", {'GData-Version' => '2'}) end |
#query_string ⇒ Object
11 12 13 14 |
# File 'lib/garb/data_request.rb', line 11 def query_string parameter_list = @parameters.map {|k,v| "#{k}=#{v}" } parameter_list.empty? ? '' : "?#{parameter_list.join('&')}" end |
#send_request ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/garb/data_request.rb', line 20 def send_request response = if @session.single_user? single_user_request(@session.auth_sub? ? 'AuthSub' : 'GoogleLogin') elsif @session.oauth_user? oauth_user_request end raise ClientError, response.body.inspect unless response.kind_of?(Net::HTTPSuccess) response end |
#single_user_request(auth = 'GoogleLogin') ⇒ Object
31 32 33 34 35 36 |
# File 'lib/garb/data_request.rb', line 31 def single_user_request(auth='GoogleLogin') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.get("#{uri.path}#{query_string}", { 'Authorization' => "#{auth} #{auth == 'GoogleLogin' ? 'auth' : 'token'}=#{@session.auth_token}", 'GData-Version' => '2' }) end |
#uri ⇒ Object
16 17 18 |
# File 'lib/garb/data_request.rb', line 16 def uri URI.parse(@base_url) end |