Documentation
¶
Overview ¶
Package klikresi provides a client for the Klik Resi API.
It supports account lookup, shipment tracking, shipping rate calculation, and location lookup (search, provinces, cities, districts) across Indonesian couriers.
Create a client with NewClient and use the resources grouped under Tracking, Rates, Location, and Me:
client := klikresi.NewClient("your-api-key")
tracking, err := client.Tracking.Get(ctx, "YOUR-AWB", klikresi.CourierJNE)
Index ¶
- Constants
- type APIError
- type AccountProfile
- type Address
- type City
- type CityPage
- type Client
- type DeliveryStatus
- type District
- type DistrictPage
- type History
- type Location
- func (l *Location) AllCities(ctx context.Context, provinceID string, opts ...PageOption) ([]City, error)
- func (l *Location) AllDistricts(ctx context.Context, cityID string, opts ...PageOption) ([]District, error)
- func (l *Location) AllLocations(ctx context.Context, keyword string, opts ...PageOption) ([]LocationInfo, error)
- func (l *Location) AllProvinces(ctx context.Context, opts ...PageOption) ([]Province, error)
- func (l *Location) Cities(ctx context.Context, provinceID string, opts ...PageOption) (*CityPage, error)
- func (l *Location) Districts(ctx context.Context, cityID string, opts ...PageOption) (*DistrictPage, error)
- func (l *Location) Provinces(ctx context.Context, opts ...PageOption) (*ProvincePage, error)
- func (l *Location) Search(ctx context.Context, keyword string, opts ...PageOption) (*LocationPage, error)
- type LocationInfo
- type LocationPage
- type LocationRef
- type Me
- type PageOption
- type Pricing
- type Province
- type ProvincePage
- type RateResult
- type Rates
- func (r *Rates) CalculateByID(ctx context.Context, originID, destinationID string, weight float64, ...) (*RateResult, error)
- func (r *Rates) CalculateByName(ctx context.Context, origin, destination string, weight float64) (*RateResult, error)
- func (r *Rates) CalculateByPostalCode(ctx context.Context, originPostalCode, destinationPostalCode int, ...) (*RateResult, error)
- type Tracking
- type TrackingInfo
- type TrackingOption
Constants ¶
const ( // CourierSPX is Shopee Express. CourierSPX = "spx" // CourierJNE is Jalur Nugraha Ekakurir. CourierJNE = "jne" // CourierJNT is J&T Express. CourierJNT = "jnt" // CourierSicepat is Sicepat Express. CourierSicepat = "sicepat" // CourierNinja is Ninja Express. CourierNinja = "ninja" // CourierPos is POS Indonesia. CourierPos = "pos" // CourierSAP is SAP Express. CourierSAP = "sap" // CourierLEX is Lazada Logistics. CourierLEX = "lex" // CourierLion is Lion Parcel. CourierLion = "lion" // CourierIDExpress is ID Express. CourierIDExpress = "ide" // CourierAnteraja is Anteraja. CourierAnteraja = "anteraja" // CourierWahana is Wahana Prestasi Logistik. CourierWahana = "wahana" // CourierTiki is TIKI. CourierTiki = "tiki" )
Supported courier codes. Use these with Tracking.Get and the Rates courier filter instead of hard-coding strings.
const ( // DefaultBaseURL is the production API endpoint. DefaultBaseURL = "https://klikresi.com" // BaseURLEnv overrides DefaultBaseURL when set. It is mainly useful // for tests and proxies. BaseURLEnv = "KLIKRESI_BASE_URL" // DefaultTimeout is applied to every request when the client is // created with NewClient. DefaultTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// StatusCode is the HTTP status code returned by the API.
StatusCode int
// Message is the error message returned by the API, when available.
Message string
}
APIError is returned for any non-2xx API response.
type AccountProfile ¶ added in v1.1.0
type AccountProfile struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Balance float64 `json:"balance"`
}
AccountProfile is the profile of the account that owns the API key.
type Client ¶
type Client struct {
// Tracking provides access to the tracking API.
Tracking *Tracking
// Rates provides access to the rates API.
Rates *Rates
// Location provides access to the location API.
Location *Location
// Me provides access to the account profile API.
Me *Me
// contains filtered or unexported fields
}
Client is a Klik Resi API client. It is safe for concurrent use.
func NewClient ¶
NewClient returns a Client for the given API key. The base URL defaults to https://klikresi.com and can be overridden with the KLIKRESI_BASE_URL environment variable.
type DeliveryStatus ¶
type DeliveryStatus string
DeliveryStatus is the normalized shipment status returned by the tracking API.
const ( // StatusInfoReceived means the carrier has received the package info // and is about to pick up the package. StatusInfoReceived DeliveryStatus = "InfoReceived" // StatusInTransit means the package is in transit and has a good // transportation condition. StatusInTransit DeliveryStatus = "InTransit" // StatusOutForDelivery means the package has arrived at the local // point or is on the way to the recipient. StatusOutForDelivery DeliveryStatus = "OutForDelivery" // StatusFailedAttempt means the delivery of the package was attempted // but failed due to some reasons. StatusFailedAttempt DeliveryStatus = "FailedAttempt" // StatusDelivered means the package has been delivered. StatusDelivered DeliveryStatus = "Delivered" // StatusReturnToSender means the package is on the way back to the // sender. StatusReturnToSender DeliveryStatus = "ReturnToSender" // StatusException means the package was lost, damaged, on hold, etc. StatusException DeliveryStatus = "Exception" // StatusExpired means the last track of the package has not been // updated for 30 days. StatusExpired DeliveryStatus = "Expired" // StatusPending means no information yet as the package is pending to // track or the carrier is wrong. StatusPending DeliveryStatus = "Pending" )
Delivery statuses returned by the tracking API.
type DistrictPage ¶
DistrictPage is one page of districts.
type History ¶
type History struct {
Status DeliveryStatus `json:"status"`
Message string `json:"message"`
Date time.Time `json:"date"`
}
History is a single tracking event.
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
Location provides access to the location API.
func (*Location) AllCities ¶
func (l *Location) AllCities(ctx context.Context, provinceID string, opts ...PageOption) ([]City, error)
AllCities returns every city within the given province, following pagination cursors automatically.
func (*Location) AllDistricts ¶
func (l *Location) AllDistricts(ctx context.Context, cityID string, opts ...PageOption) ([]District, error)
AllDistricts returns every district within the given city, following pagination cursors automatically.
func (*Location) AllLocations ¶
func (l *Location) AllLocations(ctx context.Context, keyword string, opts ...PageOption) ([]LocationInfo, error)
AllLocations returns every location matching the keyword, following pagination cursors automatically.
func (*Location) AllProvinces ¶
AllProvinces returns every province, following pagination cursors automatically.
func (*Location) Cities ¶
func (l *Location) Cities(ctx context.Context, provinceID string, opts ...PageOption) (*CityPage, error)
Cities returns one page of cities within the given province.
func (*Location) Districts ¶
func (l *Location) Districts(ctx context.Context, cityID string, opts ...PageOption) (*DistrictPage, error)
Districts returns one page of districts within the given city.
func (*Location) Provinces ¶
func (l *Location) Provinces(ctx context.Context, opts ...PageOption) (*ProvincePage, error)
Provinces returns one page of provinces.
func (*Location) Search ¶
func (l *Location) Search(ctx context.Context, keyword string, opts ...PageOption) (*LocationPage, error)
Search looks up locations matching the given keyword.
type LocationInfo ¶
type LocationInfo struct {
ID string `json:"id"`
Name string `json:"name"`
District string `json:"district"`
City string `json:"city"`
Province string `json:"province"`
}
LocationInfo is a district-level location returned by the location search.
type LocationPage ¶
type LocationPage struct {
Data []LocationInfo `json:"data"`
NextCursor string `json:"next_cursor"`
}
LocationPage is one page of location search results.
type LocationRef ¶
LocationRef identifies a location by id and name.
type Me ¶ added in v1.1.0
type Me struct {
// contains filtered or unexported fields
}
Me provides access to the account profile API.
type PageOption ¶
type PageOption func(*pageOptions)
PageOption configures a paginated location request.
func WithCursor ¶
func WithCursor(cursor string) PageOption
WithCursor sets the pagination cursor returned by the previous page.
func WithLimit ¶
func WithLimit(limit int) PageOption
WithLimit sets the number of items per page. The API default is 50.
type Pricing ¶
type Pricing struct {
Type string `json:"type"`
CourierCode string `json:"courier_code"`
CourierName string `json:"courier_name"`
Service string `json:"service"`
Price float64 `json:"price"`
Duration string `json:"duration"`
}
Pricing is a single shipping rate offer from a courier.
type ProvincePage ¶
ProvincePage is one page of provinces.
type RateResult ¶
type RateResult struct {
Origin LocationRef `json:"origin"`
Destination LocationRef `json:"destination"`
Pricing []Pricing `json:"pricing"`
}
RateResult contains shipping rates between an origin and a destination.
type Rates ¶
type Rates struct {
// contains filtered or unexported fields
}
Rates provides access to the rates API.
func (*Rates) CalculateByID ¶
func (r *Rates) CalculateByID(ctx context.Context, originID, destinationID string, weight float64, couriers ...string) (*RateResult, error)
CalculateByID calculates shipping rates using district IDs as the origin and destination. Couriers optionally filters the result to the given courier codes.
func (*Rates) CalculateByName ¶
func (r *Rates) CalculateByName(ctx context.Context, origin, destination string, weight float64) (*RateResult, error)
CalculateByName calculates shipping rates using location names as the origin and destination.
func (*Rates) CalculateByPostalCode ¶
func (r *Rates) CalculateByPostalCode(ctx context.Context, originPostalCode, destinationPostalCode int, weight float64) (*RateResult, error)
CalculateByPostalCode calculates shipping rates using postal codes as the origin and destination.
type Tracking ¶
type Tracking struct {
// contains filtered or unexported fields
}
Tracking provides access to the tracking API.
func (*Tracking) Get ¶
func (t *Tracking) Get(ctx context.Context, trackingNumber, courierCode string, opts ...TrackingOption) (*TrackingInfo, error)
Get returns the tracking information for the given tracking number and courier code. Tracking is charged only for successful requests.
type TrackingInfo ¶
type TrackingInfo struct {
// Status is the normalized delivery status.
Status DeliveryStatus `json:"status"`
// Origin is the sender address.
Origin Address `json:"origin"`
// Destination is the recipient address.
Destination Address `json:"destination"`
// Histories lists the tracking events, newest first.
Histories []History `json:"histories"`
}
TrackingInfo is the full tracking information for a shipment.
type TrackingOption ¶
type TrackingOption func(*trackingOptions)
TrackingOption configures a tracking request.
func WithNumber ¶
func WithNumber(number string) TrackingOption
WithNumber adds the `number` query parameter. It is required by ID Express (courier "ide") and is passed through for every courier whenever it is provided.