Sha256: 21611ed899796823cae4e7c97cc9e495263391951fbef69afd38e14fb4da9051
Contents?: true
Size: 857 Bytes
Versions: 17
Compression:
Stored size: 857 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 MD5 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) Digest::MD5.hexdigest(str) end end
Version data entries
17 entries across 17 versions & 1 rubygems