Esempio n. 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>
        /// <returns>The last Checkpoint object</returns>
        public Checkpoint getLastCheckpoint(Tracking tracking)
        {
            String parametersExtra = "";

            if (tracking.id != null && !(tracking.id.Equals("")))
            {
                parametersExtra = tracking.id;
            }
            else
            {
                String paramRequiredFields = this.replaceFirst(tracking.getQueryRequiredFields(), "&", "?");
                parametersExtra = tracking.slug + "/" + tracking.trackingNumber + 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Get a specific tracking from your account. If the trackingGet.id property
        /// is defined it will get that tracking from the system, if not it will take
        /// the tracking tracking.number and the tracking.slug for identify the tracking
        /// </summary>
        /// <param name="trackingGet">A Tracking to get.</param></param>
        /// <returns> A Tracking object with the response</returns>

        public Tracking getTrackingByNumber(Tracking trackingGet)
        {
            String parametersExtra;

            if (trackingGet.id != null && !trackingGet.id.Equals(""))
            {
                parametersExtra = trackingGet.id;
            }
            else
            {
                //get the require fields if any (postal_code, tracking_account etc..)
                String paramRequiredFields = replaceFirst(trackingGet.getQueryRequiredFields(), "&", "?");
                parametersExtra = trackingGet.slug + "/" + trackingGet.trackingNumber +
                                  paramRequiredFields;
            }
            JObject  response     = request("GET", "/trackings/" + parametersExtra, null);
            JObject  trackingJSON = (JObject)response["data"]["tracking"];
            Tracking tracking     = null;

            if (trackingJSON.Count != 0)
            {
                tracking = new Tracking(trackingJSON);
            }

            return(tracking);
        }
Esempio n. 3
0
        public void ConvertJsonToDataTable()
        {
            try
            {
                int      count  = dgvPromotion.Rows.Count;
                string[] arrayi = new string[count];
                for (int i = 0; i < count - 1; i++)
                {
                    arrayi[i] = dgvPromotion.Rows[i].Cells[0].Value.ToString();
                }
                dgvPromotion.Rows.Clear();
                ConnectionAPI connection = new ConnectionAPI("e3ddaecb-2ea2-4b2f-8fee-9f4e53c69704");
                for (int i = 0; i < count - 1; i++)
                {
                    Tracking tracking = new Tracking(arrayi[i])
                    {
                        slug = txtCourier.Text
                    };
                    connection.getTrackingByNumber(tracking);


                    string jsonString = connection.json_response;
                    JToken token      = JObject.Parse(jsonString);

                    string parameter;
                    if (tracking.id != null && tracking.id.Equals(""))
                    {
                        parameter = tracking.id;
                    }
                    else
                    {
                        String paramRequiredFields = connection.replaceFirst(tracking.getQueryRequiredFields(), "&", "?");
                        parameter = tracking.slug + "/" + tracking.trackingNumber + paramRequiredFields;
                    }

                    JObject response = connection.request("GET", "/last_checkpoint/" + parameter, null);

                    JObject checkpointJSON = (JObject)response["data"]["checkpoint"];
                    //List<Checkpoint> check = new List<Checkpoint>();
                    Checkpoint checkpoint = null;
                    if (checkpointJSON.Count != 0)
                    {
                        checkpoint = new Checkpoint(checkpointJSON);
                    }


                    string[] row = new string[] { arrayi[i], checkpoint.city, checkpoint.countryName, checkpoint.checkpointTime };
                    dgvPromotion.Rows.Add(row);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 4
0
        public void ConvertJsonToDataTableAll()
        {
            try
            {
                ConnectionAPI connection = new ConnectionAPI("e3ddaecb-2ea2-4b2f-8fee-9f4e53c69704");
                Tracking      tracking   = new Tracking(txtID.Text)
                {
                    slug = txtCourier.Text
                };
                connection.getTrackingByNumber(tracking);

                string jsonString = connection.json_response;
                JToken token      = JObject.Parse(jsonString);

                String parametersExtra;
                if (tracking.id != null && !tracking.id.Equals(""))
                {
                    parametersExtra = tracking.id;
                }
                else
                {
                    //get the require fields if any (postal_code, tracking_account etc..)
                    String paramRequiredFields = connection.replaceFirst(tracking.getQueryRequiredFields(), "&", "?");
                    parametersExtra = tracking.slug + "/" + tracking.trackingNumber +
                                      paramRequiredFields;
                }
                JObject  response     = connection.request("GET", "/trackings/" + parametersExtra, null);
                JObject  trackingJSON = (JObject)response["data"]["tracking"];
                Tracking tracking1    = null;
                if (trackingJSON.Count != 0)
                {
                    tracking1 = new Tracking(trackingJSON);
                }

                var rs = tracking1.checkpoints.ToList();
                foreach (var item in rs)
                {
                    string[] row = new string[] { item.city, item.countryName, item.checkpointTime };
                    dgvPromotion.Rows.Add(row);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///  Get a specific tracking from your account. If the trackingGet.id property
        /// is defined it will get that tracking from the system, if not it will take
        /// the tracking tracking.number and the tracking.slug for identify the tracking
        /// </summary>
        /// <param name="trackingGet">A Tracking to get</param>
        /// <param name="fields">A list of fields 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></returns>
        public Tracking getTrackingByNumber(Tracking trackingGet, List <FieldTracking> fields, String lang)
        {
            String parametersAll;

            //encode the fields required
            String      params_query;
            QueryString qs = new QueryString();

            if (fields != null)
            {
                qs.add("fields", parseListFieldTracking(fields));
            }

            if (lang != null && !lang.Equals(""))
            {
                qs.add("lang", lang);
            }

            params_query = replaceFirst(qs.ToString(), "&", "?");

            if (trackingGet.id != null && !trackingGet.id.Equals(""))
            {
                parametersAll = trackingGet.id + params_query;
            }
            else
            {
                //get the require fields if any (postal_code, tracking_account etc..)
                String paramRequiredFields = trackingGet.getQueryRequiredFields();
                parametersAll = trackingGet.slug +
                                "/" + trackingGet.trackingNumber + params_query + paramRequiredFields;
            }

            JObject  response     = this.request("GET", "/trackings/" + parametersAll, null);
            JObject  trackingJSON = (JObject)response["data"]["tracking"];
            Tracking tracking     = null;

            if (trackingJSON.Count != 0)
            {
                tracking = new Tracking(trackingJSON);
            }

            return(tracking);
        }
Esempio n. 6
0
        /// <summary>
        /// Updates a tracking of your account
        /// </summary>
        /// <param name="tracking">  A Tracking object with the information to update
        ///                The fields trackingNumber and slug SHOULD be informed, otherwise an exception will be thrown
        ///               The fields an user can update are: smses, emails, title, customerName, orderID, orderIDPath,
        ///               customFields</param>
        /// <returns>The last Checkpoint object</returns>
        public Tracking putTracking(Tracking tracking)
        {
            String parametersExtra = "";

            if (tracking.id != null && !(tracking.id.CompareTo("") == 0))
            {
                parametersExtra = tracking.id;
            }
            else
            {
                String paramRequiredFields = this.replaceFirst(tracking.getQueryRequiredFields(), "&", "?");
                parametersExtra = tracking.slug + "/" + tracking.trackingNumber + paramRequiredFields;
            }


            JObject response = this.request("PUT", "/trackings/" + parametersExtra, tracking.generatePutJSON());

            return(new Tracking((JObject)response["data"]["tracking"]));
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
            }
        }