Module: LabClient::ClientHelpers
- Included in:
- Client
- Defined in:
- lib/labclient/client/helpers.rb
Overview
Reader Methods / Accessor Helpers
Instance Method Summary collapse
- #api_methods ⇒ Object
- #base_url ⇒ Object
- #debug? ⇒ Boolean
-
#debug_handler ⇒ Object
Debug Print Output.
- #delay_factor ⇒ Object
- #help(help_filter = nil) ⇒ Object
- #home_file ⇒ Object
-
#profile ⇒ Object
Easier Profile Name Access.
- #quiet? ⇒ Boolean
-
#retry_after ⇒ Object
Helper for Accessing the Retry Headers.
- #retry_debug_headers ⇒ Object
- #retry_header ⇒ Object
- #retry_max ⇒ Object
-
#retry_max? ⇒ Boolean
Maximum Retries.
-
#retry_update ⇒ Object
On Successfully response lower delay Prevent multiple request / delays.
-
#save_client ⇒ Object
Instance Variable Helpers.
- #save_path ⇒ Object
-
#should_retry? ⇒ Boolean
Handle Retry Logic 1.
Instance Method Details
#api_methods ⇒ Object
5 6 7 |
# File 'lib/labclient/client/helpers.rb', line 5 def api_methods subclasses.keys.sort end |
#base_url ⇒ Object
48 49 50 |
# File 'lib/labclient/client/helpers.rb', line 48 def base_url "#{settings[:url]}/api/v4/" end |
#debug? ⇒ Boolean
56 57 58 |
# File 'lib/labclient/client/helpers.rb', line 56 def debug? settings[:debug] end |
#debug_handler ⇒ Object
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 = resp.request. logger.debug( [:method].to_s.upcase, code: resp.code, path: path, ssl_verify: [:ssl_verifyhost], message: resp., klass: klass.to_s, base_url: resp.request.base_url ) end |
#delay_factor ⇒ Object
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_file ⇒ Object
26 27 28 |
# File 'lib/labclient/client/helpers.rb', line 26 def home_file "#{ENV['HOME']}/.gitlab-labclient" end |
#profile ⇒ Object
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
52 53 54 |
# File 'lib/labclient/client/helpers.rb', line 52 def quiet? settings[:quiet] end |
#retry_after ⇒ Object
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_headers ⇒ Object
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_header ⇒ Object
100 101 102 |
# File 'lib/labclient/client/helpers.rb', line 100 def retry_header resp.headers['retry-after']&.to_i end |
#retry_max ⇒ Object
64 65 66 |
# File 'lib/labclient/client/helpers.rb', line 64 def retry_max settings[:retry][:max] end |
#retry_max? ⇒ Boolean
Maximum Retries
69 70 71 |
# File 'lib/labclient/client/helpers.rb', line 69 def retry_max? retries >= retry_max end |
#retry_update ⇒ Object
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_client ⇒ Object
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_path ⇒ Object
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
-
If response merits a retry
-
Retry is enabled
-
Retry Sleep Max isn’t hit
112 113 114 |
# File 'lib/labclient/client/helpers.rb', line 112 def should_retry? resp.retry? && settings[:retry] && !retry_max? end |