class JIRA::Client
This class is the main access point for all JIRA::Resource
instances.
The client must be initialized with an options hash containing configuration options. The available options are:
:site => 'http://localhost:2990', :context_path => '/jira', :signature_method => 'RSA-SHA1', :request_token_path => "/plugins/servlet/oauth/request-token", :authorize_path => "/plugins/servlet/oauth/authorize", :access_token_path => "/plugins/servlet/oauth/access-token", :private_key => nil, :private_key_file => "rsakey.pem", :rest_base_path => "/rest/api/2", :consumer_key => nil, :consumer_secret => nil, :ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :ssl_version => nil, :use_ssl => true, :username => nil, :password => nil, :auth_type => :oauth, :proxy_address => nil, :proxy_port => nil, :proxy_username => nil, :proxy_password => nil, :use_cookies => nil, :additional_cookies => nil, :default_headers => {}, :use_client_cert => false, :read_timeout => nil, :http_debug => false, :shared_secret => nil, :cert_path => nil, :key_path => nil, :ssl_client_cert => nil, :ssl_client_key => nil
See the JIRA::Base
class methods for all of the available methods on these accessor objects.
Constants
- DEFAULT_OPTIONS
- DEFINED_OPTIONS
Attributes
The OAuth::Consumer instance returned by the OauthClient
The authenticated client instance returned by the respective client type (Oauth, Basic)
The OAuth::Consumer instance returned by the OauthClient
The authenticated client instance returned by the respective client type (Oauth, Basic)
The OAuth::Consumer instance returned by the OauthClient
The authenticated client instance returned by the respective client type (Oauth, Basic)
The configuration options for this client instance
The OAuth::Consumer instance returned by the OauthClient
The authenticated client instance returned by the respective client type (Oauth, Basic)
Public Class Methods
# File lib/jira/client.rb, line 110 def initialize(options = {}) options = DEFAULT_OPTIONS.merge(options) @options = options @options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path] unknown_options = options.keys.reject { |o| DEFINED_OPTIONS.include?(o) } raise ArgumentError, "Unknown option(s) given: #{unknown_options}" unless unknown_options.empty? if options[:use_client_cert] @options[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) if @options[:cert_path] @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path] raise ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert] raise ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key] end case options[:auth_type] when :oauth, :oauth_2legged @request_client = OauthClient.new(@options) @consumer = @request_client.consumer when :jwt @request_client = JwtClient.new(@options) when :basic @request_client = HttpClient.new(@options) when :cookie raise ArgumentError, 'Options: :use_cookies must be true for :cookie authorization type' if @options.key?(:use_cookies) && !@options[:use_cookies] @options[:use_cookies] = true @request_client = HttpClient.new(@options) @request_client.make_cookie_auth_request @options.delete(:username) @options.delete(:password) else raise ArgumentError, 'Options: ":auth_type" must be ":oauth",":oauth_2legged", ":cookie" or ":basic"' end @http_debug = @options[:http_debug] @options.freeze @cache = OpenStruct.new end
Public Instance Methods
# File lib/jira/client.rb, line 264 def Agile JIRA::Resource::AgileFactory.new(self) end
# File lib/jira/client.rb, line 240 def ApplicationLink JIRA::Resource::ApplicationLinkFactory.new(self) end
# File lib/jira/client.rb, line 212 def Board JIRA::Resource::BoardFactory.new(self) end
# File lib/jira/client.rb, line 216 def BoardConfiguration JIRA::Resource::BoardConfigurationFactory.new(self) end
# File lib/jira/client.rb, line 236 def Createmeta JIRA::Resource::CreatemetaFactory.new(self) end
# File lib/jira/client.rb, line 252 def Issuelink JIRA::Resource::IssuelinkFactory.new(self) end
# File lib/jira/client.rb, line 256 def Issuelinktype JIRA::Resource::IssuelinktypeFactory.new(self) end
# File lib/jira/client.rb, line 220 def RapidView JIRA::Resource::RapidViewFactory.new(self) end
# File lib/jira/client.rb, line 260 def Remotelink JIRA::Resource::RemotelinkFactory.new(self) end
# File lib/jira/client.rb, line 232 def ServerInfo JIRA::Resource::ServerInfoFactory.new(self) end
# File lib/jira/client.rb, line 224 def Sprint JIRA::Resource::SprintFactory.new(self) end
# File lib/jira/client.rb, line 228 def SprintReport JIRA::Resource::SprintReportFactory.new(self) end
# File lib/jira/client.rb, line 244 def Watcher JIRA::Resource::WatcherFactory.new(self) end
# File lib/jira/client.rb, line 248 def Webhook JIRA::Resource::WebhookFactory.new(self) end
HTTP methods without a body
# File lib/jira/client.rb, line 269 def delete(path, headers = {}) request(:delete, path, nil, merge_default_headers(headers)) end
# File lib/jira/client.rb, line 273 def get(path, headers = {}) request(:get, path, nil, merge_default_headers(headers)) end
# File lib/jira/client.rb, line 277 def head(path, headers = {}) request(:head, path, nil, merge_default_headers(headers)) end
Stops sensitive client information from being displayed in logs
# File lib/jira/client.rb, line 305 def inspect "#<JIRA::Client:#{object_id}>" end
HTTP methods with a body
# File lib/jira/client.rb, line 282 def post(path, body = '', headers = {}) headers = { 'Content-Type' => 'application/json' }.merge(headers) request(:post, path, body, merge_default_headers(headers)) end
# File lib/jira/client.rb, line 287 def post_multipart(path, file, headers = {}) puts "post multipart: #{path} - [#{file}]" if @http_debug @request_client.request_multipart(path, file, headers) end
# File lib/jira/client.rb, line 292 def put(path, body = '', headers = {}) headers = { 'Content-Type' => 'application/json' }.merge(headers) request(:put, path, body, merge_default_headers(headers)) end
Sends the specified HTTP request to the REST API through the appropriate method (oauth, basic).
# File lib/jira/client.rb, line 299 def request(http_method, path, body = '', headers = {}) puts "#{http_method}: #{path} - [#{body}]" if @http_debug @request_client.request(http_method, path, body, headers) end
Protected Instance Methods
# File lib/jira/client.rb, line 311 def merge_default_headers(headers) { 'Accept' => 'application/json' }.merge(@options[:default_headers]).merge(headers) end