Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

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 CreateIncidents and start the names at ResponderRequest? So, this struct would be ResponderRequestResponse.

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ResponderRequestPayload struct with json tags and add that to the ResponderRequestOptions?


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 */
35 changes: 35 additions & 0 deletions incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}]}`))
Copy link
Contributor

Choose a reason for hiding this comment

The 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 := "[email protected]"

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)
}