Sha256: 6a5460d013a74cacdf7c628ef1862a68606fbc9f20cfcc447cc11bb9136f00a3
Contents?: true
Size: 949 Bytes
Versions: 89
Compression:
Stored size: 949 Bytes
Contents
# frozen_string_literal: true # # Reusable API methods # module RestfulController # # Render a JSON response with the results and status passed in. The payload will include # an SHA1 hash along with the response for validation. # def render_json_response(success = true, results = {}, status_code = :ok) results[:success] = success render status: status_code, json: { results: results, md5: hash(unescape_unicode(results.to_json)) }.to_json, layout: false end # # Convert UTF-8 unicode/escaped back to actual double byte character # def unescape_unicode(str) str.gsub(/\\u([\da-fA-F]{4})/) do |_m| [Regexp.last_match[1]].pack('H*').unpack('n*').pack('U*') end end # # Create a hash of the string contents # def hash(str) if SystemConfiguration.fips_mode? Digest::SHA2.hexdigest(str) else Digest::MD5.hexdigest(str) end end end
Version data entries
89 entries across 89 versions & 1 rubygems