Sha256: 913a8083424152a2d10f2649e7f9bc5f963bd3d655de47257055f3883b58ac03
Contents?: true
Size: 1.33 KB
Versions: 6
Compression:
Stored size: 1.33 KB
Contents
module TryApi class ExampleResponse < TryApi::Base typesafe_accessor :code, Integer typesafe_accessor :response, String typesafe_accessor :type, String typesafe_accessor :project, TryApi::Project class << self def parse(hash:, project:) return nil if hash.blank? instance = self.new instance.code = hash[:code] instance.project = project instance.response = hash[:response] instance.type = hash[:type] instance end def descriptions { 200 => :success, 401 => :unauthorized, 422 => :unprocessable_entity, 500 => :internal_server_error, } end end def description self.class.descriptions[self.code].to_s.humanize end def color case self.code when 200 'success' when 200...300 'info' when 300...400 'warning' when 400...500 'warning' when 500 'danger' else 'default' end end def to_json super.merge color: color, description: description, isCollapsed: true end def response=(input) if input['var:'] @response = self.project.variables[input.gsub('var:', '')] else @response = input end end end end
Version data entries
6 entries across 6 versions & 1 rubygems