class JIRA::OauthClient
Constants
- DEFAULT_OPTIONS
Attributes
consumer[RW]
options[R]
Public Class Methods
new(options)
click to toggle source
# File lib/jira/oauth_client.rb, line 33 def initialize(options) @options = DEFAULT_OPTIONS.merge(options) @consumer = init_oauth_consumer(@options) end
Public Instance Methods
access_token()
click to toggle source
Returns the current access token. Raises an JIRA::Client::UninitializedAccessTokenError exception if it is not set.
# File lib/jira/oauth_client.rb, line 71 def access_token raise UninitializedAccessTokenError.new unless @access_token @access_token end
authenticated?()
click to toggle source
# File lib/jira/oauth_client.rb, line 99 def authenticated? @authenticated end
init_access_token(params)
click to toggle source
Initialises and returns a new access token from the params hash returned by the OAuth transaction.
# File lib/jira/oauth_client.rb, line 58 def init_access_token(params) @access_token = request_token.get_access_token(params) end
init_oauth_consumer(options)
click to toggle source
# File lib/jira/oauth_client.rb, line 38 def init_oauth_consumer(options) @options[:request_token_path] = @options[:context_path] + @options[:request_token_path] @options[:authorize_path] = @options[:context_path] + @options[:authorize_path] @options[:access_token_path] = @options[:context_path] + @options[:access_token_path] OAuth::Consumer.new(@options[:consumer_key],@options[:consumer_secret],@options) end
make_request(http_method, path, body='', headers={})
click to toggle source
# File lib/jira/oauth_client.rb, line 76 def make_request(http_method, path, body='', headers={}) # When using oauth_2legged we need to add an empty oauth_token parameter to every request. if @options[:auth_type] == :oauth_2legged oauth_params_str = "oauth_token=" uri = URI.parse(path) if uri.query.to_s == "" uri.query = oauth_params_str else uri.query = uri.query + "&" + oauth_params_str end path = uri.to_s end case http_method when :delete, :get, :head response = access_token.send http_method, path, headers when :post, :put response = access_token.send http_method, path, body, headers end @authenticated = true response end
request_token(options = {}, *arguments, &block)
click to toggle source
Returns the current request token if it is set, else it creates and sets a new token.
# File lib/jira/oauth_client.rb, line 47 def request_token(options = {}, *arguments, &block) @request_token ||= get_request_token(options, *arguments, block) end
set_access_token(token, secret)
click to toggle source
Sets the access token from a preexisting token and secret.
# File lib/jira/oauth_client.rb, line 63 def set_access_token(token, secret) @access_token = OAuth::AccessToken.new(@consumer, token, secret) @authenticated = true @access_token end
set_request_token(token, secret)
click to toggle source
Sets the request token from a given token and secret.
# File lib/jira/oauth_client.rb, line 52 def set_request_token(token, secret) @request_token = OAuth::RequestToken.new(@consumer, token, secret) end