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_file   => "rsakey.pem",
:rest_base_path     => "/rest/api/2",
:consumer_key       => nil,
:consumer_secret    => nil,
:ssl_verify_mode    => OpenSSL::SSL::VERIFY_PEER,
:use_ssl            => true,
:username           => nil,
:password           => nil,
:auth_type          => :oauth,
:proxy_address      => nil,
:proxy_port         => nil,
:additional_cookies => nil

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

Constants

DEFAULT_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 60
def initialize(options={})
  options = DEFAULT_OPTIONS.merge(options)
  @options = options
  @options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path]

  if options[:use_client_cert]
    raise ArgumentError, 'Options: :cert_path must be set when :use_client_cert is true' unless @options[:cert_path]
    raise ArgumentError, 'Options: :key_path must be set when :use_client_cert is true' unless @options[:key_path]
    @options[:cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path]))
    @options[:key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path]))
  end

  case options[:auth_type]
  when :oauth, :oauth_2legged
    @request_client = OauthClient.new(@options)
    @consumer = @request_client.consumer
  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 196
def Agile
  JIRA::Resource::AgileFactory.new(self)
end
Createmeta() click to toggle source
# File lib/jira/client.rb, line 164
def Createmeta
  JIRA::Resource::CreatemetaFactory.new(self)
end
Issuelinktype() click to toggle source
# File lib/jira/client.rb, line 184
def Issuelinktype
  JIRA::Resource::IssuelinktypeFactory.new(self)
end
RapidView() click to toggle source
# File lib/jira/client.rb, line 156
def RapidView
  JIRA::Resource::RapidViewFactory.new(self)
end
ServerInfo() click to toggle source
# File lib/jira/client.rb, line 160
def ServerInfo
  JIRA::Resource::ServerInfoFactory.new(self)
end
Sprint() click to toggle source
# File lib/jira/client.rb, line 192
def Sprint
  JIRA::Resource::SprintFactory.new(self)
end
Watcher() click to toggle source
# File lib/jira/client.rb, line 172
def Watcher
  JIRA::Resource::WatcherFactory.new(self)
end
Webhook() click to toggle source
# File lib/jira/client.rb, line 176
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 201
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 205
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 209
def head(path, headers = {})
  request(:head, path, nil, merge_default_headers(headers))
end
post(path, body = '', headers = {}) click to toggle source

HTTP methods with a body

# File lib/jira/client.rb, line 214
def post(path, body = '', headers = {})
  headers = {'Content-Type' => 'application/json'}.merge(headers)
  request(:post, path, body, merge_default_headers(headers))
end
put(path, body = '', headers = {}) click to toggle source
# File lib/jira/client.rb, line 219
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 226
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 233
def merge_default_headers(headers)
  {'Accept' => 'application/json'}.merge(headers)
end