Module: LabClient::ClientHelpers

Included in:
Client
Defined in:
lib/labclient/client/helpers.rb

Overview

Reader Methods / Accessor Helpers

Instance Method Summary collapse

Instance Method Details

#api_methodsObject



5
6
7
# File 'lib/labclient/client/helpers.rb', line 5

def api_methods
  subclasses.keys.sort
end

#base_urlObject



48
49
50
# File 'lib/labclient/client/helpers.rb', line 48

def base_url
  "#{settings[:url]}/api/v4/"
end

#debug?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/labclient/client/helpers.rb', line 56

def debug?
  settings[:debug]
end

#debug_handlerObject

Debug Print Output



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/labclient/client/helpers.rb', line 81

def debug_handler
  options = resp.request.options

  logger.debug(
    options[:method].to_s.upcase,
    code: resp.code,
    path: path,
    ssl_verify: options[:ssl_verifyhost],
    message: resp.return_message,
    klass: klass.to_s,
    base_url: resp.request.base_url
  )
end

#delay_factorObject



60
61
62
# File 'lib/labclient/client/helpers.rb', line 60

def delay_factor
  settings[:retry][:delay_factor]
end

#help(help_filter = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/labclient/client/helpers.rb', line 9

def help(help_filter = nil)
  puts 'Available Methods'

  shown_subclasses = if help_filter
                       api_methods.grep(/#{help_filter}/)
                     else
                       api_methods
                     end

  puts " - #{shown_subclasses.join(' ')}\n\n"
  puts "See help for each specific sub-category\n"
  puts "- client.users.help\n"
  puts "- client.users.api_methods\n"

  nil
end

#home_fileObject



26
27
28
# File 'lib/labclient/client/helpers.rb', line 26

def home_file
  "#{ENV['HOME']}/.gitlab-labclient"
end

#profileObject

Easier Profile Name Access



31
32
33
34
35
36
37
# File 'lib/labclient/client/helpers.rb', line 31

def profile
  if settings&.key? :profile
    settings[:profile].to_sym
  else
    ENV['LABCLIENT_PROFILE'].to_sym
  end
end

#quiet?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/labclient/client/helpers.rb', line 52

def quiet?
  settings[:quiet]
end

#retry_afterObject

Helper for Accessing the Retry Headers



96
97
98
# File 'lib/labclient/client/helpers.rb', line 96

def retry_after
  retry_header || delay_factor || 1
end

#retry_debug_headersObject



104
105
106
# File 'lib/labclient/client/helpers.rb', line 104

def retry_debug_headers
  resp.headers.select { |k, _v| k.include? 'ratelimit' }
end

#retry_headerObject



100
101
102
# File 'lib/labclient/client/helpers.rb', line 100

def retry_header
  resp.headers['retry-after']&.to_i
end

#retry_maxObject



64
65
66
# File 'lib/labclient/client/helpers.rb', line 64

def retry_max
  settings[:retry][:max]
end

#retry_max?Boolean

Maximum Retries

Returns:

  • (Boolean)


69
70
71
# File 'lib/labclient/client/helpers.rb', line 69

def retry_max?
  retries >= retry_max
end

#retry_updateObject

On Successfully response lower delay Prevent multiple request / delays



75
76
77
78
# File 'lib/labclient/client/helpers.rb', line 75

def retry_update
  self.delay = [delay - 1, 1].max
  self.retries = [retries - 1, 0].max
end

#save_clientObject

Instance Variable Helpers



40
41
42
# File 'lib/labclient/client/helpers.rb', line 40

def save_client
  resp.instance_variable_set(:@client, self)
end

#save_pathObject



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

def save_path
  resp.instance_variable_set(:@path, path)
end

#should_retry?Boolean

Handle Retry Logic

  1. If response merits a retry

  2. Retry is enabled

  3. Retry Sleep Max isn’t hit

Returns:

  • (Boolean)


112
113
114
# File 'lib/labclient/client/helpers.rb', line 112

def should_retry?
  resp.retry? && settings[:retry] && !retry_max?
end