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
:ca_file            => nil

See the JIRA::Base class methods for all of the available methods on these accessor objects.

Constants

DEFAULT_OPTIONS
DEFINED_OPTIONS

Attributes

cache[RW]

The OAuth::Consumer instance returned by the OauthClient

The authenticated client instance returned by the respective client type (Oauth, Basic)

consumer[RW]

The OAuth::Consumer instance returned by the OauthClient

The authenticated client instance returned by the respective client type (Oauth, Basic)

http_debug[RW]

The OAuth::Consumer instance returned by the OauthClient

The authenticated client instance returned by the respective client type (Oauth, Basic)

options[R]

The configuration options for this client instance

request_client[RW]

The OAuth::Consumer instance returned by the OauthClient

The authenticated client instance returned by the respective client type (Oauth, Basic)

Public Class Methods

new(options = {}) click to toggle source
# File lib/jira/client.rb, line 111
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

Agile() click to toggle source
# File lib/jira/client.rb, line 269
def Agile
  JIRA::Resource::AgileFactory.new(self)
end
Board() click to toggle source
# File lib/jira/client.rb, line 213
def Board
  JIRA::Resource::BoardFactory.new(self)
end
BoardConfiguration() click to toggle source
# File lib/jira/client.rb, line 217
def BoardConfiguration
  JIRA::Resource::BoardConfigurationFactory.new(self)
end
Createmeta() click to toggle source
# File lib/jira/client.rb, line 237
def Createmeta
  JIRA::Resource::CreatemetaFactory.new(self)
end
IssuePickerSuggestions() click to toggle source
# File lib/jira/client.rb, line 261
def IssuePickerSuggestions
  JIRA::Resource::IssuePickerSuggestionsFactory.new(self)
end
Issuelinktype() click to toggle source
# File lib/jira/client.rb, line 257
def Issuelinktype
  JIRA::Resource::IssuelinktypeFactory.new(self)
end
RapidView() click to toggle source
# File lib/jira/client.rb, line 221
def RapidView
  JIRA::Resource::RapidViewFactory.new(self)
end
ServerInfo() click to toggle source
# File lib/jira/client.rb, line 233
def ServerInfo
  JIRA::Resource::ServerInfoFactory.new(self)
end
Sprint() click to toggle source
# File lib/jira/client.rb, line 225
def Sprint
  JIRA::Resource::SprintFactory.new(self)
end
SprintReport() click to toggle source
# File lib/jira/client.rb, line 229
def SprintReport
  JIRA::Resource::SprintReportFactory.new(self)
end
Watcher() click to toggle source
# File lib/jira/client.rb, line 245
def Watcher
  JIRA::Resource::WatcherFactory.new(self)
end
Webhook() click to toggle source
# File lib/jira/client.rb, line 249
def Webhook
  JIRA::Resource::WebhookFactory.new(self)
end
delete(path, headers = {}) click to toggle source

HTTP methods without a body

# File lib/jira/client.rb, line 274
def delete(path, headers = {})
  request(:delete, path, nil, merge_default_headers(headers))
end
get(path, headers = {}) click to toggle source
# File lib/jira/client.rb, line 278
def get(path, headers = {})
  request(:get, path, nil, merge_default_headers(headers))
end
head(path, headers = {}) click to toggle source
# File lib/jira/client.rb, line 282
def head(path, headers = {})
  request(:head, path, nil, merge_default_headers(headers))
end
inspect() click to toggle source

Stops sensitive client information from being displayed in logs

# File lib/jira/client.rb, line 310
def inspect
  "#<JIRA::Client:#{object_id}>"
end
post(path, body = '', headers = {}) click to toggle source

HTTP methods with a body

# File lib/jira/client.rb, line 287
def post(path, body = '', headers = {})
  headers = { 'Content-Type' => 'application/json' }.merge(headers)
  request(:post, path, body, merge_default_headers(headers))
end
post_multipart(path, file, headers = {}) click to toggle source
# File lib/jira/client.rb, line 292
def post_multipart(path, file, headers = {})
  puts "post multipart: #{path} - [#{file}]" if @http_debug
  @request_client.request_multipart(path, file, headers)
end
put(path, body = '', headers = {}) click to toggle source
# File lib/jira/client.rb, line 297
def put(path, body = '', headers = {})
  headers = { 'Content-Type' => 'application/json' }.merge(headers)
  request(:put, path, body, merge_default_headers(headers))
end
request(http_method, path, body = '', headers = {}) click to toggle source

Sends the specified HTTP request to the REST API through the appropriate method (oauth, basic).

# File lib/jira/client.rb, line 304
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

merge_default_headers(headers) click to toggle source
# File lib/jira/client.rb, line 316
def merge_default_headers(headers)
  { 'Accept' => 'application/json' }.merge(@options[:default_headers]).merge(headers)
end