Documentation
¶
Overview ¶
Package agrirouter provides a client for interacting with the new agrirouter API.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) PutEndpoint(ctx context.Context, externalID string, params *PutEndpointParams, ...) (*Endpoint, error)
- func (c *Client) ReceiveMessages(ctx context.Context, messageHandler MessageHandler, ...) error
- func (c *Client) SendMessages(ctx context.Context, params *SendMessagesParams, body io.Reader) error
- type ClientOption
- type Endpoint
- type EndpointCapability
- type EndpointSubscription
- type HTTPRequestDoer
- type Message
- type MessageHandler
- type MessageReceivedEventData
- type PutEndpointParams
- type PutEndpointRequest
- type RequestEditorFn
- type SendMessagesParams
Constants ¶
const CapabilityDirectionReceive = internal_models.RECEIVE
CapabilityDirectionReceive indicates capability of endpoint to receive messages.
const CapabilityDirectionSend = internal_models.SEND
CapabilityDirectionSend indicates capability of endpoint to send messages.
const CapabilityDirectionSendReceive = internal_models.SENDRECEIVE
CapabilityDirectionSendReceive indicates capability of endpoint to both send and receive messages.
const CommunicationUnit = internal_models.CommunicationUnit
CommunicationUnit is an endpoint type representing a communication unit.
Communication units are typically devices that can send and receive agrirouter messages, which are installed inside of a vehicle or a machine.
const FarmingSoftware = internal_models.FarmingSoftware
FarmingSoftware is an endpoint type representing farming software applications.
Farming software applications can send and receive agrirouter messages, and they are typically cloud deployed applications that manage agricultural data and provide farmers with their own typically web-based user interface.
const VirtualCommunicationUnit = internal_models.VirtualCommunicationUnit
VirtualCommunicationUnit is an endpoint type representing a virtual communication unit.
Virtual communication units like usual communication units represent devices that can send and receive agrirouter messages, but they are doing so indirectly via their own cloud service, which is not installed inside of a vehicle or a machine.
Variables ¶
var ( // ErrPutEndpointFailed is returned when an error occurs while trying to put an endpoint. ErrPutEndpointFailed = errors.New("failed to put endpoint") // ErrFailedStatusCode is returned when the agrirouter API returns a status code that is not expected. ErrFailedStatusCode = errors.New("unexpected status code received from agrirouter API") // ErrAPICallFailed is returned when an API call fails due to network or server issues. ErrAPICallFailed = errors.New("API call failed") // ErrURLIsInvalid is returned when the provided URL is invalid. ErrURLIsInvalid = errors.New("provided URL is invalid") )
var ErrFailedToFetchPayload = errors.New("failed to fetch payload")
ErrFailedToFetchPayload is returned when calling agrirouter to fetch message payload fails.
var ErrFailedToReadPayload = errors.New("failed to read payload")
ErrFailedToReadPayload is returned when reading the payload from the response fails.
var ErrMissingPayload = errors.New("missing payload: no embedded payload and no payload URI")
ErrMissingPayload is returned when agrirouter returned no embedded payload with message nor a payload URI.
var ErrToCloseResponseBody = errors.New("failed to close response body")
ErrToCloseResponseBody is returned when closing the response body fails.
var ErrUnexpectedStatusCodeWhenFetchingPayload = errors.New("unexpected status code when fetching payload")
ErrUnexpectedStatusCodeWhenFetchingPayload is returned when the agrirouter API returns an unexpected status code when fetching message payload.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the structure that allows interaction with the agrirouter API.
func NewClient ¶
func NewClient(serverURL string, opts ...ClientOption) (*Client, error)
NewClient creates a new agrirouter client with the given server URL. The server URL should be the base URL of the agrirouter API, e.g. "https://api.qa.agrirouter.farm".
func (*Client) PutEndpoint ¶
func (c *Client) PutEndpoint( ctx context.Context, externalID string, params *PutEndpointParams, req *PutEndpointRequest, ) (*Endpoint, error)
PutEndpoint sends a request to the agrirouter API to create or update an endpoint.
Identifier externalId must uniquely identify created or updated endpoint, if endpoint with the same externalId already exists, it will be updated, but only if client is authorized to change that endpoint, f.e application owns it.
The request body must contain all endpoint capabilities and subscriptions. It is not possible to update only part of endpoint configuration. For example if subscriptions are not provided, they will be removed (set to empty list).
func (*Client) ReceiveMessages ¶ added in v0.2.0
func (c *Client) ReceiveMessages( ctx context.Context, messageHandler MessageHandler, errorHandler func(err error), ) error
ReceiveMessages listens for incoming messages from the agrirouter API and calls the provided handler for each received message.
This function blocks until the context is canceled or an error occurs. It is recommended to run this function in a separate goroutine.
func (*Client) SendMessages ¶ added in v0.1.0
func (c *Client) SendMessages( ctx context.Context, params *SendMessagesParams, body io.Reader, ) error
SendMessages sends a message to the agrirouter API.
The body of the request must be a valid payload of agrirouter message.
type ClientOption ¶
type ClientOption = oapi.ClientOption
ClientOption is a type for options that can be passed to the agrirouter client.
func WithHTTPClient ¶
func WithHTTPClient(doer HTTPRequestDoer) ClientOption
WithHTTPClient allows to set a custom HTTP client for the agrirouter client.
func WithRequestEditorFn ¶
func WithRequestEditorFn(fn RequestEditorFn) ClientOption
WithRequestEditorFn allows to set a custom request editor function to modify request before sending it.
type Endpoint ¶
type Endpoint = internal_models.Endpoint
Endpoint is the structure representing an agrirouter endpoint.
type EndpointCapability ¶
type EndpointCapability = internal_models.EndpointCapability
EndpointCapability is the structure representing an endpoint's capability.
It defines what endpoint can do, such as sending or receiving messages of specific types.
type EndpointSubscription ¶
type EndpointSubscription = internal_models.EndpointSubscription
EndpointSubscription is the structure representing an endpoint's subscription.
It defines which message types the endpoint is subscribed to, meaning it can receive messages of those types in case if sending endpoint has published them.
type HTTPRequestDoer ¶
type HTTPRequestDoer = oapi.HttpRequestDoer
HTTPRequestDoer performs HTTP requests.
The standard http.Client implements this interface.
type MessageHandler ¶ added in v0.2.0
type MessageHandler func(message *Message)
MessageHandler is a function that handles a received message.
type MessageReceivedEventData ¶ added in v0.2.0
type MessageReceivedEventData = internal_models.MessageReceivedEventData
MessageReceivedEventData represents the data received in a MessageReceived event.
It contains information about the received message, including its type and payload URI. This event would typically be followed by fetching the actual message payload from the provided URI and processing it accordingly (e.g. decoding, storing, or acting upon the message content).
type PutEndpointParams ¶
type PutEndpointParams = internal_models.PutEndpointParams
PutEndpointParams contains parameters to create or update an endpoint.
type PutEndpointRequest ¶
type PutEndpointRequest = internal_models.PutEndpointRequest
PutEndpointRequest is the request structure for creating or updating an endpoint.
type RequestEditorFn ¶
type RequestEditorFn = oapi.RequestEditorFn
RequestEditorFn is a function that can modify the request before it is sent.
type SendMessagesParams ¶ added in v0.1.0
type SendMessagesParams = internal_models.SendMessagesParams
SendMessagesParams contains parameters to send a message.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
oapi
Package oapi provides primitives to interact with the openapi HTTP API.
|
Package oapi provides primitives to interact with the openapi HTTP API. |
|
oapi/models
Package models provides primitives to interact with the openapi HTTP API.
|
Package models provides primitives to interact with the openapi HTTP API. |
|
tests/agriroutertestcontainer
Package agriroutertestcontainer is a testcontainers module for the agrirouter service.
|
Package agriroutertestcontainer is a testcontainers module for the agrirouter service. |