コード例 #1
0
        /// <summary>
        /// Return the tracking information of the last checkpoint of a single tracking
        /// </summary>
        /// <param name="tracking"> A Tracking to get the last checkpoint of, it should have tracking number and slug at least.</param>
        /// <param name="fields"> A list of fields of checkpoint wanted to be in the response</param>
        /// <param name="lang"> A String with the language desired. Support Chinese to English translation
        ///                      for china-ems and china-post only</param>
        /// <returns>The last Checkpoint object</returns>

        public Checkpoint getLastCheckpoint(Tracking tracking, List <FieldCheckpoint> fields, String lang)
        {
            String      parameters = null;
            QueryString qs         = new QueryString();

            if (fields != null)
            {
                qs.add("fields", string.Join(",", fields));
            }
            if (lang != null && !lang.Equals(""))
            {
                qs.add("lang", lang);
            }
            parameters = this.replaceFirst(qs.ToString(), "&", "?");

            String parametersExtra = "";

            if (tracking.id != null && !tracking.id.Equals(""))
            {
                parametersExtra = tracking.id + parameters;
            }
            else
            {
                String paramRequiredFields = tracking.getQueryRequiredFields();
                parametersExtra = tracking.slug + "/" + tracking.trackingNumber + parameters + paramRequiredFields;
            }

            JObject response = this.request("GET", "/last_checkpoint/" + parametersExtra, null);

            JObject    checkpointJSON = (JObject)response["data"]["checkpoint"];
            Checkpoint checkpoint     = null;

            if (checkpointJSON.Count != 0)
            {
                checkpoint = new Checkpoint(checkpointJSON);
            }

            return(checkpoint);
        }
コード例 #2
0
        /// <summary>
        /// Retrack an expired tracking once
        /// </summary>
        /// <param name="tracking"> tracking A Tracking to reactivate, it should have tracking number and slug at least.</param>
        /// <param name="fields"> A list of fields of checkpoint wanted to be in the response</param>
        /// <param name="lang"> A String with the language desired. Support Chinese to English translation
        ///                      for china-ems and china-post only</param>
        /// <returns> A JSONObject with the response. It will contain the status code of the operation, trackingNumber,
        ///         slug and active (to true)</returns>

        public bool retrack(Tracking tracking)
        {
            String paramRequiredFields = this.replaceFirst(tracking.getQueryRequiredFields(), "&", "?");

            JObject response = this.request("POST", "/trackings/" + tracking.slug +
                                            "/" + tracking.trackingNumber + "/retrack" + paramRequiredFields, null);

            if ((int)response["meta"]["code"] == 200)
            {
                if ((bool)response["data"]["tracking"]["active"])
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }