コード例 #1
0
        public static string SerializeObjectToPrettyJson(BaseRequestV2 value)
        {
            StringBuilder sb = new StringBuilder(256);
            StringWriter  sw = new StringWriter(sb, CultureInfo.InvariantCulture);

            var jsonSerializer = JsonSerializer.CreateDefault();

            jsonSerializer.NullValueHandling    = NullValueHandling.Ignore;
            jsonSerializer.DefaultValueHandling = DefaultValueHandling.Ignore;
            jsonSerializer.ContractResolver     = new CamelCasePropertyNamesContractResolver();
            jsonSerializer.Formatting           = Formatting.Indented;

            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw)
            {
                Formatting = Formatting.Indented,
                IndentChar = '\t',
                Indentation = 1
            })
            {
                jsonSerializer.Serialize(jsonWriter, value, typeof(BaseRequestV2));
            }

            string json = sw.ToString();

            return(json.Replace("\r", ""));
        }
コード例 #2
0
        private static string PrepareAuthorizationStringWithRequestBody(BaseRequestV2 request, string url, Options options)
        {
            string randomKey     = GenerateRandomKey();
            string uriPath       = FindUriPath(url);
            string payload       = request != null ? uriPath + JsonBuilder.SerializeObjectToPrettyJson(request) : uriPath;
            string dataToEncrypt = randomKey + payload;
            string hash          = HashGeneratorV2.GenerateHash(options.ApiKey, options.SecretKey, randomKey, dataToEncrypt);

            return(IYZIWS_V2_HEADER_NAME + hash);
        }
コード例 #3
0
 public static string SerializeToJsonString(BaseRequestV2 request)
 {
     return(JsonConvert.SerializeObject(request, new JsonSerializerSettings
     {
         Formatting = Formatting.None,
         NullValueHandling = NullValueHandling.Ignore,
         DefaultValueHandling = DefaultValueHandling.Ignore,
         ContractResolver = new CamelCasePropertyNamesContractResolver()
     }));
 }
コード例 #4
0
        protected static WebHeaderCollection GetHttpHeadersWithUrlParams(BaseRequestV2 request, string url, Options options)
        {
            WebHeaderCollection headers = GetCommonHttpHeaders(request);
            string authHeader           = PrepareAuthorizationStringWithUrlParam(url, options);

#if NETSTANDARD
            headers[Constants.AUTHORIZATION] = authHeader;
#else
            headers.Add(Constants.AUTHORIZATION, authHeader);
#endif
            return(headers);
        }
コード例 #5
0
        private static WebHeaderCollection GetCommonHttpHeaders(BaseRequestV2 request)
        {
            WebHeaderCollection headers = new WebHeaderCollection();

#if NETSTANDARD
            headers["Accept"] = "application/json";
            headers[Constants.CLIENT_VERSION_HEADER] = Constants.CLIENT_VERSION;
            headers[CONVERSATION_ID_HEADER_NAME]     = request.ConversationId;
#else
            headers.Add("Accept", "application/json");
            headers.Add(Constants.CLIENT_VERSION_HEADER, Constants.CLIENT_VERSION);
            headers.Add(CONVERSATION_ID_HEADER_NAME, request.ConversationId);
#endif
            return(headers);
        }
コード例 #6
0
 public static StringContent ToJsonString(BaseRequestV2 request)
 {
     return(new StringContent(SerializeObjectToPrettyJson(request), Encoding.UTF8, "application/json"));
 }
コード例 #7
0
 public static StringContent ToJsonString(BaseRequestV2 request)
 {
     return(new StringContent(SerializeToJsonString(request), Encoding.Unicode, "application/json"));
 }