diff --git a/client.go b/client.go index 6a22ccd..aa2ec10 100644 --- a/client.go +++ b/client.go @@ -1,11 +1,13 @@ package databridge +// Config allows a consuming app to set up API Key, Consumer ID, and Topic Slug type Config struct { APIKey string ConsumerID string TopicSlug string } +// Client allows access to the Databridge API type Client struct { BaseURL string APIKey string @@ -13,6 +15,7 @@ type Client struct { ConsumerID string } +// NewClient returns a new Databridge Client func NewClient(config Config) (Client, error) { c := Client{} c.APIKey = config.APIKey @@ -23,14 +26,17 @@ func NewClient(config Config) (Client, error) { return c, nil } +// GetNextRecord returns the topic's next record. Will return nil without an error when there are no more records. func (c Client) GetNextRecord() (*Record, error) { return getNextRecord(c) } +// CompleteRecord allows the record to be marked as completed func (c Client) CompleteRecord(r Record) error { return r.updateRecordState(c, "completed") } +// FailRecord allows the record to be marked as failed func (c Client) FailRecord(r Record) error { return r.updateRecordState(c, "failed") } diff --git a/record.go b/record.go index 75d51fd..7e788fe 100644 --- a/record.go +++ b/record.go @@ -25,6 +25,10 @@ func getNextRecord(c Client) (*Record, error) { return nil, err } + if res.StatusCode == 404 { + return nil, nil + } + defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil {