Example #1
0
        /// <inheritdoc />
        public string ToString(BatchObjectAction batchObjectAction)
        {
            JObject outterObject = new JObject();

            outterObject.Add(this.ProcessBatchObjectAction(batchObjectAction));
            return(outterObject.ToString());
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        /// <inheritdoc />
        public string ToString(BatchObjectAction batchObjectAction)
        {
            JObject outerObject = new JObject
            {
                this.ProcessBatchObjectAction(batchObjectAction)
            };

            return(outerObject.ToString());
        }