Sha256: 3a784e435658cf52022d3b935791093c9e240b61b3a4e684858bc883abb3e726

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 Bytes

Contents

module Garb
  class DataRequest
    class HTTPRequestError < StandardError;end

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

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

    def uri
      URI.parse(@base_url)
    end

    def send_request(email=nil)
      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(email)}")
      raise HTTPRequestError, response.body.inspect unless response.is_a?(Net::HTTPOK)
      response
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jonuts-garb-0.2.4 lib/garb/data_request.rb
jonuts-garb-0.2.6 lib/garb/data_request.rb