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,
: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,
  :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)

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

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)


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

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)


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

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)


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

def http_debug
  @http_debug
end

#optionsObject (readonly)

The configuration options for this client instance


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

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)


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

def request_client
  @request_client
end

Instance Method Details

#AgileObject


262
263
264
# File 'lib/jira/client.rb', line 262

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

238
239
240
# File 'lib/jira/client.rb', line 238

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

#AttachmentObject

:nodoc:


190
191
192
# File 'lib/jira/client.rb', line 190

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

#BoardObject


210
211
212
# File 'lib/jira/client.rb', line 210

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

#BoardConfigurationObject


214
215
216
# File 'lib/jira/client.rb', line 214

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

#CommentObject

:nodoc:


186
187
188
# File 'lib/jira/client.rb', line 186

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

#ComponentObject

:nodoc:


162
163
164
# File 'lib/jira/client.rb', line 162

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

#CreatemetaObject


234
235
236
# File 'lib/jira/client.rb', line 234

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

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

HTTP methods without a body


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

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

#FieldObject

:nodoc:


206
207
208
# File 'lib/jira/client.rb', line 206

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

#FilterObject

:nodoc:


158
159
160
# File 'lib/jira/client.rb', line 158

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

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


271
272
273
# File 'lib/jira/client.rb', line 271

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

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


275
276
277
# File 'lib/jira/client.rb', line 275

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

#IssueObject

:nodoc:


154
155
156
# File 'lib/jira/client.rb', line 154

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

250
251
252
# File 'lib/jira/client.rb', line 250

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

#IssuelinktypeObject


254
255
256
# File 'lib/jira/client.rb', line 254

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

#IssuetypeObject

:nodoc:


170
171
172
# File 'lib/jira/client.rb', line 170

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

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

HTTP methods with a body


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

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


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

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

#PriorityObject

:nodoc:


174
175
176
# File 'lib/jira/client.rb', line 174

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

#ProjectObject

:nodoc:


150
151
152
# File 'lib/jira/client.rb', line 150

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

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


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

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

#RapidViewObject


218
219
220
# File 'lib/jira/client.rb', line 218

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

258
259
260
# File 'lib/jira/client.rb', line 258

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


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

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:


182
183
184
# File 'lib/jira/client.rb', line 182

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

#ServerInfoObject


230
231
232
# File 'lib/jira/client.rb', line 230

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

#SprintObject


222
223
224
# File 'lib/jira/client.rb', line 222

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

#SprintReportObject


226
227
228
# File 'lib/jira/client.rb', line 226

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

#StatusObject

:nodoc:


178
179
180
# File 'lib/jira/client.rb', line 178

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

#TransitionObject

:nodoc:


202
203
204
# File 'lib/jira/client.rb', line 202

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

#UserObject

:nodoc:


166
167
168
# File 'lib/jira/client.rb', line 166

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

#VersionObject

:nodoc:


198
199
200
# File 'lib/jira/client.rb', line 198

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

#WatcherObject


242
243
244
# File 'lib/jira/client.rb', line 242

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

#WebhookObject


246
247
248
# File 'lib/jira/client.rb', line 246

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

#WorklogObject

:nodoc:


194
195
196
# File 'lib/jira/client.rb', line 194

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