Class: JIRA::Client
- Inherits:
-
Object
- Object
- JIRA::Client
- 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, :enable_caching => false, :cache_ttl => 86400000 # 1 day }
Instance Attribute Summary collapse
-
#consumer ⇒ Object
The OAuth::Consumer instance returned by the OauthClient.
-
#options ⇒ Object
readonly
The configuration options for this client instance.
-
#request_client ⇒ Object
The OAuth::Consumer instance returned by the OauthClient.
Instance Method Summary collapse
-
#Agileboard ⇒ Object
:nodoc:.
-
#Attachment ⇒ Object
:nodoc:.
-
#Comment ⇒ Object
:nodoc:.
-
#Component ⇒ Object
:nodoc:.
-
#delete(path, headers = {}) ⇒ Object
HTTP methods without a body.
-
#Field ⇒ Object
:nodoc:.
-
#Filter ⇒ Object
:nodoc:.
- #get(path, headers = {}) ⇒ Object
- #get_from_cache(path, headers) ⇒ Object
- #head(path, headers = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#Issue ⇒ Object
:nodoc:.
-
#Issuetype ⇒ Object
:nodoc:.
-
#post(path, body = '', headers = {}) ⇒ Object
HTTP methods with a body.
-
#Priority ⇒ Object
:nodoc:.
-
#Project ⇒ Object
:nodoc:.
- #put(path, body = '', headers = {}) ⇒ Object
-
#request(http_method, path, body = '', headers = {}) ⇒ Object
Sends the specified HTTP request to the REST API through the appropriate method (oauth, basic).
-
#Sprint ⇒ Object
:nodoc:.
-
#SprintReport ⇒ Object
:nodoc:.
-
#Status ⇒ Object
:nodoc:.
-
#Transition ⇒ Object
:nodoc:.
-
#User ⇒ Object
:nodoc:.
-
#Version ⇒ Object
:nodoc:.
-
#Worklog ⇒ Object
:nodoc:.
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 |
# File 'lib/jira/client.rb', line 58 def initialize(={}) = DEFAULT_OPTIONS.merge() = [:rest_base_path] = [:context_path] + [:rest_base_path] case [:auth_type] when :oauth @request_client = OauthClient.new() @consumer = @request_client.consumer when :basic @request_client = HttpClient.new() end @cache = JIRA::RequestCache.new([:cache_ttl]) .freeze end |
Instance Attribute Details
#consumer ⇒ Object
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 |
#options ⇒ Object (readonly)
The configuration options for this client instance
43 44 45 |
# File 'lib/jira/client.rb', line 43 def end |
#request_client ⇒ Object
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
#Agileboard ⇒ Object
:nodoc:
136 137 138 |
# File 'lib/jira/client.rb', line 136 def Agileboard # :nodoc: JIRA::Resource::AgileboardFactory.new(self) end |
#Attachment ⇒ Object
:nodoc:
112 113 114 |
# File 'lib/jira/client.rb', line 112 def Attachment # :nodoc: JIRA::Resource::AttachmentFactory.new(self) end |
#Comment ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/jira/client.rb', line 108 def Comment # :nodoc: JIRA::Resource::CommentFactory.new(self) end |
#Component ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/jira/client.rb', line 88 def Component # :nodoc: JIRA::Resource::ComponentFactory.new(self) end |
#delete(path, headers = {}) ⇒ Object
HTTP methods without a body
145 146 147 |
# File 'lib/jira/client.rb', line 145 def delete(path, headers = {}) request(:delete, path, nil, merge_default_headers(headers)) end |
#Field ⇒ Object
:nodoc:
128 129 130 |
# File 'lib/jira/client.rb', line 128 def Field # :nodoc: JIRA::Resource::FieldFactory.new(self) end |
#Filter ⇒ Object
:nodoc:
84 85 86 |
# File 'lib/jira/client.rb', line 84 def Filter # :nodoc: JIRA::Resource::FilterFactory.new(self) end |
#get(path, headers = {}) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/jira/client.rb', line 149 def get(path, headers = {}) if [:enable_caching] get_from_cache(path, headers) else request(:get, path, nil, merge_default_headers(headers)) end end |
#get_from_cache(path, headers) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/jira/client.rb', line 157 def get_from_cache(path, headers) cached_response = @cache.load(path) if cached_response == nil response = request(:get, path, nil, merge_default_headers(headers)) @cache.save(path, Marshal.dump(response)) else response = Marshal.restore(cached_response) end response end |
#head(path, headers = {}) ⇒ Object
171 172 173 |
# File 'lib/jira/client.rb', line 171 def head(path, headers = {}) request(:head, path, nil, merge_default_headers(headers)) end |
#Issue ⇒ Object
:nodoc:
80 81 82 |
# File 'lib/jira/client.rb', line 80 def Issue # :nodoc: JIRA::Resource::IssueFactory.new(self) end |
#Issuetype ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/jira/client.rb', line 96 def Issuetype # :nodoc: JIRA::Resource::IssuetypeFactory.new(self) end |
#post(path, body = '', headers = {}) ⇒ Object
HTTP methods with a body
176 177 178 179 |
# File 'lib/jira/client.rb', line 176 def post(path, body = '', headers = {}) headers = {'Content-Type' => 'application/json'}.merge(headers) request(:post, path, body, merge_default_headers(headers)) end |
#Priority ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/jira/client.rb', line 100 def Priority # :nodoc: JIRA::Resource::PriorityFactory.new(self) end |
#Project ⇒ Object
:nodoc:
76 77 78 |
# File 'lib/jira/client.rb', line 76 def Project # :nodoc: JIRA::Resource::ProjectFactory.new(self) end |
#put(path, body = '', headers = {}) ⇒ Object
181 182 183 184 |
# File 'lib/jira/client.rb', line 181 def put(path, body = '', headers = {}) headers = {'Content-Type' => 'application/json'}.merge(headers) request(:put, path, body, merge_default_headers(headers)) end |
#request(http_method, path, body = '', headers = {}) ⇒ Object
Sends the specified HTTP request to the REST API through the appropriate method (oauth, basic).
188 189 190 |
# File 'lib/jira/client.rb', line 188 def request(http_method, path, body = '', headers={}) @request_client.request(http_method, path, body, headers) end |
#Sprint ⇒ Object
:nodoc:
132 133 134 |
# File 'lib/jira/client.rb', line 132 def Sprint # :nodoc: JIRA::Resource::SprintFactory.new(self) end |
#SprintReport ⇒ Object
:nodoc:
140 141 142 |
# File 'lib/jira/client.rb', line 140 def SprintReport # :nodoc: JIRA::Resource::SprintReportFactory.new(self) end |
#Status ⇒ Object
:nodoc:
104 105 106 |
# File 'lib/jira/client.rb', line 104 def Status # :nodoc: JIRA::Resource::StatusFactory.new(self) end |
#Transition ⇒ Object
:nodoc:
124 125 126 |
# File 'lib/jira/client.rb', line 124 def Transition # :nodoc: JIRA::Resource::TransitionFactory.new(self) end |
#User ⇒ Object
:nodoc:
92 93 94 |
# File 'lib/jira/client.rb', line 92 def User # :nodoc: JIRA::Resource::UserFactory.new(self) end |
#Version ⇒ Object
:nodoc:
120 121 122 |
# File 'lib/jira/client.rb', line 120 def Version # :nodoc: JIRA::Resource::VersionFactory.new(self) end |
#Worklog ⇒ Object
:nodoc:
116 117 118 |
# File 'lib/jira/client.rb', line 116 def Worklog # :nodoc: JIRA::Resource::WorklogFactory.new(self) end |