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,
:proxy_address      => nil,
:proxy_port         => nil,
:additional_cookies => nil

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,
  use_client_cert: false,
  auth_type: :oauth,
  http_debug: false
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/jira/client.rb', line 58

def initialize(options = {})
  options = DEFAULT_OPTIONS.merge(options)
  @options = options
  @options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path]

  if options[:use_client_cert]
    raise ArgumentError, 'Options: :cert_path must be set when :use_client_cert is true' unless @options[:cert_path]
    raise ArgumentError, 'Options: :key_path must be set when :use_client_cert is true' unless @options[:key_path]
    @options[:cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path]))
    @options[:key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path]))
  end

  case options[:auth_type]
  when :oauth, :oauth_2legged
    @request_client = OauthClient.new(@options)
    @consumer = @request_client.consumer
  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)



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

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)



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

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)



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

def http_debug
  @http_debug
end

#optionsObject (readonly)

The configuration options for this client instance



43
44
45
# File 'lib/jira/client.rb', line 43

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)



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

def request_client
  @request_client
end

Instance Method Details

#AgileObject



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

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


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

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

#AttachmentObject

:nodoc:



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

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

#BoardObject



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

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

#CommentObject

:nodoc:



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

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

#ComponentObject

:nodoc:



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

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

#CreatemetaObject



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

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

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

HTTP methods without a body



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

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

#FieldObject

:nodoc:



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

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

#FilterObject

:nodoc:



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

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

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



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

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

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



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

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

#IssueObject

:nodoc:



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

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


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

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

#IssuelinktypeObject



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

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

#IssuetypeObject

:nodoc:



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

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

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

HTTP methods with a body



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

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

#PriorityObject

:nodoc:



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

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

#ProjectObject

:nodoc:



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

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

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



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

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

#RapidViewObject



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

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


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

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



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

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:



126
127
128
# File 'lib/jira/client.rb', line 126

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

#ServerInfoObject



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

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

#SprintObject



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

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

#SprintReportObject



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

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

#StatusObject

:nodoc:



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

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

#TransitionObject

:nodoc:



146
147
148
# File 'lib/jira/client.rb', line 146

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

#UserObject

:nodoc:



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

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

#VersionObject

:nodoc:



142
143
144
# File 'lib/jira/client.rb', line 142

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

#WatcherObject



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

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

#WebhookObject



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

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

#WorklogObject

:nodoc:



138
139
140
# File 'lib/jira/client.rb', line 138

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