Documentation ¶
Overview ¶
Package drs provides a very basic and simple API for working with V2 of the Amazon Dash Replenishment Services For more information, check the README file at https://github.com/kevineaton/drs-sdk
Most of the functions will require a deviceToken. This is the DRS Access Token retrieved after the user signs up for DRS, most often through LWA. The token will need to be managed and refreshed. At the time of this library's creation, it needed to be refreshed at least once an hour. This library does not handle that responsibility.
Index ¶
- func DeregisterDevice(deviceToken string) (bool, error)
- func ReportSlotStatus(deviceToken string, slotID string, status *SlotStatus) (bool, error)
- func UpdateDeviceStatus(deviceToken string, lastStatus string) (bool, error)
- type APIError
- type ConfigStruct
- type OrderInfoData
- type OrderItem
- type ProductInfoListItem
- type ReplenishResult
- type Slot
- type SlotOrderStatus
- type SlotOrderStatuses
- type SlotStatus
- type SubscriptionInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeregisterDevice ¶ added in v0.0.4
DeregisterDevice sends a request to DRS requesting that the device is deregistered from the service
func ReportSlotStatus ¶ added in v1.0.0
func ReportSlotStatus(deviceToken string, slotID string, status *SlotStatus) (bool, error)
ReportSlotStatus reports a slot status to Amazon. See the SlotStatus struct for information about the parameters
func UpdateDeviceStatus ¶ added in v0.0.3
UpdateDeviceStatus updates the device status. According to the docs, you will want to call this at least once every 24 hours.
If lastStatus is an empty string, we will replace it with the current timestamp in ISO8601
Types ¶
type APIError ¶
type APIError struct { Code int Data interface{} }
APIError represents an error from the API and SDK. It implements Error() and contains additional data such as Code and Data. Code represents, in most cases, the HTTP status code. Data will be filled with information that depends on the context of the usage.
type ConfigStruct ¶
ConfigStruct holds the various configuration options
var Config *ConfigStruct
Config is the global configuration object that holds global configuration settings
func ConfigSetup ¶
func ConfigSetup() *ConfigStruct
ConfigSetup sets up the config struct with data from the environment
type OrderInfoData ¶ added in v1.0.0
type OrderInfoData struct { InstanceID string `json:"instanceId"` OrderItems []OrderItem `json:"orderItems"` }
OrderInfoData represents a single order a slot
func GetOrderInfo ¶ added in v1.0.0
func GetOrderInfo(deviceToken, instanceID string) (*OrderInfoData, error)
GetOrderInfo gets the information regarding an order identified by its instanceId
type OrderItem ¶ added in v1.0.0
type OrderItem struct { ASIN string `json:"asin"` ExpectedDeliveryDate string `json:"expectedDeliveryDate"` Quantity int `json:"quantity"` SlotID string `json:"slotID"` Status string `json:"status"` }
OrderItem represents a single order item in an order information call
type ProductInfoListItem ¶
type ProductInfoListItem struct { ASIN string `json:"asin"` Quantity int `json:"quantity"` Unit string `json:"unit"` }
ProductInfoListItem represents a single ASIN in the subscription
type ReplenishResult ¶ added in v0.1.0
type ReplenishResult struct { EventInstanceID string `json:"eventInstanceId"` DetailCode string `json:"detailCode"` }
ReplenishResult represents the end result of a request to replenish a slot
func ReplenishSlot ¶ added in v0.1.0
func ReplenishSlot(deviceToken, slotID string) (*ReplenishResult, error)
ReplenishSlot asks Amazon to submit an order to replenish a specific slot for the device
type Slot ¶
type Slot struct { ProductInfoList []ProductInfoListItem `json:"productInfoList"` Subscribed bool `json:"subscribed"` }
Slot represents a DRS Slot and it's subscription status
type SlotOrderStatus ¶ added in v1.0.0
type SlotOrderStatus struct { OrderStatus string `json:"orderStatus"` SlotID string `json:"slotId"` }
SlotOrderStatus represents a single slot and the status of order on that slot
type SlotOrderStatuses ¶ added in v1.0.0
type SlotOrderStatuses struct {
SlotOrderStatuses []SlotOrderStatus `json:"slotOrderStatuses"`
}
SlotOrderStatuses is a container to hold a slice of SlotOrderStatuses returned after cancelling a test order
func CancelTestOrder ¶ added in v1.0.0
func CancelTestOrder(deviceToken, slotID string) (*SlotOrderStatuses, error)
CancelTestOrder cancels a test order on a slot for a device. Note that only test orders can be cancelled. An order for a real device must be cancelled through the Amazon account of the user and is not exposed by the DRS API
type SlotStatus ¶ added in v1.0.0
type SlotStatus struct { // ExpectedReplenishmentDate is the expected product replenishment date in // ISO 8601 format ExpectedReplenishmentDate string `json:"expectedReplenishmentDate"` // RemainingQuantityInUnit is the emaining quantity of the container // (in the unit of measurement provided during DeviceCapabilitiesGroup creation) RemainingQuantityInUnit float64 `json:"remainingQuantityInUnit"` // OriginalQuantityInUnit is the total quantity of product the container // had when it was full (in the unit of measurement that you provided // during DeviceCapabilitiesGroup creation) OriginalQuantityInUnit float64 `json:"originalQuantityInUnit"` // TotalQuantityOnHand is the total quantity of product on hand, but not // loaded into the device (if known) TotalQuantityOnHand float64 `json:"totalQuantityOnHand"` // LastUseDate is the last time that product was consumed from a given // slot in ISO 8601 format LastUseDate string `json:"lastUseDate"` }
SlotStatus represents the current status of the slot of a device and needs to be reported to Amazon at least on a daily basis.
type SubscriptionInfo ¶
SubscriptionInfo holds the results of the Subscription Information call. The Slots are a map of strings to Slot data
func GetSubscriptionInfo ¶ added in v0.0.4
func GetSubscriptionInfo(deviceToken string) (*SubscriptionInfo, error)
GetSubscriptionInfo gets the subscription information from DRS for the passed in device token