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.



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

def initialize(options)
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#basic_auth_http_connObject



26
27
28
# File 'lib/jira/http_client.rb', line 26

def basic_auth_http_conn
  http_conn(uri)
end

#http_conn(uri) ⇒ Object



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

def http_conn(uri)
  http_conn = Net::HTTP.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



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

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?
  request.basic_auth(@options[:username], @options[:password])
  response = basic_auth_http_conn.request(request)
  response
end

#uriObject



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

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