Skip to content

Commit

Permalink
Merge pull request #63 from EshaanAgg/add_integrations
Browse files Browse the repository at this point in the history
Add all the methods for Integration endpoint
  • Loading branch information
Cliftonz authored Oct 17, 2023
2 parents 8f79e77 + 66b350e commit f8c99af
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 26 deletions.
58 changes: 32 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Novu's API exposes the entire Novu features via a standardized programmatic interface. Please refer to the full [documentation](https://docs.novu.co/docs/overview/introduction) to learn more.

## Installation & Usage

Install the package to your GoLang project.

```golang
go get github.com/novuhq/go-novu
```
Expand Down Expand Up @@ -61,35 +63,39 @@ func main() {
fmt.Println(integrations)
}
```

**NOTE**
Check the `cmd` directory to see a sample implementation and test files to see sample tests

## Documentation for API Endpoints

Class | Method | HTTP request | Description
------------ |----------------------------------------------------------------------------------|-----------------------------------------| -------------
*EventApi* | [**Trigger**](https://docs.novu.co/platform/subscribers#removing-a-subscriber) | **Post** /events/trigger | Trigger
*EventApi* | [**TriggerBulk**](https://docs.novu.co/api/trigger-event/) | **Post** /v1/events/trigger/bulk | Bulk trigger event
*EventApi* | [**BroadcastToAll**](https://docs.novu.co/api/broadcast-event-to-all/) | **Post** /v1/events/trigger/broadcast | Broadcast event to all
*EventApi* | [**CancelTrigger**](https://docs.novu.co/api/cancel-triggered-event/) | **Delete** /v1/events/trigger/:transactionId | Cancel triggered event
*SubscriberApi* | [**Get**](https://docs.novu.co/api/get-subscriber/) | **Get** /subscribers/:subscriberId | Get a subscriber
*SubscriberApi* | [**Identify**](https://docs.novu.co/platform/subscribers#creating-a-subscriber) | **Post** /subscribers | Create a subscriber
*SubscriberApi* | [**Update**](https://docs.novu.co/platform/subscribers#updating-subscriber-data) | **Put** /subscribers/:subscriberID | Update subscriber data
*SubscriberApi* | [**Delete**](https://docs.novu.co/platform/subscribers#removing-a-subscriber) | **Delete** /subscribers/:subscriberID | Removing a subscriber
*SubscriberApi* | [**Get**](https://docs.novu.co/api/get-a-notification-feed-for-a-particular-subscriber) | **Get** /subscribers/:subscriberId/notifications/feed | Get a notification feed for a particular subscriber
*SubscriberApi* | [**Get**](https://docs.novu.co/api/get-the-unseen-notification-count-for-subscribers-feed) | **Get** /subscribers/:subscriberId/notifications/feed | Get the unseen notification count for subscribers feed
*SubscriberApi* | [**Post**](https://docs.novu.co/api/mark-a-subscriber-feed-message-as-seen) | **Post** /v1/subscribers/:subscriberId/messages/markAs | Mark a subscriber feed message as seen
*SubscriberApi* | [**Get**](https://docs.novu.co/api/get-subscriber-preferences/) | **Get** /subscribers/:subscriberId/preferences | Get subscriber preferences
*SubscriberApi* | [**Patch**](https://docs.novu.co/api/update-subscriber-preference/) | **Patch** /subscribers/:subscriberId/preferences/:templateId | Update subscriber preference
*IntegrationsApi* | [**Create**](https://docs.novu.co/platform/integrations) | **Post** /integrations | Create an integration
*IntegrationsApi* | [**Update**](https://docs.novu.co/platform/integrations) | **Put** /integrations/:integrationId | Update an integration
*IntegrationsApi* | [**Delete**](https://docs.novu.co/platform/integrations) | **Delete** /integrations/:integrationId | Delete an integration
*IntegrationsApi* | [**Get**](https://docs.novu.co/platform/integrations) | **Get** /integrations | Get all integrations
*IntegrationsApi* | [**GetActive**](https://docs.novu.co/platform/intergations) | **Get** /integrations/active | Get all active integrations

*InboundParserApi* | [**Get**](https://docs.novu.co/platform/inbound-parse-webhook/) | **Get** /inbound-parse/mx/status | Validate the mx record setup for the inbound parse functionality
| Class | Method | HTTP request | Description |
| ----------------- | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------ |
| _EventApi_ | [**Trigger**](https://docs.novu.co/platform/subscribers#removing-a-subscriber) | **Post** /events/trigger | Trigger |
| _EventApi_ | [**TriggerBulk**](https://docs.novu.co/api/trigger-event/) | **Post** /v1/events/trigger/bulk | Bulk trigger event |
| _EventApi_ | [**BroadcastToAll**](https://docs.novu.co/api/broadcast-event-to-all/) | **Post** /v1/events/trigger/broadcast | Broadcast event to all |
| _EventApi_ | [**CancelTrigger**](https://docs.novu.co/api/cancel-triggered-event/) | **Delete** /v1/events/trigger/:transactionId | Cancel triggered event |
| _SubscriberApi_ | [**Get**](https://docs.novu.co/api/get-subscriber/) | **Get** /subscribers/:subscriberId | Get a subscriber |
| _SubscriberApi_ | [**Identify**](https://docs.novu.co/platform/subscribers#creating-a-subscriber) | **Post** /subscribers | Create a subscriber |
| _SubscriberApi_ | [**Update**](https://docs.novu.co/platform/subscribers#updating-subscriber-data) | **Put** /subscribers/:subscriberID | Update subscriber data |
| _SubscriberApi_ | [**Delete**](https://docs.novu.co/platform/subscribers#removing-a-subscriber) | **Delete** /subscribers/:subscriberID | Removing a subscriber |
| _SubscriberApi_ | [**Get**](https://docs.novu.co/api/get-a-notification-feed-for-a-particular-subscriber) | **Get** /subscribers/:subscriberId/notifications/feed | Get a notification feed for a particular subscriber |
| _SubscriberApi_ | [**Get**](https://docs.novu.co/api/get-the-unseen-notification-count-for-subscribers-feed) | **Get** /subscribers/:subscriberId/notifications/feed | Get the unseen notification count for subscribers feed |
| _SubscriberApi_ | [**Post**](https://docs.novu.co/api/mark-a-subscriber-feed-message-as-seen) | **Post** /v1/subscribers/:subscriberId/messages/markAs | Mark a subscriber feed message as seen |
| _SubscriberApi_ | [**Get**](https://docs.novu.co/api/get-subscriber-preferences/) | **Get** /subscribers/:subscriberId/preferences | Get subscriber preferences |
| _SubscriberApi_ | [**Patch**](https://docs.novu.co/api/update-subscriber-preference/) | **Patch** /subscribers/:subscriberId/preferences/:templateId | Update subscriber preference |
| _IntegrationsApi_ | [**Create**](https://docs.novu.co/platform/integrations) | **Post** /integrations | Create an integration |
| _IntegrationsApi_ | [**Update**](https://docs.novu.co/platform/integrations) | **Put** /integrations/:integrationId | Update an integration |
| _IntegrationsApi_ | [**Delete**](https://docs.novu.co/platform/integrations) | **Delete** /integrations/:integrationId | Delete an integration |
| _IntegrationsApi_ | [**Get**](https://docs.novu.co/platform/integrations) | **Get** /integrations | Get all integrations |
| _IntegrationsApi_ | [**GetActive**](https://docs.novu.co/platform/intergations) | **Get** /integrations/active | Get all active integrations |
| _IntegrationsApi_ | [**SetIntegrationAsPrimary**](https://docs.novu.co/platform/intergations) | **Post** /integrations/{integrationId}/set-primary | Set the integration as primary |
| _IntegrationsApi_ | [**GetChannelLimit**](https://docs.novu.co/platform/intergations) | **Get** /integrations/{channelType}/limit | Get the limits of the channel |

_InboundParserApi_ | [**Get**](https://docs.novu.co/platform/inbound-parse-webhook/) | **Get** /inbound-parse/mx/status | Validate the mx record setup for the inbound parse functionality

## Authorization (api-key)

## Authorization (api-key)

- **Type**: API key
Expand All @@ -106,7 +112,7 @@ As always, if you need additional assistance, join our Discord us a note [here](

## Contributors

Name |
------------ |
[Oyewole Samuel](https://github.com/samsoft00) |
[Dima Grossman](https://github.com/scopsy) |
| Name |
| ---------------------------------------------- |
| [Oyewole Samuel](https://github.com/samsoft00) |
| [Dima Grossman](https://github.com/scopsy) |
38 changes: 38 additions & 0 deletions lib/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type IIntegration interface {
GetWebhookSupportStatus(ctx context.Context, providerId string) (bool, error)
Update(ctx context.Context, integrationId string, request UpdateIntegrationRequest) (*IntegrationResponse, error)
Delete(ctx context.Context, integrationId string) (*IntegrationResponse, error)
SetIntegrationAsPrimary(ctx context.Context, integrationId string) (*SetIntegrationAsPrimaryResponse, error)
GetChannelLimit(ctx context.Context, channelType string) (*IntegrationChannelLimitResponse, error)
}

type IntegrationService service
Expand Down Expand Up @@ -148,3 +150,39 @@ func (i IntegrationService) Delete(ctx context.Context, integrationId string) (*

return &response, nil
}

func (i IntegrationService) SetIntegrationAsPrimary(ctx context.Context, integrationId string) (*SetIntegrationAsPrimaryResponse, error) {
var response SetIntegrationAsPrimaryResponse

URL := i.client.config.BackendURL.JoinPath("integrations", integrationId, "set-primary")

req, err := http.NewRequestWithContext(ctx, http.MethodPost, URL.String(), http.NoBody)
if err != nil {
return nil, err
}

_, err = i.client.sendRequest(req, &response)
if err != nil {
return nil, err
}

return &response, nil
}

func (i IntegrationService) GetChannelLimit(ctx context.Context, channelType string) (*IntegrationChannelLimitResponse, error) {
var response IntegrationChannelLimitResponse

URL := i.client.config.BackendURL.JoinPath("integrations", channelType, "limit")

req, err := http.NewRequestWithContext(ctx, http.MethodGet, URL.String(), http.NoBody)
if err != nil {
return nil, err
}

_, err = i.client.sendRequest(req, &response)
if err != nil {
return nil, err
}

return &response, nil
}
52 changes: 52 additions & 0 deletions lib/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,55 @@ func TestDeleteActiveIntegration_Success(t *testing.T) {

require.NoError(t, err)
}

func TestSetIntegrationAsPrimary_Success(t *testing.T) {
const integrationId = "IntegrationId"

var response *lib.SetIntegrationAsPrimaryResponse
fileToStruct(filepath.Join("../testdata", "set_integration_as_primary_response.json"), &response)

httpServer := IntegrationTestServer(t, IntegrationServerOptions[interface{}]{
ExpectedRequest: IntegrationRequestDetails[interface{}]{
Url: fmt.Sprintf("/v1/integrations/%s/set-primary", integrationId),
Method: http.MethodPost,
},
ExpectedResponse: IntegrationResponseDetails{
StatusCode: http.StatusOK,
Body: response,
},
})

ctx := context.Background()
novuClient := lib.NewAPIClient(novuApiKey, &lib.Config{BackendURL: lib.MustParseURL(httpServer.URL)})

res, err := novuClient.IntegrationsApi.SetIntegrationAsPrimary(ctx, integrationId)

assert.Equal(t, response, res)
require.NoError(t, err)
}

func TestGetChannelLimit_Success(t *testing.T) {
const channelType = "ChannelType"

var response *lib.IntegrationChannelLimitResponse
fileToStruct(filepath.Join("../testdata", "integration_channel_limit_response.json"), &response)

httpServer := IntegrationTestServer(t, IntegrationServerOptions[interface{}]{
ExpectedRequest: IntegrationRequestDetails[interface{}]{
Url: fmt.Sprintf("/v1/integrations/%s/limit", channelType),
Method: http.MethodGet,
},
ExpectedResponse: IntegrationResponseDetails{
StatusCode: http.StatusOK,
Body: response,
},
})

ctx := context.Background()
novuClient := lib.NewAPIClient(novuApiKey, &lib.Config{BackendURL: lib.MustParseURL(httpServer.URL)})

res, err := novuClient.IntegrationsApi.GetChannelLimit(ctx, channelType)

assert.Equal(t, response, res)
require.NoError(t, err)
}
24 changes: 24 additions & 0 deletions lib/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,30 @@ type GetIntegrationsResponse struct {
Data []Integration `json:"data"`
}

type IntegrationChannelLimitResponse struct {
Data struct {
Limit int `json:"limit"`
Count int `json:"count"`
} `json:"data"`
}

type SetIntegrationAsPrimaryResponse struct {
Data struct {
ID string `json:"_id"`
EnvironmentID string `json:"_environmentId"`
OrganizationID string `json:"_organizationId"`
Name string `json:"name"`
Identifier string `json:"identifier"`
ProviderID string `json:"providerId"`
Channel string `json:"channel"`
Credentials IntegrationCredentials `json:"credentials"`
Active bool `json:"active"`
Deleted bool `json:"deleted"`
DeletedAt string `json:"deletedAt"`
DeletedBy string `json:"deletedBy"`
Primary bool `json:"primary"`
} `json:"data"`
}
type BulkTriggerOptions struct {
Name interface{} `json:"name,omitempty"`
To interface{} `json:"to,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions testdata/integration_channel_limit_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"data": {
"limit": 0,
"count": 0
}
}
43 changes: 43 additions & 0 deletions testdata/set_integration_as_primary_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"data": {
"_id": "string",
"_environmentId": "string",
"_organizationId": "string",
"name": "string",
"identifier": "string",
"providerId": "string",
"channel": "in_app",
"credentials": {
"apiKey": "string",
"user": "string",
"secretKey": "string",
"domain": "string",
"password": "string",
"host": "string",
"port": "string",
"secure": true,
"region": "string",
"accountSid": "string",
"messageProfileId": "string",
"token": "string",
"from": "string",
"senderName": "string",
"projectName": "string",
"applicationId": "string",
"clientId": "string",
"requireTls": true,
"ignoreTls": true,
"baseUrl": "string",
"webhookUrl": "string",
"redirectUrl": "string",
"hmac": true,
"serviceAccount": "string",
"ipPoolName": "string"
},
"active": true,
"deleted": true,
"deletedAt": "string",
"deletedBy": "string",
"primary": true
}
}

0 comments on commit f8c99af

Please sign in to comment.