Merge pull request #8 from FlipsideCrypto/check-for-unread-count

change record back to using record with interface value for data
This commit is contained in:
Don Cote 2019-09-16 14:22:43 -04:00 committed by GitHub
commit ce1846977d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -22,15 +22,14 @@ func TestClient_GetUnreadCount(t *testing.T) {
func TestClient_GetNextRecord(t *testing.T) {
client := getClient(t)
r, err := client.GetNextRecord("b053b974-608e-4f1b-9969-871a02cfbf92")
record, err := client.GetNextRecord("b053b974-608e-4f1b-9969-871a02cfbf92")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if r == nil {
t.Fatal("Result is nil")
if record == nil {
t.Fatal("record is nil")
}
record := string(*r)
fmt.Fprintln(os.Stdout, "GetNextRecord")
fmt.Fprintln(os.Stdout, record)
}

View File

@ -11,8 +11,8 @@ import (
// Record represents a Data Bridge data record
type Record struct {
ID string `json:"id"`
Data []map[string]interface{} `json:"data"`
ID string `json:"id"`
Data interface{} `json:"data"`
}
// GetUnreadCount returns the count of unread records in the given topic in the context of the api key
@ -51,7 +51,7 @@ func (c Client) GetUnreadCount() (*int32, error) {
}
// GetNextRecord returns the topic's next record. Will return nil without an error when there are no more records.
func (c Client) GetNextRecord(consumerID string) (*json.RawMessage, error) {
func (c Client) GetNextRecord(consumerID string) (*Record, error) {
count, err := c.GetUnreadCount()
if err != nil {
return nil, err
@ -79,14 +79,14 @@ func (c Client) GetNextRecord(consumerID string) (*json.RawMessage, error) {
return nil, errors.Wrap(err, "error trying to read databridge response body")
}
var result json.RawMessage
var record Record
err = json.Unmarshal([]byte(body), &result)
err = json.Unmarshal([]byte(body), &record)
if err != nil {
return nil, errors.Wrap(err, "error trying to unmarshal response body to json")
}
return &result, nil
return &record, nil
}
// CompleteRecord allows the record to be marked as completed