Class: Terjira::Client::Base

Inherits:
Object
  • Object
show all
Extended by:
AuthOptionBuilder, JQLBuilder
Defined in:
lib/terjira/client/base.rb

Overview

Abstract class to delegate jira-ruby resource class

Constant Summary collapse

DEFAULT_CACHE_SEC =
60
DEFAULT_API_PATH =
'/rest/api/2/'.freeze
AGILE_API_PATH =
'/rest/agile/1.0/'.freeze

Constants included from JQLBuilder

JQLBuilder::SEARCH_KEYS, JQLBuilder::STRICT_KEYS

Constants included from AuthOptionBuilder

AuthOptionBuilder::AUTH_CACHE_KEY

Class Method Summary collapse

Methods included from JQLBuilder

build_jql

Methods included from AuthOptionBuilder

auth_file_cache, build_auth_options, build_auth_options_by_cached, build_auth_options_by_tty, expire_auth_options

Class Method Details

.cache(options = {}) ⇒ Object



39
40
41
42
# File 'lib/terjira/client/base.rb', line 39

def cache(options = {})
  options[:expiry] ||= DEFAULT_CACHE_SEC
  @cache ||= Terjira::FileCache.new(class_name, expiry)
end

.class_nameObject



35
36
37
# File 'lib/terjira/client/base.rb', line 35

def class_name
  to_s.split('::').last
end

.clientObject



18
19
20
# File 'lib/terjira/client/base.rb', line 18

def client
  @client ||= JIRA::Client.new(build_auth_options)
end

.parse_body(response) ⇒ Object



68
69
70
# File 'lib/terjira/client/base.rb', line 68

def parse_body(response)
  JSON.parse(response.body) if response.body.present?
end

.resourceObject



22
23
24
# File 'lib/terjira/client/base.rb', line 22

def resource
  client.send(class_name) if client.respond_to?(class_name)
end

.site_urlObject



26
27
28
29
# File 'lib/terjira/client/base.rb', line 26

def site_url
  auth_options = build_auth_options
  "#{auth_options[:site]}/#{auth_options[:context_path]}"
end

.usernameObject



31
32
33
# File 'lib/terjira/client/base.rb', line 31

def username
  client.options[:username]
end