Class: HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/gracenote/HTTP.rb

Class Method Summary collapse

Class Method Details

.get(path, cookie = '') ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/gracenote/HTTP.rb', line 13

def self.get(path, cookie='')
  uri = URI(path)
  req = Net::HTTP.new(uri.host, uri.port)
  req.read_timeout = 60
  req.use_ssl = (uri.scheme == "https") ? true : false
  headers = {'Cookie' => cookie}
  
  resp = req.get( uri.path, headers)
  return resp
end

.post(path, data = '', cookie = '') ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gracenote/HTTP.rb', line 24

def self.post(path, data='', cookie='')
  uri = URI(path)
  req = Net::HTTP.new(uri.host, uri.port)
  req.read_timeout = 60
  req.use_ssl = (uri.scheme == "https") ? true : false
  headers = {'Cookie' => cookie, "Content-Type" => "application/xml"}

  if data.class.to_s == 'String'
    reqdata = data;
  else
    reqdata = Rack::Utils.build_nested_query(data)
  end

  resp = req.request_post( uri.path, reqdata, headers)     
  return resp
end