Class: JIRA::HttpClient

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

Direct Known Subclasses

JwtClient

Constant Summary collapse

DEFAULT_OPTIONS =
{
  username: nil,
  password: nil
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RequestClient

#request, #request_multipart

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

#authenticated?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/jira/http_client.rb', line 70

def authenticated?
  @authenticated
end

#basic_auth_http_connObject



43
44
45
# File 'lib/jira/http_client.rb', line 43

def basic_auth_http_conn
  http_conn(uri)
end

#http_conn(uri) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jira/http_client.rb', line 47

def http_conn(uri)
  if @options[:proxy_address]
    http_class = Net::HTTP::Proxy(@options[:proxy_address], @options[:proxy_port] || 80, @options[:proxy_username], @options[:proxy_password])
  else
    http_class = Net::HTTP
  end
  http_conn = http_class.new(uri.host, uri.port)
  http_conn.use_ssl = @options[:use_ssl]
  if @options[:use_client_cert]
    http_conn.cert = @options[:ssl_client_cert]
    http_conn.key = @options[:ssl_client_key]
  end
  http_conn.verify_mode = @options[:ssl_verify_mode]
  http_conn.ssl_version = @options[:ssl_version] if @options[:ssl_version]
  http_conn.read_timeout = @options[:read_timeout]
  http_conn.ca_file = @options[:ca_file] if @options[:ca_file]
  http_conn
end


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

def make_cookie_auth_request
  body = { username: @options[:username].to_s, password: @options[:password].to_s }.to_json
  @options.delete(:username)
  @options.delete(:password)
  make_request(:post, @options[:context_path] + '/rest/auth/1/session', body, 'Content-Type' => 'application/json')
end

#make_multipart_request(url, body, headers = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/jira/http_client.rb', line 36

def make_multipart_request(url, body, headers = {})
  path = request_path(url)
  request = Net::HTTP::Post::Multipart.new(path, body, headers)

  execute_request(request)
end

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



27
28
29
30
31
32
33
34
# File 'lib/jira/http_client.rb', line 27

def make_request(http_method, url, body = '', headers = {})
  # When a proxy is enabled, Net::HTTP expects that the request path omits the domain name
  path = request_path(url)
  request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
  request.body = body unless body.nil?

  execute_request(request)
end

#uriObject



66
67
68
# File 'lib/jira/http_client.rb', line 66

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