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 a consumer_key and consumer secret, and an optional hash of extra 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"
See the JIRA::Base class methods for all of the available methods on these accessor objects.
Defined Under Namespace
Classes: UninitializedAccessTokenError
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :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" }
Instance Attribute Summary collapse
-
#consumer ⇒ Object
The OAuth::Consumer instance used by this client.
-
#options ⇒ Object
readonly
The configuration options for this client instance.
Instance Method Summary collapse
-
#access_token ⇒ Object
Returns the current access token.
-
#Attachment ⇒ Object
:nodoc:.
-
#Comment ⇒ Object
:nodoc:.
-
#Component ⇒ Object
:nodoc:.
-
#delete(path, headers = {}) ⇒ Object
HTTP methods without a body.
- #get(path, headers = {}) ⇒ Object
- #head(path, headers = {}) ⇒ Object
-
#init_access_token(params) ⇒ Object
Initialises and returns a new access token from the params hash returned by the OAuth transaction.
-
#initialize(consumer_key, consumer_secret, 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, *arguments) ⇒ Object
Sends the specified HTTP request to the REST API through the OAuth token.
-
#request_token ⇒ Object
Returns the current request token if it is set, else it creates and sets a new token.
-
#set_access_token(token, secret) ⇒ Object
Sets the access token from a preexisting token and secret.
-
#set_request_token(token, secret) ⇒ Object
Sets the request token from a given token and secret.
-
#Status ⇒ Object
:nodoc:.
-
#User ⇒ Object
:nodoc:.
-
#Version ⇒ Object
:nodoc:.
-
#Worklog ⇒ Object
:nodoc:.
Constructor Details
#initialize(consumer_key, consumer_secret, options = {}) ⇒ Client
Returns a new instance of Client.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/jira/client.rb', line 57 def initialize(consumer_key, consumer_secret, ={}) = DEFAULT_OPTIONS.merge() # prepend the context path to all authorization and rest paths [:request_token_path] = [:context_path] + [:request_token_path] [:authorize_path] = [:context_path] + [:authorize_path] [:access_token_path] = [:context_path] + [:access_token_path] [:rest_base_path] = [:context_path] + [:rest_base_path] @options = @options.freeze @consumer = OAuth::Consumer.new(consumer_key,consumer_secret,) end |
Instance Attribute Details
#consumer ⇒ Object
The OAuth::Consumer instance used by this client
39 40 41 |
# File 'lib/jira/client.rb', line 39 def consumer @consumer end |
#options ⇒ Object (readonly)
The configuration options for this client instance
42 43 44 |
# File 'lib/jira/client.rb', line 42 def @options end |
Instance Method Details
#access_token ⇒ Object
Returns the current access token. Raises an JIRA::Client::UninitializedAccessTokenError exception if it is not set.
139 140 141 142 |
# File 'lib/jira/client.rb', line 139 def access_token raise UninitializedAccessTokenError.new unless @access_token @access_token end |
#Attachment ⇒ Object
:nodoc:
103 104 105 |
# File 'lib/jira/client.rb', line 103 def Attachment # :nodoc: JIRA::Resource::AttachmentFactory.new(self) end |
#Comment ⇒ Object
:nodoc:
99 100 101 |
# File 'lib/jira/client.rb', line 99 def Comment # :nodoc: JIRA::Resource::CommentFactory.new(self) end |
#Component ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/jira/client.rb', line 79 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, merge_default_headers(headers)) end |
#get(path, headers = {}) ⇒ Object
148 149 150 |
# File 'lib/jira/client.rb', line 148 def get(path, headers = {}) request(:get, path, merge_default_headers(headers)) end |
#head(path, headers = {}) ⇒ Object
151 152 153 |
# File 'lib/jira/client.rb', line 151 def head(path, headers = {}) request(:head, path, merge_default_headers(headers)) end |
#init_access_token(params) ⇒ Object
Initialises and returns a new access token from the params hash returned by the OAuth transaction.
128 129 130 |
# File 'lib/jira/client.rb', line 128 def init_access_token(params) @access_token = request_token.get_access_token(params) end |
#Issue ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/jira/client.rb', line 75 def Issue # :nodoc: JIRA::Resource::IssueFactory.new(self) end |
#Issuetype ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/jira/client.rb', line 87 def Issuetype # :nodoc: JIRA::Resource::IssuetypeFactory.new(self) end |
#post(path, body = '', headers = {}) ⇒ Object
HTTP methods with a body
156 157 158 159 |
# File 'lib/jira/client.rb', line 156 def post(path, body = '', headers = {}) headers = {'Content-Type' => 'application/json'}.merge(headers) request(:post, path, body, merge_default_headers(headers)) end |
#Priority ⇒ Object
:nodoc:
91 92 93 |
# File 'lib/jira/client.rb', line 91 def Priority # :nodoc: JIRA::Resource::PriorityFactory.new(self) end |
#Project ⇒ Object
:nodoc:
71 72 73 |
# File 'lib/jira/client.rb', line 71 def Project # :nodoc: JIRA::Resource::ProjectFactory.new(self) end |
#put(path, body = '', headers = {}) ⇒ Object
160 161 162 163 |
# File 'lib/jira/client.rb', line 160 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, *arguments) ⇒ Object
Sends the specified HTTP request to the REST API through the OAuth token.
Returns the response if the request was successful (HTTP::2xx) and raises a JIRA::HTTPError if it was not successful, with the response attached.
171 172 173 174 175 |
# File 'lib/jira/client.rb', line 171 def request(http_method, path, *arguments) response = access_token.request(http_method, path, *arguments) raise HTTPError.new(response) unless response.kind_of?(Net::HTTPSuccess) response end |
#request_token ⇒ Object
Returns the current request token if it is set, else it creates and sets a new token.
117 118 119 |
# File 'lib/jira/client.rb', line 117 def request_token @request_token ||= get_request_token end |
#set_access_token(token, secret) ⇒ Object
Sets the access token from a preexisting token and secret.
133 134 135 |
# File 'lib/jira/client.rb', line 133 def set_access_token(token, secret) @access_token = OAuth::AccessToken.new(@consumer, token, secret) end |
#set_request_token(token, secret) ⇒ Object
Sets the request token from a given token and secret.
122 123 124 |
# File 'lib/jira/client.rb', line 122 def set_request_token(token, secret) @request_token = OAuth::RequestToken.new(@consumer, token, secret) end |
#Status ⇒ Object
:nodoc:
95 96 97 |
# File 'lib/jira/client.rb', line 95 def Status # :nodoc: JIRA::Resource::StatusFactory.new(self) end |
#User ⇒ Object
:nodoc:
83 84 85 |
# File 'lib/jira/client.rb', line 83 def User # :nodoc: JIRA::Resource::UserFactory.new(self) end |
#Version ⇒ Object
:nodoc:
111 112 113 |
# File 'lib/jira/client.rb', line 111 def Version # :nodoc: JIRA::Resource::VersionFactory.new(self) end |
#Worklog ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/jira/client.rb', line 107 def Worklog # :nodoc: JIRA::Resource::WorklogFactory.new(self) end |