Class: JIRA::HttpClient
- Inherits:
-
RequestClient
- Object
- RequestClient
- JIRA::HttpClient
- Defined in:
- lib/jira/http_client.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ username: '', password: '' }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #basic_auth_http_conn ⇒ Object
- #http_conn(uri) ⇒ Object
-
#initialize(options) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #make_cookie_auth_request ⇒ Object
- #make_request(http_method, url, body = '', headers = {}) ⇒ Object
- #uri ⇒ Object
Methods inherited from RequestClient
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 = DEFAULT_OPTIONS.merge() @cookies = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/jira/http_client.rb', line 13 def @options end |
Instance Method Details
#authenticated? ⇒ Boolean
65 66 67 |
# File 'lib/jira/http_client.rb', line 65 def authenticated? @authenticated end |
#basic_auth_http_conn ⇒ Object
40 41 42 |
# File 'lib/jira/http_client.rb', line 40 def basic_auth_http_conn http_conn(uri) end |
#http_conn(uri) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jira/http_client.rb', line 44 def http_conn(uri) if @options[:proxy_address] http_class = Net::HTTP::Proxy(@options[:proxy_address], @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] if @options[:use_client_cert] http_conn.cert = @options[:cert] http_conn.key = @options[:key] end http_conn.verify_mode = @options[:ssl_verify_mode] http_conn.read_timeout = @options[:read_timeout] http_conn end |
#make_cookie_auth_request ⇒ Object
20 21 22 23 24 25 |
# File 'lib/jira/http_client.rb', line 20 def body = { username: @options[:username], password: @options[:password] }.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_request(http_method, url, body = '', headers = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# 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? (request) if [:use_cookies] request.basic_auth(@options[:username], @options[:password]) if @options[:username] && @options[:password] response = basic_auth_http_conn.request(request) @authenticated = response.is_a? Net::HTTPOK (response) if [:use_cookies] response end |
#uri ⇒ Object
61 62 63 |
# File 'lib/jira/http_client.rb', line 61 def uri uri = URI.parse(@options[:site]) end |