Class: JIRA::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jira/client.rb

Overview

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

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :site               => 'http://localhost:2990',
  :context_path       => '/jira',
  :rest_base_path     => "/rest/api/2",
  :ssl_verify_mode    => OpenSSL::SSL::VERIFY_PEER,
  :use_ssl            => true,
  :auth_type          => :oauth
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jira/client.rb', line 54

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

Instance Attribute Details

#consumerObject

The OAuth::Consumer instance returned by the OauthClient

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


38
39
40
# File 'lib/jira/client.rb', line 38

def consumer
  @consumer
end

#optionsObject (readonly)

The configuration options for this client instance


41
42
43
# File 'lib/jira/client.rb', line 41

def options
  @options
end

#request_clientObject

The OAuth::Consumer instance returned by the OauthClient

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


38
39
40
# File 'lib/jira/client.rb', line 38

def request_client
  @request_client
end

Instance Method Details

#AttachmentObject

:nodoc:


102
103
104
# File 'lib/jira/client.rb', line 102

def Attachment # :nodoc:
  JIRA::Resource::AttachmentFactory.new(self)
end

#CommentObject

:nodoc:


98
99
100
# File 'lib/jira/client.rb', line 98

def Comment # :nodoc:
  JIRA::Resource::CommentFactory.new(self)
end

#ComponentObject

:nodoc:


78
79
80
# File 'lib/jira/client.rb', line 78

def Component # :nodoc:
  JIRA::Resource::ComponentFactory.new(self)
end

#delete(path, headers = {}) ⇒ Object

HTTP methods without a body


115
116
117
# File 'lib/jira/client.rb', line 115

def delete(path, headers = {})
  request(:delete, path, nil, merge_default_headers(headers))
end

#get(path, headers = {}) ⇒ Object


119
120
121
# File 'lib/jira/client.rb', line 119

def get(path, headers = {})
  request(:get, path, nil, merge_default_headers(headers))
end

#head(path, headers = {}) ⇒ Object


123
124
125
# File 'lib/jira/client.rb', line 123

def head(path, headers = {})
  request(:head, path, nil, merge_default_headers(headers))
end

#IssueObject

:nodoc:


74
75
76
# File 'lib/jira/client.rb', line 74

def Issue # :nodoc:
  JIRA::Resource::IssueFactory.new(self)
end

#IssuetypeObject

:nodoc:


86
87
88
# File 'lib/jira/client.rb', line 86

def Issuetype # :nodoc:
  JIRA::Resource::IssuetypeFactory.new(self)
end

#post(path, body = '', headers = {}) ⇒ Object

HTTP methods with a body


128
129
130
131
# File 'lib/jira/client.rb', line 128

def post(path, body = '', headers = {})
  headers = {'Content-Type' => 'application/json'}.merge(headers)
  request(:post, path, body, merge_default_headers(headers))
end

#PriorityObject

:nodoc:


90
91
92
# File 'lib/jira/client.rb', line 90

def Priority # :nodoc:
  JIRA::Resource::PriorityFactory.new(self)
end

#ProjectObject

:nodoc:


70
71
72
# File 'lib/jira/client.rb', line 70

def Project # :nodoc:
  JIRA::Resource::ProjectFactory.new(self)
end

#put(path, body = '', headers = {}) ⇒ Object


133
134
135
136
# File 'lib/jira/client.rb', line 133

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 = {}) ⇒ Object

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


140
141
142
# File 'lib/jira/client.rb', line 140

def request(http_method, path, body = '', headers={})
  @request_client.request(http_method, path, body, headers)
end

#StatusObject

:nodoc:


94
95
96
# File 'lib/jira/client.rb', line 94

def Status # :nodoc:
  JIRA::Resource::StatusFactory.new(self)
end

#UserObject

:nodoc:


82
83
84
# File 'lib/jira/client.rb', line 82

def User # :nodoc:
  JIRA::Resource::UserFactory.new(self)
end

#VersionObject

:nodoc:


110
111
112
# File 'lib/jira/client.rb', line 110

def Version # :nodoc:
  JIRA::Resource::VersionFactory.new(self)
end

#WorklogObject

:nodoc:


106
107
108
# File 'lib/jira/client.rb', line 106

def Worklog # :nodoc:
  JIRA::Resource::WorklogFactory.new(self)
end