Class: OpenID::SimpleHTTPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/consumer.rb

Overview

Provides a very simple interface to get from and post to http servers

Instance Method Summary collapse

Instance Method Details

#get(url) ⇒ Object

Returns the the url which was retrieved, and the retrived data (data.base_uri, data)



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/openid/consumer.rb', line 33

def get(url)
  uri = URI.parse(url)
  begin
    data = uri.read
  ensure
    if data
      return data.base_uri, data
    else
      return nil, nil
    end
  end
end

#post(url, body) ⇒ Object

Takes the url to post body to. Returns the url retrieved, and the body of the response received.



47
48
49
50
51
52
53
54
55
56
# File 'lib/openid/consumer.rb', line 47

def post(url, body)
  uri = URI.parse(url)
  response = nil
  Net::HTTP.start(uri.host, uri.port) { |http|
    response = http.post(uri.request_uri(), body)
  }
  # TODO: some error checking here

  # TODO: return actually retrieved url

  return url, response.body
end