myparcel

package module
v0.0.0-...-f5cc5ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 8 Imported by: 0

README

MyParcel Go Package [WIP, partially working]

MyParcel is a Go package that provides functionality for sending and tracking letters and parcels. It interacts with the MyParcel API to perform operations such as creating shipments and tracking packages.

Installation

To install the MyParcel Go package, use the following command:

go get github.com/daltcore/myparcel

Usage

To use the MyParcel Go package, import it into your Go project:

import "github.com/daltcore/myparcel"

Then, create a new MyParcel client:

client := myparcel.NewClient("<your API key>")

You can then use the client to perform various operations, such as creating a shipment:

shipment := myparcel.ShipmentStruct{
    ReferenceIdentifier: "123456789",
    Recipient: myparcel.RecipientStruct{
        Street:     "Testlane",
        Number:     "1",
        PostalCode: "1234 AB",
        City:       "Amsterdam",
        Cc:         "NL",
        Person:     "D. Duck",
    },
    Options: myparcel.OptionsStruct{
        PackageType: myparcel.ParcelPackage,
    },
    Carrier: myparcel.CarrierPostnl,
}

id, err := client.CreateShipment(shipment)
if err != nil {
    panic(err)
}

fmt.Println(id)

You can also use the client to track a package:

shipmentResponse, err := client.GetShipment(12345)
	if err != nil {
		panic(err)
	}

fmt.Printf("%+v\n", shipmentResponse)

For more information about the available operations and data structures, see the GoDoc documentation.

Features

The MyParcel Go package includes the following features:

  • Create shipments
  • Get shipments
  • Track packages

Contributing

If you would like to contribute to the MyParcel Go package, please follow these steps:

  • Fork this repository
  • Create a new branch for your feature: git checkout -b my-new-feature
  • Make your changes and commit them: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Create a new pull request

Please ensure that your code follows the project's coding style and that all tests pass before submitting a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	// Carriers
	CarrierPostnl     = 1 // (PostNL)
	CarrierBpost      = 2 // (bpost. Only available on Sendmyparcel.be)
	CarrierCheapCargo = 3 // (CheapCargo/pallets)
	CarrierDpd        = 4 // (DPD. Only available on Sendmyparcel.be)
	CarrierInstabox   = 5 // (Instabox. Only available on MyParcel.nl)
	CarrierUps        = 8 // (UPS. Only available on MyParcel.nl)

	// Package types
	ParcelPackage = 1 // This is the standard package type used for NL, EU and Global shipments. It supports a variety of additional options such as insurance, xl format etc. We will look at these options in more detail later. This package is most commonly used when creating shipments.
	ParcelMailbox = 2 // This package type is only available on MyParcel.nl and Flespakket for NL shipment that fit into a mailbox. It does not support additional options. Note: If you still make the request with additional options, bear in mind that you need to pay more than is necessary!
	ParcelLetter  = 3 // This package type is available on MyParcel.nl for NL, EU and Global shipments. The label for this shipment is unpaid meaning that you will need to pay the postal office/courier to sent this letter/package. Therefore, it does not support additional options.
	ParcelStamp   = 4 // This package type is only available on MyParcel.nl for NL shipments and does not support any additional options. Its price is calculated using the package weight. Note: This shipment will appear on your invoice on shipment_status 2 (pending - registered) as opposed to all other package types, which won't appear on your invoice until shipment status 3 (enroute - handed to carrier).

	// Delivery types
	DeliveryMorning  = 1 // Morning delivery
	DeliveryStandard = 2 // Standard delivery
	DeliveryEvening  = 3 // Evening delivery
	DeliveryPickup   = 4 // Pickup point delivery
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ApiKey string

	UserAgent string
	// contains filtered or unexported fields
}

Client is the MyParcel client.

func NewClient

func NewClient(apiKey string) *Client

NewClient returns a new MyParcel client. The API key is required to use the MyParcel API.

func (*Client) CreateShipment

func (c *Client) CreateShipment(shipment ShipmentCreateStruct) (int, error)

CreateShipment creates a new shipment.

func (*Client) GetShipment

func (c *Client) GetShipment(id int) (ShipmentResponseStruct, error)

GetShipment returns a shipment by ID.

type InsuranceStruct

type InsuranceStruct struct {
	Amount   int    `json:"amount"`   // Required: yes. The amount is without decimal separators (in cents).
	Currency string `json:"currency"` // Required: yes. The insurance currency code. Must be one of the following: EUR.
}

Insurance struct

type JSONTime

type JSONTime time.Time

JSONTime is a custom time type that can be marshalled to JSON.

func (JSONTime) IsZero

func (t JSONTime) IsZero() bool

IsZero returns true if the time is zero.

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of time specified in the format

type OptionsStruct

type OptionsStruct struct {
	PackageType      int             `json:"package_type"`             // Required: yes. The package type. For international shipment only package type 1 (package) is allowed.
	OnlyRecipient    int             `json:"only_recipient,omitempty"` // Required: No. Deliver the package to the recipient only.
	DeliveryType     int             `json:"delivery_type,omitempty"`  // Required: Yes if delivery_date has been specified. The delivery type for the package.
	DeliveryDate     JSONTime        `json:"delivery_date,omitempty"`  // Required: Yes if delivery type has been specified. The delivery date time for this shipment.
	Signature        int             `json:"signature,omitempty"`      // Required: No. Package must be signed for.
	Return           int             `json:"return,omitempty"`         // Required: No. Return the package if the recipient is not home.
	Insurance        InsuranceStruct `json:"insurance"`                // Required: No. Insurance price for the package.
	LargeFormat      int             `json:"large_format"`             // Required: No. Large format package.
	LabelDescription string          `json:"label_description"`        // Required: No. This description will appear on the shipment label. Note: This will be overridden for return shipment by the following: Retour – 3SMYPAMYPAXXXXXX
	AgeCheck         int             `json:"age_check"`                // Required: No. The recipient must sign for the package and must be at least 18 years old.
}

Options struct

type RecipientStruct

type RecipientStruct struct {
	Cc         string `json:"cc"`               // Required: yes. The address country code.
	Region     string `json:"region,omitempty"` // Required: no. The region, department, state or province of the address.
	City       string `json:"city"`             // Required: yes. The address city.
	Street     string `json:"street"`           // Required: yes. The address street name. When shipping to an international destination, you may include street number in this field.
	Number     string `json:"number"`           // Required: yes for domestic shipments in NL and BE. Street number.
	PostalCode string `json:"postal_code"`      // Required: yes for NL and EU destinations except for IE. The address postal code.
	Person     string `json:"person"`           // Required: yes. The person at this address. Up to 40 characters long.
	Phone      string `json:"phone,omitempty"`  // Required: no. The address phone.
	Email      string `json:"email,omitempty"`  // Required: no The address email.
}

Insurance struct

type SenderStruct

type SenderStruct struct {
	Cc         string `json:"cc,omitempty"`          // Required: yes. The address country code.
	Region     string `json:"region,omitempty"`      // Required: no. The region, department, state or province of the address.
	City       string `json:"city,omitempty"`        // Required: yes. The address city.
	Street     string `json:"street,omitempty"`      // Required: yes. The address street name. When shipping to an international destination, you may include street number in this field.
	Number     string `json:"number,omitempty"`      // Required: yes for domestic shipments in NL and BE. Street number.
	PostalCode string `json:"postal_code,omitempty"` // Required: yes for NL and EU destinations except for IE. The address postal code.
	Person     string `json:"person,omitempty"`      // Required: yes. The person at this address. Up to 40 characters long.
	Phone      string `json:"phone,omitempty"`       // Required: no. The address phone.
	Email      string `json:"email,omitempty"`       // Required: no The address email.
}

Sender struct

type ShipmentCreateStruct

type ShipmentCreateStruct struct {
	Recipient                RecipientStruct `json:"recipient"`                              // Required: Yes. The recipient address.
	ReferenceIdentifier      string          `json:"reference_identifier"`                   // Required: No. Arbitrary reference indentifier to identify this shipment.
	Options                  OptionsStruct   `json:"options"`                                // Required: Yes. The shipment options.
	Carrier                  int             `json:"carrier"`                                // Required: Yes. The carrier that will deliver the package.
	Barcode                  string          `json:"barcode,omitempty"`                      // Required: n/a. Shipment barcode.
	SecondaryShipments       interface{}     `json:"secondary_shipments,omitempty"`          // Required: no. You can specify secondary shipments for the shipment with this object. This property is used to create a multi collo shipment: multiple packages to be delivered to the same address at the same time. Secondary shipment can be passed as empty json objects as all required data will be copied from the main shipment. When data is passed with the secondary shipment this data will be used in favor of the main shipment data.
	MultiColloMainShipmentID interface{}     `json:"multi_collo_main_shipment_id,omitempty"` // Required: n/a. In case of a multi collo shipment this field contains the id of the main shipment.
	Created                  string          `json:"created,omitempty"`                      // Required: n/a. Date of creaton.
	Modified                 string          `json:"modified,omitempty"`                     // Required: n/a. Date of modification.
}

Shipment struct

type ShipmentCreatedResponseStruct

type ShipmentCreatedResponseStruct struct {
	Data struct {
		Ids []struct {
			ID                  int    `json:"id"`
			ReferenceIdentifier string `json:"reference_identifier"`
		} `json:"ids"`
	} `json:"data"`
}

type ShipmentRequest

type ShipmentRequest struct {
	Data struct {
		Shipments []ShipmentCreateStruct `json:"shipments"`
	} `json:"data"`
}

ShipmentRequest struct with data and with multiple shipments

type ShipmentRequestStruct

type ShipmentRequestStruct struct {
	Recipient                RecipientStruct `json:"recipient"`                              // Required: Yes. The recipient address.
	Sender                   SenderStruct    `json:"sender,omitempty"`                       // Required: n/a. The sender of the package. This field is never set.
	ReferenceIdentifier      string          `json:"reference_identifier"`                   // Required: No. Arbitrary reference indentifier to identify this shipment.
	Options                  OptionsStruct   `json:"options"`                                // Required: Yes. The shipment options.
	Carrier                  int             `json:"carrier"`                                // Required: Yes. The carrier that will deliver the package.
	Barcode                  string          `json:"barcode,omitempty"`                      // Required: n/a. Shipment barcode.
	SecondaryShipments       interface{}     `json:"secondary_shipments,omitempty"`          // Required: no. You can specify secondary shipments for the shipment with this object. This property is used to create a multi collo shipment: multiple packages to be delivered to the same address at the same time. Secondary shipment can be passed as empty json objects as all required data will be copied from the main shipment. When data is passed with the secondary shipment this data will be used in favor of the main shipment data.
	MultiColloMainShipmentID interface{}     `json:"multi_collo_main_shipment_id,omitempty"` // Required: n/a. In case of a multi collo shipment this field contains the id of the main shipment.
	Created                  string          `json:"created,omitempty"`                      // Required: n/a. Date of creaton.
	Modified                 string          `json:"modified,omitempty"`                     // Required: n/a. Date of modification.
}

type ShipmentResponseStruct

type ShipmentResponseStruct struct {
	Data struct {
		Shipments []ShipmentRequestStruct `json:"shipments"`
		Results   int                     `json:"results"`
	} `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL