Class: Skylight::Api::ConfigValidationResults Private

Inherits:
Object
  • Object
show all
Includes:
Util::Logging
Defined in:
lib/skylight/api.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Logging

#config_for_logging, #debug, #error, #fmt, #info, #log, #log_context, #raise_on_error?, #t, #trace, #trace?, #warn

Constructor Details

#initialize(config, raw_response) ⇒ ConfigValidationResults

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConfigValidationResults.



50
51
52
53
# File 'lib/skylight/api.rb', line 50

def initialize(config, raw_response)
  @config = config
  @raw_response = raw_response
end

Instance Attribute Details

#raw_responseObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/skylight/api.rb', line 48

def raw_response
  @raw_response
end

Instance Method Details

#bodyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
70
71
72
# File 'lib/skylight/api.rb', line 63

def body
  return nil if error_response?

  unless raw_response.body.is_a?(Hash)
    warn("Unable to parse server response: status=%s, body=%s", raw_response.status, raw_response.body)
    return {}
  end

  raw_response.body
end

#config_valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/skylight/api.rb', line 87

def config_valid?
  # Only assume config is good if we have positive confirmation
  raw_response.success?
end

#corrected_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
105
106
# File 'lib/skylight/api.rb', line 102

def corrected_config
  return nil if config_valid? || !body

  body["corrected"]
end

#error_response?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


55
56
57
# File 'lib/skylight/api.rb', line 55

def error_response?
  raw_response.is_a?(Util::HTTP::ErrorResponse) || status > 499
end

#forbidden?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


92
93
94
# File 'lib/skylight/api.rb', line 92

def forbidden?
  status == 403
end

#statusObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
# File 'lib/skylight/api.rb', line 59

def status
  raw_response.status
end

#token_valid?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/skylight/api.rb', line 74

def token_valid?
  # Don't prevent boot if it's an error response, so assume token is valid
  return true if error_response?

  # A 2xx response means everything is good!
  return true if raw_response.success?
  return false if status == 401

  # A 403/422 means an invalid config,
  # but the token must be valid if we got this far
  true
end

#validation_errorsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



96
97
98
99
100
# File 'lib/skylight/api.rb', line 96

def validation_errors
  return {} if config_valid? || !body

  body["errors"]
end