Module: SkypeCheck::HTTPService

Defined in:
lib/skype_check/http_service.rb

Class Method Summary collapse

Class Method Details

.http_query(username) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/skype_check/http_service.rb', line 10

def http_query(username) 
  begin
    #setup uri object with username param
    uri = URI(SkypeCheck.configuration.username_validator_endpoint)
    param = { new_username: username }
    uri.query = URI.encode_www_form(param)

    #build a request object
    http = Net::HTTP.new(uri.host, uri.port)
    if uri.kind_of? URI::HTTPS
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end

    request = Net::HTTP::Get.new(uri.request_uri)
    http.request(request)
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, SocketError => e
    raise SkypeCheck::QueryError.new(e)
  end
end