-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the Incident endpoint for ResponderRequest #196
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,4 +380,46 @@ type ListAlertResponse struct { | |
Alerts []Alert `json:"alerts,omitempty"` | ||
} | ||
|
||
/* TODO: Manage Alerts, Get Alert, Create Status Updates, Create Responder Request, */ | ||
// CreateIncidentResponderRequestResponse | ||
type CreateIncidentResponderRequestResponse struct { | ||
ResponderRequest ResponderRequest `json:"responder_request"` | ||
} | ||
|
||
// CreateIncidentResponderRequestOptions defines the input options for the Create Responder function. | ||
type CreateIncidentResponderRequestOptions struct { | ||
From string | ||
Message string | ||
RequesterID string | ||
Targets []APIObject | ||
} | ||
|
||
// ResponderRequest contains the API structure for an incident responder request. | ||
type ResponderRequest struct { | ||
Incident Incident `json:"incident"` | ||
Requester User `json:"user,omitempty"` | ||
RequestedAt string `json:"request_at,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
Targets []APIObject `json:"responder_request_targets,omitempty"` | ||
} | ||
|
||
// CreateIncidentResponderRequest will submit a request to have a responder join an incident. | ||
func (c *Client) CreateIncidentResponderRequest(id string, o CreateIncidentResponderRequestOptions) (*CreateIncidentResponderRequestResponse, error) { | ||
data := make(map[string]interface{}) | ||
headers := make(map[string]string) | ||
headers["From"] = o.From | ||
|
||
data["message"] = o.Message | ||
data["request_id"] = o.RequesterID | ||
data["responder_request_targets"] = o.Targets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than piece out each field in the payload object, will you create a |
||
|
||
resp, err := c.post("/incidents/"+id+"/responder_requests", data, &headers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result := &CreateIncidentResponderRequestResponse{} | ||
err = json.NewDecoder(resp.Body).Decode(result) | ||
return result, err | ||
} | ||
|
||
/* TODO: Manage Alerts, Get Alert, Create Status Updates */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,3 +341,38 @@ func TestIncident_ListLogEntries(t *testing.T) { | |
} | ||
testEqual(t, want, res) | ||
} | ||
|
||
func TestIncident_ResponderRequest(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
id := "1" | ||
mux.HandleFunc("/incidents/"+id+"/responder_requests", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "POST") | ||
w.Write([]byte(`{"requester_id": "PL1JMK5", "message": "Help", "responder_request_targets": [{"responder_request_target":{"id":"PJ25ZYX","type":"user_reference"}}]}`)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is supposed to match the JSON of the response you're expecting. Can you change it to reflect the response? |
||
}) | ||
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient} | ||
from := "foo@bar.com" | ||
|
||
input := CreateIncidentResponderRequestOptions{ | ||
From: from, | ||
Message: "help", | ||
RequesterID: "PL1JMK5", | ||
Targets: []APIObject{ | ||
APIObject{ID: "PJ25ZYX", Type: "user_reference"}, | ||
}, | ||
} | ||
|
||
want := &CreateIncidentResponderRequestResponse{ | ||
ResponderRequest: ResponderRequest{ | ||
Incident: Incident{}, | ||
Requester: User{}, | ||
}, | ||
} | ||
res, err := client.CreateIncidentResponderRequest(id, input) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
testEqual(t, want, res) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll go with a shorter name. Will you remove all the
CreateIncident
s and start the names atResponderRequest
? So, this struct would beResponderRequestResponse
.