Example #1
0
        /// <summary>
        /// Purchase a label for this shipment with the given rate.
        /// </summary>
        /// <param name="rateId">The id of the rate to purchase the shipment with.</param>
        public void Buy(string rateId)
        {
            Request request = new Request("v2/shipments/{id}/buy", Method.POST);

            request.AddUrlSegment("id", id);

            Dictionary <string, object> rate = new Dictionary <string, object>()
            {
                { "id", rateId }
            };

            request.AddBody(new Dictionary <string, object>()
            {
                { "rate", rate }
            });

            Shipment result = request.Execute <Shipment>();

            insurance     = result.insurance;
            postage_label = result.postage_label;
            tracking_code = result.tracking_code;
            tracker       = result.tracker;
            selected_rate = result.selected_rate;
            forms         = result.forms;
            messages      = result.messages;
            fees          = result.fees;
        }
Example #2
0
        /// <summary>
        /// Purchase a label for this shipment with the given rate.
        /// </summary>
        /// <param name="rateId">The id of the rate to purchase the shipment with.</param>
        /// <param name="insuranceValue">The value to insure the shipment for.</param>

        public void Buy(Client client, string rateId, string insuranceValue = null)
        {
            Request request = new Request("v2/shipments/{id}/buy", Method.POST);

            request.AddUrlSegment("id", id);

            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "rate", new Dictionary <string, object>()
                  {
                      { "id", rateId }
                  } }
            };

            if (insuranceValue != null)
            {
                body["insurance"] = insuranceValue;
            }

            request.AddBody(body);

            Shipment result = request.Execute <Shipment>(client);

            insurance     = result.insurance;
            postage_label = result.postage_label;
            tracking_code = result.tracking_code;
            tracker       = result.tracker;
            selected_rate = result.selected_rate;
            forms         = result.forms;
            messages      = result.messages;
            fees          = result.fees;
        }
Example #3
0
        /// <summary>
        /// Create a Batch.
        /// </summary>
        /// <param name="parameters">
        /// Optional dictionary containing parameters to create the batch with. Valid pairs:
        ///   * {"shipments", List<Dictionary<string, object>>} See Shipment.Create for a list of valid keys.
        ///   * {"reference", string}
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Batch instance.</returns>
        public static Batch Create(Dictionary<string, object> parameters = null) {
            parameters = parameters ?? new Dictionary<string, object>();

            Request request = new Request("batches", Method.POST);
            request.AddBody(parameters, "batch");

            return request.Execute<Batch>();
        }
Example #4
0
        /// <summary>
        /// Create a Webhook.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the carrier account with. Valid pairs:
        ///   * { "url", string } Url of the webhook that events will be sent to.
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Webhook instance.</returns>
        public static Webhook Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/webhooks", Method.POST);

            request.AddBody(parameters, "webhook");

            return(request.Execute <Webhook>());
        }
Example #5
0
        private static Order sendCreate(IDictionary <string, object> parameters)
        {
            Request request = new Request("orders", Method.POST);

            request.AddBody(parameters, "order");

            return(request.Execute <Order>());
        }
Example #6
0
        /// <summary>
        /// Create Rating.
        /// </summary>
        /// <param name="parameters">
        /// dictionary containing parameters to create the shipment with. Valid pairs:
        ///   * {"from_address", Dictionary&lt;string, object&gt;} See Address.Create for a list of valid keys.
        ///   * {"to_address", Dictionary&lt;string, object&gt;} See Address.Create for a list of valid keys.
        ///   * {"parcels", List&lt;Dictionary&lt;string, object&gt;&gt;} See Parcel.Create for list of valid keys.
        ///   * {"carrier_accounts", List&lt;string&gt;} List of CarrierAccount.id to limit rating.
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Rating instance.</returns>
        /// <summary>
        public static Rating Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("rating/v1/rates", Method.POST);

            request.AddBody(parameters);

            return(request.Execute <Rating>());
        }
Example #7
0
        private static Pickup sendCreate(IDictionary <string, object> parameters)
        {
            Request request = new Request("pickups", Method.POST);

            request.AddBody(parameters, "pickup");

            return(request.Execute <Pickup>());
        }
Example #8
0
        /// <summary>
        /// Create a child user for the account associated with the api_key specified.
        /// </summary>
        /// <param name="parameters">
        /// Optional dictionary containing parameters to create the carrier account with. Valid pairs:
        ///   * {"name", string} Name on the account.
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.User instance.</returns>
        public static User Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("users", Method.POST);

            request.AddBody(parameters, "user");

            return(request.Execute <User>());
        }
Example #9
0
        private static Address sendCreate(IDictionary <string, object> parameters)
        {
            Request request = new Request("addresses", Method.POST);

            request.AddBody(parameters, "address");

            return(request.Execute <Address>());
        }
        /// <summary>
        /// Create a CarrierAccount.
        /// </summary>
        /// <param name="parameters">
        /// Optional dictionary containing parameters to create the carrier account with. Valid pairs:
        ///   * {"type", string} Required (e.g. EndiciaAccount, UPSAccount, etc.).
        ///   * {"reference", string} External reference for carrier account.
        ///   * {"description", string} Description of carrier account.
        ///   * {"credentials", Dictionary<string, string>}
        ///   * {"test_credentials", Dictionary<string, string>}
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.CarrierAccount instance.</returns>
        public static CarrierAccount Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/carrier_accounts", Method.POST);

            request.AddBody(parameters, "carrier_account");

            return(request.Execute <CarrierAccount>());
        }
Example #11
0
        /// <summary>
        /// Create a Parcel.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the parcel with. Valid pairs:
        ///   * {"length", int}
        ///   * {"width", int}
        ///   * {"height", int}
        ///   * {"weight", double}
        ///   * {"predefined_package", string}
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Parcel instance.</returns>
        public static Parcel Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("parcels", Method.POST);

            request.AddBody(parameters, "parcel");

            return(request.Execute <Parcel>());
        }
Example #12
0
        /// <summary>
        /// Create a CustomsItem.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the customs item with. Valid pairs:
        ///   * {"description", string}
        ///   * {"quantity", int}
        ///   * {"weight", int}
        ///   * {"value", double}
        ///   * {"hs_tariff_number", string}
        ///   * {"origin_country", string}
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.CustomsItem instance.</returns>
        public static CustomsItem Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("customs_items", Method.POST);

            request.AddBody(parameters, "customs_item");

            return(request.Execute <CustomsItem>());
        }
Example #13
0
        private static Shipment sendCreate(Dictionary <string, object> parameters)
        {
            Request request = new Request("shipments", Method.POST);

            request.AddBody(parameters, "shipment");

            return(request.Execute <Shipment>());
        }
Example #14
0
        /// <summary>
        /// Update the User associated with the api_key specified.
        /// </summary>
        /// <param name="parameters">
        /// Optional dictionary containing parameters to create the carrier account with. Valid pairs:
        ///   * {"name", string} Name on the account.
        ///   * {"email", string} Email on the account. Can only be updated on the parent account.
        ///   * {"phone_number", string} Phone number on the account. Can only be updated on the parent account.
        ///   * {"recharge_amount", int} Recharge amount for the account in cents. Can only be updated on the parent account.
        ///   * {"secondary_recharge_amount", int} Secondary recharge amount for the account in cents. Can only be updated on the parent account.
        ///   * {"recharge_threshold", int} Recharge threshold for the account in cents. Can only be updated on the parent account.
        /// All invalid keys will be ignored.
        /// </param>
        public void Update(Dictionary <string, object> parameters)
        {
            Request request = new Request("users/{id}", Method.PUT);

            request.AddUrlSegment("id", id);
            request.AddBody(parameters, "user");

            this.Merge(request.Execute <User>());
        }
Example #15
0
        /// <summary>
        /// Remove shipments from the batch.
        /// </summary>
        /// <param name="shipmentIds">List of shipment ids to be removed.</param>
        public void RemoveShipments(IEnumerable<string> shipmentIds) {
            Request request = new Request("batches/{id}/remove_shipments", Method.POST);
            request.AddUrlSegment("id", id);

            List<Dictionary<string, object>> body = shipmentIds.Select(shipmentId => new Dictionary<string, object>() { { "id", shipmentId } }).ToList();
            request.AddBody(body, "shipments");

            Merge(request.Execute<Batch>());
        }
        /// <summary>
        /// Update this CarrierAccount.
        /// </summary>
        /// <param name="parameters">See CarrierAccount.Create for more details.</param>
        public void Update(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/carrier_accounts/{id}", Method.PUT);

            request.AddUrlSegment("id", id);
            request.AddBody(parameters, "carrier_account");

            Merge(request.Execute <CarrierAccount>());
        }
Example #17
0
        /// <summary>
        /// Create a Order.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the order with. Valid pairs:
        ///   * {"from_address", Dictionary&lt;string, object&gt;} See Address.Create for a list of valid keys.
        ///   * {"to_address", Dictionary&lt;string, object&gt;} See Address.Create for a list of valid keys.
        ///   * {"buyer_address", Dictionary&lt;string, object&gt;} See Address.Create for a list of valid keys.
        ///   * {"return_address", Dictionary&lt;string, object&gt;} See Address.Create for a list of valid keys.
        ///   * {"customs_info", Dictionary&lt;string, object&gt;} See CustomsInfo.Create for list of valid keys.
        ///   * {"is_return", bool}
        ///   * {"reference", string}
        ///   * {"shipments", IEnumerable&lt;Shipment&gt;} See Shipment.Create for list of valid keys.
        ///   * {"carrier_accounts", IEnumerable&lt;CarrierAccount&gt;}
        ///   * {"containers", IEnumerable&lt;Container&gt;} See Container.Create for list of valid keys.
        ///   * {"items", IEnumerable&lt;Item&gt;} See Item.Create for list of valid keys.
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Order instance.</returns>
        public static Order Create(Client client, Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/orders", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "order", parameters }
            });

            return(request.Execute <Order>(client));
        }
Example #18
0
        /// <summary>
        /// Create a Container.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the container with. Valid pairs:
        ///   * {"name", string}
        ///   * {"type", string}
        ///   * {"reference", string}
        ///   * {"length", double}
        ///   * {"width", double}
        ///   * {"height", double}
        ///   * {"max_weight", double}
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Container instance.</returns>
        public static Container Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/containers", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "container", parameters }
            });

            return(request.Execute <Container>());
        }
Example #19
0
        /// <summary>
        /// Create a CustomsInfo.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the customs info with. Valid pairs:
        ///   * {"customs_certify", bool}
        ///   * {"customs_signer", string}
        ///   * {"contents_type", string}
        ///   * {"contents_explanation", string}
        ///   * {"restriction_type", string}
        ///   * {"eel_pfc", string}
        ///   * {"custom_items", Dictionary<string, object>} -- Can contain the key "id" or all keys required to create a CustomsItem.
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.CustomsInfo instance.</returns>
        public static CustomsInfo Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/customs_infos", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "customs_info", parameters }
            });

            return(request.Execute <CustomsInfo>());
        }
Example #20
0
        private static Shipment SendCreate(Client client, Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/shipments", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "shipment", parameters }
            });

            return(request.Execute <Shipment>(client));
        }
Example #21
0
        private static Order SendCreate(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/orders", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "order", parameters }
            });

            return(request.Execute <Order>());
        }
Example #22
0
        /// <summary>
        /// Create an Item.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the item with. Valid pairs:
        ///   * {"name", string}
        ///   * {"description", string}
        ///   * {"reference", string}
        ///   * {"harmonized_code", string}
        ///   * {"country_of_origin", string}
        ///   * {"warehouse_location", string}
        ///   * {"value", double}
        ///   * {"length", double}
        ///   * {"width", double}
        ///   * {"height", double}
        ///   * {"weight", double}
        ///   ADD ANY CUSTOM REFERENCES HERE
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Item instance.</returns>
        public static Item Create(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/items", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "item", parameters }
            });

            return(request.Execute <Item>());
        }
Example #23
0
        /// <summary>
        /// Create a Webhook.
        /// </summary>
        /// <param name="parameters">
        /// Dictionary containing parameters to create the carrier account with. Valid pairs:
        ///   * { "url", string } Url of the webhook that events will be sent to.
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Webhook instance.</returns>
        public static Webhook Create(Client client, Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/webhooks", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "webhook", parameters }
            });

            return(request.Execute <Webhook>(client));
        }
Example #24
0
        /// <summary>
        /// Create and verify an Address.
        /// </summary>
        /// <param name="parameters">
        /// Optional dictionary containing parameters to create the address with. Valid pairs:
        ///   * {"name", string}
        ///   * {"company", string}
        ///   * {"stree1", string}
        ///   * {"street2", string}
        ///   * {"city", string}
        ///   * {"state", string}
        ///   * {"zip", string}
        ///   * {"country", string}
        ///   * {"phone", string}
        ///   * {"email", string}
        /// All invalid keys will be ignored.
        /// </param>
        /// <returns>EasyPost.Address instance.</returns>
        public static Address CreateAndVerify(IDictionary <string, object> parameters = null)
        {
            parameters = parameters ?? new Dictionary <string, object>();

            Request request = new Request("addresses/create_and_verify", Method.POST);

            request.RootElement = "address";
            request.AddBody(parameters, "address");

            return(request.Execute <Address>());
        }
Example #25
0
        private static Pickup SendCreate(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/pickups", Method.POST);

            request.AddBody(new Dictionary <string, object>()
            {
                { "pickup", parameters }
            });

            return(request.Execute <Pickup>());
        }
Example #26
0
        /// <summary>
        /// Create a ScanForm.
        /// </summary>
        /// <param name="shipments">Shipments to be associated with the ScanForm. Only id is required.</param>
        /// <returns>EasyPost.ScanForm instance.</returns>
        public static ScanForm Create(List <Shipment> shipments)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object> {
                { "shipments", shipments }
            };

            Request request = new Request("v2/scan_forms", Method.POST);

            request.AddBody(parameters, "scan_form");

            return(request.Execute <ScanForm>());
        }
Example #27
0
        /// <summary>
        /// Update the User associated with the api_key specified.
        /// </summary>
        /// <param name="parameters">
        /// Optional dictionary containing parameters to create the carrier account with. Valid pairs:
        ///   * {"name", string} Name on the account.
        ///   * {"email", string} Email on the account. Can only be updated on the parent account.
        ///   * {"phone_number", string} Phone number on the account. Can only be updated on the parent account.
        ///   * {"recharge_amount", int} Recharge amount for the account in cents. Can only be updated on the parent account.
        ///   * {"secondary_recharge_amount", int} Secondary recharge amount for the account in cents. Can only be updated on the parent account.
        ///   * {"recharge_threshold", int} Recharge threshold for the account in cents. Can only be updated on the parent account.
        /// All invalid keys will be ignored.
        /// </param>
        public void Update(Dictionary <string, object> parameters)
        {
            Request request = new Request("v2/users/{id}", Method.PUT);

            request.AddUrlSegment("id", id);
            request.AddBody(new Dictionary <string, object>()
            {
                { "user", parameters }
            });

            Merge(request.Execute <User>());
        }
Example #28
0
        public static Tracker Create(string carrier, string trackingCode)
        {
            Request request = new Request("trackers", RestSharp.Method.POST);
            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "tracking_code", trackingCode }, { "carrier", carrier }
            };

            request.AddBody(parameters, "tracker");

            return(request.Execute <Tracker>());
        }
Example #29
0
        /// <summary>
        /// Insure shipment for the given amount.
        /// </summary>
        /// <param name="amount">The amount to insure the shipment for. Currency is provided when creating a shipment.</param>
        public void Insure(double amount)
        {
            Request request = new Request("shipments/{id}/insure", Method.POST);

            request.AddUrlSegment("id", id);
            request.AddBody(new List <Tuple <string, string> >()
            {
                new Tuple <string, string>("amount", amount.ToString())
            });

            Merge(request.Execute <Shipment>());
        }
Example #30
0
        /// <summary>
        /// Purchase the shipments within this order with a carrier and service.
        /// </summary>
        /// <param name="carrier">The carrier to purchase a shipment from.</param>
        /// <param name="service">The service to purchase.</param>
        public void Buy(string carrier, string service)
        {
            Request request = new Request("orders/{id}/buy", Method.POST);

            request.AddUrlSegment("id", id);
            request.AddBody(new List <Tuple <string, string> >()
            {
                new Tuple <string, string>("carrier", carrier), new Tuple <string, string>("service", service)
            });

            this.Merge(request.Execute <Order>());
        }