def format_payload(payload, as: JSON_CONTENT_TYPE)
      ## Non-Hash payloads are passed through as-is.
      return payload unless payload.is_a? Hash

      ## Massage Hash-like payloads into a suitable format.
      case as
      when JSON_CONTENT_TYPE
        JSON.generate(payload.as_json)
      when FORM_CONTENT_TYPE
        payload.to_query
      else
        payload.to_s
      end
    end
def format_payload(payload, as: JSON_CONTENT_TYPE)
      ## Non-Hash payloads are passed through as-is.
      return payload unless payload.is_a? Hash

      ## Massage Hash-like payloads into a suitable format.
      case as
      when JSON_CONTENT_TYPE
        JSON.generate(payload.as_json)
      when FORM_CONTENT_TYPE
        payload.to_query
      else
        payload.to_s
      end
    end
Serializes the given payload per the requested content-type.


 @param payload [Hash, String]
   The payload to format. Strings are returned as-is; Hashes are serialized per the given *as*
   content-type.

 @param as [String]
   The target content-type.


 @return [String]