Class: Fogbugz::Adapter::HTTP::NetHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_fogbugz/adapters/http/net_http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NetHttp

Returns a new instance of NetHttp.



10
11
12
# File 'lib/ruby_fogbugz/adapters/http/net_http.rb', line 10

def initialize(options = {})
  @root_url = options[:uri]
end

Instance Attribute Details

#requesterObject

Returns the value of attribute requester.



8
9
10
# File 'lib/ruby_fogbugz/adapters/http/net_http.rb', line 8

def requester
  @requester
end

#root_urlObject

Returns the value of attribute root_url.



8
9
10
# File 'lib/ruby_fogbugz/adapters/http/net_http.rb', line 8

def root_url
  @root_url
end

Instance Method Details

#request(action, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_fogbugz/adapters/http/net_http.rb', line 14

def request(action, options)
  # Convert the hash key/values to key=value&key2=value2 strings - CGI escaping along the way
  options_string = options[:params].map{ |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
  
  url_string = "#{@root_url}/api.asp?cmd=#{action}&#{options_string}"
  url = URI.parse(url_string)
  
  request = Net::HTTP::Get.new(url_string, {"Content-Type"=>"text/xml"})
  
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = @root_url.start_with? 'https'
  
  response = http.start {|http| http.request(request) }
  response.body
end