diff --git a/README.md b/README.md index 8591e94..8a4cbf7 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,28 @@ https://data-bridge-docs.flipsidecrypto.com/#section/Introduction ### Initialization ``` -config := Config{APIKey: "api-key", TopicSlug: "my-topic-slug", ConsumerID: "consumer-id"} +config := Config{APIKey: "api-key", TopicSlug: "my-topic-slug"} client, err := NewClient(config) ``` +### Get Registered Consumers +``` +consumers, err := client.GetRegisteredConsumers() +``` + +### Get Available Consumers +``` +consumers, err := client.GetAvailableConsumers() +``` + +### Register Consumer +``` +consumer, err := client.RegisterConsumer() +``` + ### Get Next Record ``` -record, err := client.GetNextRecord() +record, err := client.GetNextRecord(consumerID) ``` ### Mark Record Completed diff --git a/client.go b/client.go index e4ca6a2..3a1c64b 100644 --- a/client.go +++ b/client.go @@ -2,17 +2,15 @@ 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 + APIKey string + TopicSlug string } // Client allows access to the Databridge API type Client struct { - BaseURL string - APIKey string - TopicSlug string - ConsumerID string + BaseURL string + APIKey string + TopicSlug string } // NewClient returns a new Databridge Client @@ -21,7 +19,6 @@ func NewClient(config Config) (Client, error) { c.APIKey = config.APIKey c.BaseURL = "https://data-bridge.flipsidecrypto.com/api/v1" c.TopicSlug = config.TopicSlug - c.ConsumerID = config.ConsumerID return c, nil } diff --git a/client_test.go b/client_test.go index 80f36a7..645c159 100644 --- a/client_test.go +++ b/client_test.go @@ -22,7 +22,7 @@ func TestClient_GetUnreadCount(t *testing.T) { func TestClient_GetNextRecord(t *testing.T) { client := getClient(t) - r, err := client.GetNextRecord() + r, err := client.GetNextRecord("b053b974-608e-4f1b-9969-871a02cfbf92") if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -69,7 +69,7 @@ func TestClient_RegisterConsumer(t *testing.T) { } func getClient(t *testing.T) Client { - config := Config{APIKey: "15d4fbbc-d12e-4b08-a4d6-b55b92200649", TopicSlug: "dev-alert-fcas-events", ConsumerID: "84d3cba6-8be8-4848-b759-59093f2e74e6"} + config := Config{APIKey: "15d4fbbc-d12e-4b08-a4d6-b55b92200649", TopicSlug: "dev-alert-fcas-events"} client, err := NewClient(config) if err != nil { t.Fatalf("Unexpected error: %v", err) diff --git a/record.go b/record.go index c14ad43..2759ab4 100644 --- a/record.go +++ b/record.go @@ -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() (*json.RawMessage, error) { +func (c Client) GetNextRecord(consumerID string) (*json.RawMessage, error) { count, err := c.GetUnreadCount() if err != nil { return nil, err @@ -59,7 +59,7 @@ func (c Client) GetNextRecord() (*json.RawMessage, error) { return nil, nil } - url := fmt.Sprintf("%s/topics/%s/records/next?consumer_id=%s&api_key=%s", c.BaseURL, c.TopicSlug, c.ConsumerID, c.APIKey) + url := fmt.Sprintf("%s/topics/%s/records/next?consumer_id=%s&api_key=%s", c.BaseURL, c.TopicSlug, consumerID, c.APIKey) req, _ := http.NewRequest("GET", url, nil) req.Header.Add("content-type", "application/json") req.Header.Add("api_key", c.APIKey)