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

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

Constants

DEFAULT_OPTIONS

Attributes

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

  case options[:auth_type]
  when :oauth
    @request_client = OauthClient.new(@options)
    @consumer = @request_client.consumer
  when :basic
    @request_client = HttpClient.new(@options)
  end

  @options.freeze
end

Public Instance Methods

delete(path, headers = {}) click to toggle source

HTTP methods without a body

# File lib/jira/client.rb, line 129
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 133
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 137
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 142
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 147
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 154
def request(http_method, path, body = '', headers={})
  @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 160
def merge_default_headers(headers)
  {'Accept' => 'application/json'}.merge(headers)
end