Class: Garb::DataRequest
- Inherits:
-
Object
- Object
- Garb::DataRequest
- Defined in:
- lib/garb/data_request.rb
Defined Under Namespace
Classes: ClientError
Instance Method Summary collapse
- #authsub_user_request ⇒ Object
-
#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 ⇒ 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
#authsub_user_request ⇒ Object
44 45 46 47 48 49 |
# File 'lib/garb/data_request.rb', line 44 def authsub_user_request 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' => "AuthSub token=#{@session.authsub_token}") end |
#oauth_user_request ⇒ Object
40 41 42 |
# File 'lib/garb/data_request.rb', line 40 def oauth_user_request @session.access_token.get("#{uri}#{query_string}") 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 30 31 |
# File 'lib/garb/data_request.rb', line 20 def send_request response = if @session.single_user? single_user_request elsif @session.oauth_user? oauth_user_request elsif @session.authsub_user? authsub_user_request end raise ClientError, response.body.inspect unless response.kind_of?(Net::HTTPSuccess) response end |
#single_user_request ⇒ Object
33 34 35 36 37 38 |
# File 'lib/garb/data_request.rb', line 33 def single_user_request 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' => "GoogleLogin auth=#{@session.auth_token}") end |
#uri ⇒ Object
16 17 18 |
# File 'lib/garb/data_request.rb', line 16 def uri URI.parse(@base_url) end |