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        => 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.

Constant Summary collapse

DEFINED_OPTIONS =
[
  :site,
  :context_path,
  :signature_method,
  :request_token_path,
  :authorize_path,
  :access_token_path,
  :private_key,
  :private_key_file,
  :rest_base_path,
  :consumer_key,
  :consumer_secret,
  :ssl_verify_mode,
  :ssl_version,
  :use_ssl,
  :username,
  :password,
  :auth_type,
  :proxy_address,
  :proxy_port,
  :proxy_username,
  :proxy_password,
  :use_cookies,
  :additional_cookies,
  :default_headers,
  :use_client_cert,
  :read_timeout,
  :http_debug,
  :issuer,
  :base_url,
  :shared_secret,
  :cert_path,
  :key_path,
  :ssl_client_cert,
  :ssl_client_key
].freeze
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,
  use_client_cert: false,
  auth_type: :oauth,
  http_debug: false,
  default_headers: {}
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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

Instance Attribute Details

#cacheObject

The OAuth::Consumer instance returned by the OauthClient

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


54
55
56
# File 'lib/jira/client.rb', line 54

def cache
  @cache
end

#consumerObject

The OAuth::Consumer instance returned by the OauthClient

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


54
55
56
# File 'lib/jira/client.rb', line 54

def consumer
  @consumer
end

#http_debugObject

The OAuth::Consumer instance returned by the OauthClient

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


54
55
56
# File 'lib/jira/client.rb', line 54

def http_debug
  @http_debug
end

#optionsObject (readonly)

The configuration options for this client instance


57
58
59
# File 'lib/jira/client.rb', line 57

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)


54
55
56
# File 'lib/jira/client.rb', line 54

def request_client
  @request_client
end

Instance Method Details

#AgileObject


268
269
270
# File 'lib/jira/client.rb', line 268

def Agile
  JIRA::Resource::AgileFactory.new(self)
end

240
241
242
# File 'lib/jira/client.rb', line 240

def ApplicationLink
  JIRA::Resource::ApplicationLinkFactory.new(self)
end

#AttachmentObject

:nodoc:


192
193
194
# File 'lib/jira/client.rb', line 192

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

#BoardObject


212
213
214
# File 'lib/jira/client.rb', line 212

def Board
  JIRA::Resource::BoardFactory.new(self)
end

#BoardConfigurationObject


216
217
218
# File 'lib/jira/client.rb', line 216

def BoardConfiguration
  JIRA::Resource::BoardConfigurationFactory.new(self)
end

#CommentObject

:nodoc:


188
189
190
# File 'lib/jira/client.rb', line 188

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

#ComponentObject

:nodoc:


164
165
166
# File 'lib/jira/client.rb', line 164

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

#CreatemetaObject


236
237
238
# File 'lib/jira/client.rb', line 236

def Createmeta
  JIRA::Resource::CreatemetaFactory.new(self)
end

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

HTTP methods without a body


273
274
275
# File 'lib/jira/client.rb', line 273

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

#FieldObject

:nodoc:


208
209
210
# File 'lib/jira/client.rb', line 208

def Field # :nodoc:
  JIRA::Resource::FieldFactory.new(self)
end

#FilterObject

:nodoc:


160
161
162
# File 'lib/jira/client.rb', line 160

def Filter # :nodoc:
  JIRA::Resource::FilterFactory.new(self)
end

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


277
278
279
# File 'lib/jira/client.rb', line 277

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

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


281
282
283
# File 'lib/jira/client.rb', line 281

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

#inspectObject

Stops sensitive client information from being displayed in logs


309
310
311
# File 'lib/jira/client.rb', line 309

def inspect
  "#<JIRA::Client:#{object_id}>"
end

#IssueObject

:nodoc:


156
157
158
# File 'lib/jira/client.rb', line 156

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

252
253
254
# File 'lib/jira/client.rb', line 252

def Issuelink
  JIRA::Resource::IssuelinkFactory.new(self)
end

#IssuelinktypeObject


256
257
258
# File 'lib/jira/client.rb', line 256

def Issuelinktype
  JIRA::Resource::IssuelinktypeFactory.new(self)
end

#IssuePickerSuggestionsObject


260
261
262
# File 'lib/jira/client.rb', line 260

def IssuePickerSuggestions
  JIRA::Resource::IssuePickerSuggestionsFactory.new(self)
end

#IssuetypeObject

:nodoc:


172
173
174
# File 'lib/jira/client.rb', line 172

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

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

HTTP methods with a body


286
287
288
289
# File 'lib/jira/client.rb', line 286

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


291
292
293
294
# File 'lib/jira/client.rb', line 291

def post_multipart(path, file, headers = {})
  puts "post multipart: #{path} - [#{file}]" if @http_debug
  @request_client.request_multipart(path, file, headers)
end

#PriorityObject

:nodoc:


176
177
178
# File 'lib/jira/client.rb', line 176

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

#ProjectObject

:nodoc:


152
153
154
# File 'lib/jira/client.rb', line 152

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

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


296
297
298
299
# File 'lib/jira/client.rb', line 296

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

#RapidViewObject


220
221
222
# File 'lib/jira/client.rb', line 220

def RapidView
  JIRA::Resource::RapidViewFactory.new(self)
end

264
265
266
# File 'lib/jira/client.rb', line 264

def Remotelink
  JIRA::Resource::RemotelinkFactory.new(self)
end

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

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


303
304
305
306
# File 'lib/jira/client.rb', line 303

def request(http_method, path, body = '', headers = {})
  puts "#{http_method}: #{path} - [#{body}]" if @http_debug
  @request_client.request(http_method, path, body, headers)
end

#ResolutionObject

:nodoc:


184
185
186
# File 'lib/jira/client.rb', line 184

def Resolution # :nodoc:
  JIRA::Resource::ResolutionFactory.new(self)
end

#ServerInfoObject


232
233
234
# File 'lib/jira/client.rb', line 232

def ServerInfo
  JIRA::Resource::ServerInfoFactory.new(self)
end

#SprintObject


224
225
226
# File 'lib/jira/client.rb', line 224

def Sprint
  JIRA::Resource::SprintFactory.new(self)
end

#SprintReportObject


228
229
230
# File 'lib/jira/client.rb', line 228

def SprintReport
  JIRA::Resource::SprintReportFactory.new(self)
end

#StatusObject

:nodoc:


180
181
182
# File 'lib/jira/client.rb', line 180

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

#TransitionObject

:nodoc:


204
205
206
# File 'lib/jira/client.rb', line 204

def Transition # :nodoc:
  JIRA::Resource::TransitionFactory.new(self)
end

#UserObject

:nodoc:


168
169
170
# File 'lib/jira/client.rb', line 168

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

#VersionObject

:nodoc:


200
201
202
# File 'lib/jira/client.rb', line 200

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

#WatcherObject


244
245
246
# File 'lib/jira/client.rb', line 244

def Watcher
  JIRA::Resource::WatcherFactory.new(self)
end

#WebhookObject


248
249
250
# File 'lib/jira/client.rb', line 248

def Webhook
  JIRA::Resource::WebhookFactory.new(self)
end

#WorklogObject

:nodoc:


196
197
198
# File 'lib/jira/client.rb', line 196

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