Sha256: a6c7a5fdd583f8455e9692d13e6f7c1f264ccdd3c7bf3bc7bff172ba330a44b3
Contents?: true
Size: 987 Bytes
Versions: 7
Compression:
Stored size: 987 Bytes
Contents
module TryApi class ExampleResponse < TryApi::Base typesafe_accessor :code, Integer typesafe_accessor :response, String typesafe_accessor :type, String class << self def parse(hash) return nil if hash.blank? instance = self.new instance.code = hash[:code] 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] 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 end end
Version data entries
7 entries across 7 versions & 1 rubygems