/// <inheritdoc /> public string ToString(BatchObjectAction batchObjectAction) { JObject outterObject = new JObject(); outterObject.Add(this.ProcessBatchObjectAction(batchObjectAction)); return(outterObject.ToString()); }
private JProperty ProcessBatchObjectAction(BatchObjectAction action) { var actionContents = new JObject { new JProperty("href", action.HRef) }; if (action.Headers != null) { var headers = new JObject(); foreach (BatchHeader header in action.Headers) { var property = new JProperty(header.Key, header.Value); headers.Add(property); } actionContents["header"] = headers; } if (action.ExpiresIn != null) { actionContents.Add(new JProperty("expires_in", action.ExpiresIn)); } if (action.ExpiresAt != null) { actionContents.Add(new JProperty("expires_at", action.ExpiresAt.Value.ToUniversalTime())); } var actionToken = new JProperty(action.Mode.ToString().ToLowerInvariant(), actionContents); return(actionToken); }
private BatchObjectAction ProcessBatchObjectActionJson(JProperty actionToken) { var action = new BatchObjectAction(); if (Enum.TryParse(actionToken.Name, true, out BatchActionMode actionMode) == false) { throw new ParseException("Invalid action mode."); } action.Mode = actionMode; action.HRef = (string)actionToken.Value["href"]; action.ExpiresAt = (DateTime?)actionToken.Value["expires_at"]; action.ExpiresIn = (int?)actionToken.Value["expires_in"]; var headerToken = actionToken.Value["header"] as JObject; if (headerToken != null) { var headers = new List <BatchHeader>(); foreach (JProperty headerPair in headerToken.Cast <JProperty>()) { string key = headerPair.Name; var value = (string)headerPair.Value; headers.Add(new BatchHeader(key, value)); } action.Headers = headers; } return(action); }
/// <inheritdoc /> public string ToString(BatchObjectAction batchObjectAction) { JObject outerObject = new JObject { this.ProcessBatchObjectAction(batchObjectAction) }; return(outerObject.ToString()); }