Class: Steam::Connection::NetHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/connection/net_http.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
# File 'lib/steam/connection/net_http.rb', line 14

def call(env)
  request  = Rack::Request.new(env)
  response = send(request.request_method.downcase, request)
  response = follow_redirect(response) if response.status.to_s[0, 1] == '3'
  response.to_a
end

#follow_redirect(response) ⇒ Object



34
35
36
37
38
39
# File 'lib/steam/connection/net_http.rb', line 34

def follow_redirect(response)
  location = response.headers['location'].join
  env      = Steam::Request.env_for(location)
  request  = Rack::Request.new(env)
  get(request)
end

#get(request) ⇒ Object



21
22
23
24
25
# File 'lib/steam/connection/net_http.rb', line 21

def get(request)
  url      = URI.parse(request.url)
  response = Net::HTTP.start(url.host, url.port) { |http| http.get(url.path) }
  Rack::Response.new(response.body, response.code, response.to_hash)
end

#post(request) ⇒ Object



27
28
29
30
31
32
# File 'lib/steam/connection/net_http.rb', line 27

def post(request)
  url      = URI.parse(request.url)
  params   = Rack::Utils.parse_query(Rack::Utils.build_nested_query(request.params))
  response = Net::HTTP.post_form(url, params)
  Rack::Response.new(response.body, response.code, response.to_hash)
end