repsolapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package repsolapi implements the public and authenticated clients of the Repsol API and of its address service.

Index

Constants

View Source
const (
	// DefaultBaseURL is the default base URL of the Repsol API.
	DefaultBaseURL = "https://pidetubombona.repsol.es/api"
	// DefaultPlacesBaseURL is the default base URL of the address service.
	DefaultPlacesBaseURL = "https://pro-repsol.ed-integrations.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Province            string      `json:"province" toml:"province"`
	ProvinceCode        string      `json:"provinceCode" toml:"provinceCode"`
	Locality            string      `json:"locality" toml:"locality"`
	LocalityCode        string      `json:"localityCode" toml:"localityCode"`
	StreetType          string      `json:"streetType" toml:"streetType"`
	StreetTypeCode      string      `json:"streetTypeCode" toml:"streetTypeCode"`
	Street              string      `json:"street" toml:"street"`
	StreetCode          string      `json:"streetCode" toml:"streetCode"`
	Municipality        string      `json:"municipality" toml:"municipality"`
	MunicipalityCode    string      `json:"municipalityCode" toml:"municipalityCode"`
	Number              string      `json:"number" toml:"number"`
	AgencyCode          string      `json:"agencyCode" toml:"agencyCode"`
	ServiceCode         string      `json:"serviceCode" toml:"serviceCode"`
	PlaceID             string      `json:"placeId" toml:"placeId"`
	Latitude            FlexNumber  `json:"latitude" toml:"latitude"`
	Longitude           FlexNumber  `json:"longitude" toml:"longitude"`
	Origin              string      `json:"origin" toml:"origin"`
	Neutral             *bool       `json:"neutral,omitempty" toml:"neutral,omitempty"`
	FullAddress         string      `json:"fullAddress" toml:"fullAddress"`
	Confidence          *Confidence `json:"confidence,omitempty" toml:"confidence,omitempty"`
	CurrentFullAddress  *string     `json:"currentFullAddress,omitempty" toml:"currentFullAddress,omitempty"`
	CurrentStreet       *string     `json:"currentStreet,omitempty" toml:"currentStreet,omitempty"`
	Floor               string      `json:"floor" toml:"floor"`
	Door                string      `json:"door" toml:"door"`
	Details             string      `json:"details" toml:"details"`
	PostalCode          string      `json:"postalCode" toml:"postalCode"`
	IsPeninsula         bool        `json:"isPeninsula" toml:"isPeninsula"`
	AutocompleteContent string      `json:"autocompleteContent" toml:"autocompleteContent"`
}

Address is one address as the address service and the Repsol API describe it: the autocomplete and geocode results, the stored profile address and the address sent with an order.

type AgencyInfo

type AgencyInfo struct {
	AgencyCode    string `json:"agencyCode" toml:"agencyCode"`
	OnlinePayment bool   `json:"onlinePayment" toml:"onlinePayment"`
	WayletPayment bool   `json:"wayletPayment" toml:"wayletPayment"`
	AllowsTip     bool   `json:"allowsTip" toml:"allowsTip"`
}

AgencyInfo is the agency that serves an address.

type Auth

type Auth struct {
	UID       string
	Signature string
	Timestamp string
}

Auth is the signature triple that authenticates one call, as Gigya issues it.

type CartCheck

type CartCheck struct {
	Status       string `json:"status" toml:"status"`
	OnlinePolicy bool   `json:"onlinePolicy" toml:"onlinePolicy"`
	Order        bool   `json:"order" toml:"order"`
	OrderType    string `json:"orderType" toml:"orderType"`
}

CartCheck is the cart validation result. It says which write follows: a solicitude when OrderType is SOLICITUDE, an order when Order is true.

type CartCheckRequest

type CartCheckRequest struct {
	ScheduleMode   *string `json:"scheduleMode" toml:"scheduleMode"`
	AgencyCode     string  `json:"agencyCode" toml:"agencyCode"`
	UserGigyaUID   string  `json:"userGigyaUid" toml:"userGigyaUid"`
	Address        Address `json:"address" toml:"address"`
	MaterialID     string  `json:"materialId" toml:"materialId"`
	Quantity       int     `json:"quantity" toml:"quantity"`
	UnitPrice      float64 `json:"unitPrice" toml:"unitPrice"`
	DeliveryDateID string  `json:"deliveryDateId" toml:"deliveryDateId"`
	DeliveryDate   string  `json:"deliveryDate" toml:"deliveryDate"`
}

CartCheckRequest is the body of the cart validation that decides which write places the order. A nil ScheduleMode is sent as null, as the web does when the schedule has no mode.

type Client

type Client struct {
	// BaseURL is the API base URL, without a trailing slash.
	BaseURL string
	// HTTP is the shared transport.
	HTTP *httpx.Client
	// Signer signs authenticated calls. A nil Signer makes them fail with an
	// auth error before any request is sent.
	Signer Signer
	// Telemetry carries the identifiers of the current order flow. A nil
	// Telemetry leaves the ptb-* headers off writes.
	Telemetry *Telemetry
}

Client talks to the Repsol API. The zero value is not usable; BaseURL and HTTP must be set.

func (*Client) AddressMaps

func (c *Client) AddressMaps(ctx context.Context, a Address) (Address, error)

AddressMaps asks the API to normalise a Google address into a Repsol one. The endpoint may answer with an empty body, which means no mapping; that is a zero Address rather than an error.

func (*Client) Agency

func (c *Client) Agency(ctx context.Context, a Address) (AgencyInfo, error)

Agency returns the agency that serves the address.

func (*Client) Catalog

func (c *Client) Catalog(ctx context.Context, agencyCode string) ([]Product, error)

Catalog returns the products the agency sells. Entries without a material ID are packaging and not orderable.

func (*Client) CheckCart

func (c *Client) CheckCart(ctx context.Context, r CartCheckRequest) (CartCheck, error)

CheckCart runs the cart validation that decides which write places the order. It is authenticated and never retried, but it places nothing, so its failures keep their own category. UserGigyaUID is filled from the signature.

func (*Client) CreateOrder

func (c *Client) CreateOrder(ctx context.Context, r OrderRequest) (Placed, error)

CreateOrder places an order. A failure after the request leaves the process becomes the outcome-unknown error: the order may have been placed, so it is never retried.

func (*Client) CreateSolicitude

func (c *Client) CreateSolicitude(ctx context.Context, r SolicitudeRequest) (Placed, error)

CreateSolicitude places a pay-on-delivery order. A failure after the request leaves the process becomes the outcome-unknown error: the order may have been placed, so it is never retried.

func (*Client) DeliverySchedule

func (c *Client) DeliverySchedule(ctx context.Context, materialID string, a Address) ([]Schedule, error)

DeliverySchedule returns the delivery schedule of a material for the address.

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health checks that the API answers.

func (*Client) OrderHistory

func (c *Client) OrderHistory(ctx context.Context, limit, offset int) ([]HistoryEntry, error)

OrderHistory returns the newest orders first. limit and offset are sent as given, and paramToAvoidCache carries the current Unix milliseconds.

type Confidence

type Confidence struct {
	NumberNotFound               bool `json:"number_not_found" toml:"number_not_found"`
	AgencyNotFound               bool `json:"agency_not_found" toml:"agency_not_found"`
	ServiceNotFound              bool `json:"service_not_found" toml:"service_not_found"`
	IsFromDiscardedIsland        bool `json:"is_from_discarded_island" toml:"is_from_discarded_island"`
	ReferencePolicyInWrongIsland bool `json:"reference_policy_in_wrong_island" toml:"reference_policy_in_wrong_island"`
}

Confidence is the geocoder's confidence block. Every flag reports whether the geocoder could not confirm the matching part of the address.

type DeliveryDate

type DeliveryDate struct {
	ID   string `json:"id" toml:"id"`
	Date string `json:"date" toml:"date"`
}

DeliveryDate is one date the agency offers for a material.

type FlexNumber

type FlexNumber string

FlexNumber is a number that the API sends either as a JSON number or as a JSON string, depending on the endpoint. It marshals an empty value as "" and numeric text as a bare number, so the wire name and the wire type survive a round trip.

func (FlexNumber) MarshalJSON

func (n FlexNumber) MarshalJSON() ([]byte, error)

MarshalJSON writes an empty value as "" and numeric text as a bare number.

func (*FlexNumber) UnmarshalJSON

func (n *FlexNumber) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts a JSON number, a JSON string or null.

type HistoryAddress

type HistoryAddress struct {
	Province         string `json:"province" toml:"province"`
	ProvinceCode     string `json:"provinceCode" toml:"provinceCode"`
	Locality         string `json:"locality" toml:"locality"`
	LocalityCode     string `json:"localityCode" toml:"localityCode"`
	StreetType       string `json:"streetType" toml:"streetType"`
	Street           string `json:"street" toml:"street"`
	StreetTypeCode   string `json:"streetTypeCode" toml:"streetTypeCode"`
	StreetCode       string `json:"streetCode" toml:"streetCode"`
	Municipality     string `json:"municipality" toml:"municipality"`
	MunicipalityCode string `json:"municipalityCode" toml:"municipalityCode"`
	Number           string `json:"number" toml:"number"`
	Floor            string `json:"floor" toml:"floor"`
	Door             string `json:"door" toml:"door"`
	PostalCode       string `json:"postalCode" toml:"postalCode"`
	Details          string `json:"details" toml:"details"`
}

HistoryAddress is the partial address block of one history entry. The API keeps the text in Details and often leaves Street and Number empty, so a history address cannot rebuild the address object an order needs.

type HistoryAgency

type HistoryAgency struct {
	Name        string `json:"name" toml:"name"`
	Phone       string `json:"phone" toml:"phone"`
	RepsolPhone string `json:"repsolPhone" toml:"repsolPhone"`
	AgencyCode  string `json:"agencyCode" toml:"agencyCode"`
}

HistoryAgency is the agency block of one history entry.

type HistoryEntry

type HistoryEntry struct {
	CreatedAt     string         `json:"createdAt" toml:"createdAt"`
	DeliveryDate  string         `json:"deliveryDate" toml:"deliveryDate"`
	ReferenceSAC  string         `json:"referenceSAC" toml:"referenceSAC"`
	MaterialID    string         `json:"materialId" toml:"materialId"`
	Quantity      int            `json:"quantity" toml:"quantity"`
	UnitPrice     float64        `json:"unitPrice" toml:"unitPrice"`
	Discount      *float64       `json:"discount" toml:"discount"`
	PaymentMethod *string        `json:"paymentMethod" toml:"paymentMethod"`
	Bill          bool           `json:"bill" toml:"bill"`
	Agency        HistoryAgency  `json:"agency" toml:"agency"`
	Address       HistoryAddress `json:"address" toml:"address"`
}

HistoryEntry is one past order. The API reports no status: a delivery is pending when DeliveryDate is today or later in Europe/Madrid.

type OrderRequest

type OrderRequest struct {
	Address        Address `json:"address" toml:"address"`
	MaterialID     string  `json:"materialId" toml:"materialId"`
	Quantity       int     `json:"quantity" toml:"quantity"`
	UnitPrice      float64 `json:"unitPrice" toml:"unitPrice"`
	Bill           bool    `json:"bill" toml:"bill"`
	Discount       int     `json:"discount" toml:"discount"`
	DeliveryDateID string  `json:"deliveryDateId" toml:"deliveryDateId"`
	DeliveryDate   string  `json:"deliveryDate" toml:"deliveryDate"`
}

OrderRequest is the body of the order write the web uses when the cart check reports Order.

type Placed

type Placed struct {
	ExternalID   string        `json:"externalId" toml:"externalId"`
	DeliveryDate string        `json:"deliveryDate" toml:"deliveryDate"`
	Material     string        `json:"material" toml:"material"`
	Quantity     int           `json:"quantity" toml:"quantity"`
	UnitPrice    float64       `json:"unitPrice" toml:"unitPrice"`
	Address      PlacedAddress `json:"address" toml:"address"`
	Agency       PlacedAgency  `json:"agency" toml:"agency"`
}

Placed is a placed order. ExternalID is the only reference the write returns; the history reports the different referenceSAC instead.

type PlacedAddress

type PlacedAddress struct {
	Province     string `json:"province" toml:"province"`
	Locality     string `json:"locality" toml:"locality"`
	Municipality string `json:"municipality" toml:"municipality"`
	Street       string `json:"street" toml:"street"`
	Number       string `json:"number" toml:"number"`
	Door         string `json:"door" toml:"door"`
	Floor        string `json:"floor" toml:"floor"`
	PostalCode   string `json:"postalCode" toml:"postalCode"`
	StreetType   string `json:"streetType" toml:"streetType"`
}

PlacedAddress is the address summary of a placed order.

type PlacedAgency

type PlacedAgency struct {
	Name        string `json:"name" toml:"name"`
	Phone       string `json:"phone" toml:"phone"`
	RepsolPhone string `json:"repsolPhone" toml:"repsolPhone"`
}

PlacedAgency is the agency block of a placed order.

type PlacesClient

type PlacesClient struct {
	// BaseURL is the address service base URL, without a trailing slash.
	BaseURL string
	// HTTP is the shared transport.
	HTTP *httpx.Client
}

PlacesClient talks to the address service. The zero value is not usable; BaseURL and HTTP must be set.

func (*PlacesClient) Autocomplete

func (p *PlacesClient) Autocomplete(ctx context.Context, input string) ([]Address, error)

Autocomplete returns the address suggestions for a free-text input.

func (*PlacesClient) Geocode

func (p *PlacesClient) Geocode(ctx context.Context, placeID, number string) (Address, error)

Geocode resolves one autocomplete suggestion, identified by its place ID and street number, into a full address with a confidence block.

type Product

type Product struct {
	ID           string  `json:"id" toml:"id"`
	MaterialID   string  `json:"materialId" toml:"materialId"`
	Type         string  `json:"type" toml:"type"`
	Description  string  `json:"description" toml:"description"`
	Price        float64 `json:"price" toml:"price"`
	PricePerKilo float64 `json:"pricePerKilo" toml:"pricePerKilo"`
}

Product is one catalog entry. Entries without a material ID are packaging and not orderable.

type Schedule

type Schedule struct {
	MaterialID string         `json:"materialId" toml:"materialId"`
	Dates      []DeliveryDate `json:"dates" toml:"dates"`
	Mode       string         `json:"mode" toml:"mode"`
	Warning    bool           `json:"warning" toml:"warning"`
	Type       string         `json:"type" toml:"type"`
}

Schedule is the delivery schedule of one material. Mode is optional and is empty when the API omits it.

type Signer

type Signer interface {
	Sign(ctx context.Context) (Auth, error)
}

Signer signs authenticated calls. The implementation refreshes the signature when it has expired.

type SolicitudeRequest

type SolicitudeRequest struct {
	Address        Address `json:"address" toml:"address"`
	MaterialID     string  `json:"materialId" toml:"materialId"`
	Quantity       int     `json:"quantity" toml:"quantity"`
	UnitPrice      float64 `json:"unitPrice" toml:"unitPrice"`
	Status         string  `json:"status" toml:"status"`
	Bill           bool    `json:"bill" toml:"bill"`
	Discount       int     `json:"discount" toml:"discount"`
	DeliveryDateID string  `json:"deliveryDateId" toml:"deliveryDateId"`
	DeliveryDate   string  `json:"deliveryDate" toml:"deliveryDate"`
}

SolicitudeRequest is the body of a pay-on-delivery order request. Status is the one the cart check returned.

type Telemetry

type Telemetry struct {
	ProcessID string
	UserID    string
	Session   string
	User      string
}

Telemetry is the set of identifiers the web bundles send with the telemetry headers of a write. One Telemetry covers a whole order flow, so the process id is the same from /cart/check to /solicitude or /order.

func NewTelemetry

func NewTelemetry() *Telemetry

NewTelemetry returns fresh telemetry identifiers: a 21 character process id, a "us:" prefixed user id of 48 characters, and 22 character session and user ids.

It panics when the system's random source fails, which is unrecoverable for a process that needs fresh identifiers.

Jump to

Keyboard shortcuts

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