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

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,
  :http_debug         => false
}

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
# 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]

  case options[:auth_type]
  when :oauth
    @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
  else
    raise ArgumentError, 'Options: ":auth_type" must be ":oauth", ":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)



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

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)



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

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)



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

def http_debug
  @http_debug
end

#optionsObject (readonly)

The configuration options for this client instance



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

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)



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

def request_client
  @request_client
end

Instance Method Details

#AgileObject



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

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


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

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

#AttachmentObject

:nodoc:



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

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

#CommentObject

:nodoc:



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

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

#ComponentObject

:nodoc:



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

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

#CreatemetaObject



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

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

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

HTTP methods without a body



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

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

#FieldObject

:nodoc:



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

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

#FilterObject

:nodoc:



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

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

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



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

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

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



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

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

#IssueObject

:nodoc:



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

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


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

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

#IssuelinktypeObject



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

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

#IssuetypeObject

:nodoc:



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

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

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

HTTP methods with a body



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

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

#PriorityObject

:nodoc:



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

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

#ProjectObject

:nodoc:



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

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

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



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

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

#RapidViewObject



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

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


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

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



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

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:



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

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

#ServerInfoObject



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

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

#SprintObject



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

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

#StatusObject

:nodoc:



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

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

#TransitionObject

:nodoc:



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

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

#UserObject

:nodoc:



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

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

#VersionObject

:nodoc:



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

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

#WebhookObject



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

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

#WorklogObject

:nodoc:



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

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