Class: JIRA::HttpClient

Inherits:
RequestClient show all
Defined in:
lib/jira/http_client.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :username           => '',
  :password           => ''
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RequestClient

#request

Constructor Details

#initialize(options) ⇒ HttpClient

Returns a new instance of HttpClient.



15
16
17
18
# File 'lib/jira/http_client.rb', line 15

def initialize(options)
  @options = DEFAULT_OPTIONS.merge(options)
  @cookies = {}
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/jira/http_client.rb', line 13

def options
  @options
end

Instance Method Details

#basic_auth_http_connObject



30
31
32
# File 'lib/jira/http_client.rb', line 30

def basic_auth_http_conn
  http_conn(uri)
end

#http_conn(uri) ⇒ Object



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

def http_conn(uri)
  if @options[:proxy_address]
      http_class = Net::HTTP::Proxy(@options[:proxy_address], @options[:proxy_port] ? @options[:proxy_port] : 80)
  else
      http_class = Net::HTTP
  end
  http_conn = http_class.new(uri.host, uri.port)
  http_conn.use_ssl = @options[:use_ssl]
  http_conn.verify_mode = @options[:ssl_verify_mode]
  http_conn
end

#make_request(http_method, path, body = '', headers = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/jira/http_client.rb', line 20

def make_request(http_method, path, body='', headers={})
  request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
  request.body = body unless body.nil?
  add_cookies(request) if options[:use_cookies]
  request.basic_auth(@options[:username], @options[:password])
  response = basic_auth_http_conn.request(request)
  store_cookies(response) if options[:use_cookies]
  response
end

#uriObject



46
47
48
# File 'lib/jira/http_client.rb', line 46

def uri
  uri = URI.parse(@options[:site])
end