Class: Garb::DataRequest

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

Instance Method Summary collapse

Constructor Details

#initialize(base_url, parameters = {}) ⇒ DataRequest

Returns a new instance of DataRequest.



4
5
6
7
# File 'lib/garb/data_request.rb', line 4

def initialize(base_url, parameters={})
  @base_url = base_url
  @parameters = parameters
end

Instance Method Details

#query_stringObject



9
10
11
12
# File 'lib/garb/data_request.rb', line 9

def query_string
  parameter_list = @parameters.map {|k,v| "#{k}=#{v}" }
  parameter_list.empty? ? '' : "?#{parameter_list.join('&')}"
end

#send_requestObject



18
19
20
21
22
23
24
25
# File 'lib/garb/data_request.rb', line 18

def send_request
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  response = http.get("#{uri.path}#{query_string}", 'Authorization' => "GoogleLogin auth=#{Session.auth_token}")
  raise response.body.inspect unless response.is_a?(Net::HTTPOK)
  response
end

#uriObject



14
15
16
# File 'lib/garb/data_request.rb', line 14

def uri
  URI.parse(@base_url)
end