-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package sentry | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type NotificationActionsService service | ||
|
||
type CreateNotificationActionParams struct { | ||
TriggerType *string `json:"triggerType"` | ||
ServiceType *string `json:"serviceType"` | ||
IntegrationId json.Number `json:"integrationId,omitempty"` | ||
TargetIdentifier interface{} `json:"targetIdentifier,omitempty"` | ||
TargetDisplay *string `json:"targetDisplay,omitempty"` | ||
TargetType *string `json:"targetType,omitempty"` | ||
Projects []string `json:"projects"` | ||
} | ||
|
||
type NotificationAction struct { | ||
ID json.Number `json:"id"` | ||
OrganizationId *string `json:"organizationId"` | ||
TriggerType *string `json:"triggerType"` | ||
ServiceType *string `json:"serviceType"` | ||
IntegrationId json.Number `json:"integrationId"` | ||
TargetIdentifier interface{} `json:"targetIdentifier"` | ||
TargetDisplay *string `json:"targetDisplay"` | ||
TargetType *string `json:"targetType"` | ||
Projects []int `json:"projects"` | ||
} | ||
|
||
func (s *NotificationActionsService) Get(ctx context.Context, organizationSlug string, actionId string) (*NotificationAction, *Response, error) { | ||
u := fmt.Sprintf("0/organizations/%v/notifications/actions/%v/", organizationSlug, actionId) | ||
req, err := s.client.NewRequest(http.MethodGet, u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
action := &NotificationAction{} | ||
resp, err := s.client.Do(ctx, req, action) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return action, resp, nil | ||
} | ||
|
||
func (s *NotificationActionsService) Create(ctx context.Context, organizationSlug string, params *CreateNotificationActionParams) (*NotificationAction, *Response, error) { | ||
u := fmt.Sprintf("0/organizations/%v/notifications/actions/", organizationSlug) | ||
req, err := s.client.NewRequest(http.MethodPost, u, params) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
action := &NotificationAction{} | ||
resp, err := s.client.Do(ctx, req, action) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return action, resp, nil | ||
} | ||
|
||
func (s *NotificationActionsService) Update(ctx context.Context, organizationSlug string, actionId string, params *CreateNotificationActionParams) (*NotificationAction, *Response, error) { | ||
u := fmt.Sprintf("0/organizations/%v/notification/actions/%v/", organizationSlug, actionId) | ||
req, err := s.client.NewRequest(http.MethodPut, u, params) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
action := &NotificationAction{} | ||
resp, err := s.client.Do(ctx, req, action) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return action, resp, nil | ||
} | ||
|
||
func (s *NotificationActionsService) Delete(ctx context.Context, organizationSlug string, actionId string) (*Response, error) { | ||
u := fmt.Sprintf("0/organizations/%v/notifications/actions/%v/", organizationSlug, actionId) | ||
req, err := s.client.NewRequest(http.MethodDelete, u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package sentry | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNotificationActionsService_Get(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/api/0/organizations/organization_slug/notifications/actions/action_id/", func(w http.ResponseWriter, r *http.Request) { | ||
assertMethod(t, http.MethodGet, r) | ||
fmt.Fprintf(w, `{ | ||
"id": "836501735", | ||
"organizationId": "62848264", | ||
"serviceType": "sentry_notification", | ||
"targetDisplay": "default", | ||
"targetIdentifier": "default", | ||
"targetType": "specific", | ||
"triggerType": "spike-protection", | ||
"projects": [ | ||
4505321021243392 | ||
] | ||
}`) | ||
}) | ||
|
||
ctx := context.Background() | ||
action, _, err := client.NotificationActions.Get(ctx, "organization_slug", "action_id") | ||
assert.NoError(t, err) | ||
|
||
expected := &NotificationAction{ | ||
ID: json.Number("836501735"), | ||
OrganizationId: String("62848264"), | ||
TriggerType: String("spike-protection"), | ||
ServiceType: String("sentry_notification"), | ||
TargetIdentifier: "default", | ||
TargetDisplay: String("default"), | ||
TargetType: String("specific"), | ||
Projects: []int{4505321021243392}, | ||
} | ||
assert.Equal(t, expected, action) | ||
} | ||
|
||
func TestNotificationActionsService_Create(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/api/0/organizations/organization_slug/notifications/actions/", func(w http.ResponseWriter, r *http.Request) { | ||
assertMethod(t, http.MethodPost, r) | ||
assertPostJSON(t, map[string]interface{}{ | ||
"projects": []interface{}{"go"}, | ||
"serviceType": "sentry_notification", | ||
"targetDisplay": "default", | ||
"targetIdentifier": "default", | ||
"targetType": "specific", | ||
"triggerType": "spike-protection", | ||
}, r) | ||
w.WriteHeader(http.StatusCreated) | ||
fmt.Fprintf(w, `{ | ||
"id": "836501735", | ||
"organizationId": "62848264", | ||
"serviceType": "sentry_notification", | ||
"targetDisplay": "default", | ||
"targetIdentifier": "default", | ||
"targetType": "specific", | ||
"triggerType": "spike-protection", | ||
"projects": [ | ||
4505321021243392 | ||
] | ||
}`) | ||
}) | ||
|
||
params := &CreateNotificationActionParams{ | ||
TriggerType: String("spike-protection"), | ||
ServiceType: String("sentry_notification"), | ||
TargetIdentifier: String("default"), | ||
TargetDisplay: String("default"), | ||
TargetType: String("specific"), | ||
Projects: []string{"go"}, | ||
} | ||
ctx := context.Background() | ||
action, _, err := client.NotificationActions.Create(ctx, "organization_slug", params) | ||
assert.NoError(t, err) | ||
|
||
expected := &NotificationAction{ | ||
ID: json.Number("836501735"), | ||
OrganizationId: String("62848264"), | ||
TriggerType: String("spike-protection"), | ||
ServiceType: String("sentry_notification"), | ||
TargetIdentifier: "default", | ||
TargetDisplay: String("default"), | ||
TargetType: String("specific"), | ||
Projects: []int{4505321021243392}, | ||
} | ||
assert.Equal(t, expected, action) | ||
} | ||
|
||
func TestNotificationActionsService_Delete(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/api/0/organizations/organization_slug/notifications/actions/action_id/", func(w http.ResponseWriter, r *http.Request) { | ||
assertMethod(t, http.MethodDelete, r) | ||
}) | ||
|
||
ctx := context.Background() | ||
_, err := client.NotificationActions.Delete(ctx, "organization_slug", "action_id") | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters