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
:ca_file            => 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)


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

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)



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

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)



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

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)



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

def http_debug
  @http_debug
end

#optionsObject (readonly)

The configuration options for this client instance



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

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)



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

def request_client
  @request_client
end

Instance Method Details

#AgileObject



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

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


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

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

#AttachmentObject

:nodoc:



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

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

#BoardObject



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

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

#BoardConfigurationObject



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

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

#CommentObject

:nodoc:



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

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

#ComponentObject

:nodoc:



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

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

#CreatemetaObject



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

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

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

HTTP methods without a body



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

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

#FieldObject

:nodoc:



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

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

#FilterObject

:nodoc:



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

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

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



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

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

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



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

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

#inspectObject

Stops sensitive client information from being displayed in logs



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

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

#IssueObject

:nodoc:



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

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


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

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

#IssuelinktypeObject



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

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

#IssuePickerSuggestionsObject



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

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

#IssuetypeObject

:nodoc:



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

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

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

HTTP methods with a body



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

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



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

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

#PriorityObject

:nodoc:



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

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

#ProjectObject

:nodoc:



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

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

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



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

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

#RapidViewObject



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

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


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

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



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

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:



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

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

#ServerInfoObject



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

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

#SprintObject



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

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

#SprintReportObject



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

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

#StatusObject

:nodoc:



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

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

#TransitionObject

:nodoc:



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

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

#UserObject

:nodoc:



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

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

#VersionObject

:nodoc:



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

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

#WatcherObject



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

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

#WebhookObject



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

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

#WorklogObject

:nodoc:



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

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