Skip to content

Commit

Permalink
[CSGI-1984] Add From field to ListResponsePlays method options (#502
Browse files Browse the repository at this point in the history
)

* Adds `From` header to `ListResponsePlays` method options
* Updates `Client.get` signature to accept headers
  • Loading branch information
imjaroiswebdev authored Nov 2, 2023
1 parent 8ec1a2b commit bcffd24
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 75 deletions.
4 changes: 2 additions & 2 deletions ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *Client) ListAbilities() (*ListAbilityResponse, error) {

// ListAbilitiesWithContext lists all abilities on your account.
func (c *Client) ListAbilitiesWithContext(ctx context.Context) (*ListAbilityResponse, error) {
resp, err := c.get(ctx, "/abilities")
resp, err := c.get(ctx, "/abilities", nil)
if err != nil {
return nil, err
}
Expand All @@ -38,6 +38,6 @@ func (c *Client) TestAbility(ability string) error {

// TestAbilityWithContext checks if your account has the given ability.
func (c *Client) TestAbilityWithContext(ctx context.Context, ability string) error {
_, err := c.get(ctx, "/abilities/"+ability)
_, err := c.get(ctx, "/abilities/"+ability, nil)
return err
}
4 changes: 2 additions & 2 deletions addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Client) ListAddonsWithContext(ctx context.Context, o ListAddonOptions)
return nil, err
}

resp, err := c.get(ctx, "/addons?"+v.Encode())
resp, err := c.get(ctx, "/addons?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func (c *Client) GetAddon(id string) (*Addon, error) {

// GetAddonWithContext gets details about an existing add-on.
func (c *Client) GetAddonWithContext(ctx context.Context, id string) (*Addon, error) {
resp, err := c.get(ctx, "/addons/"+id)
resp, err := c.get(ctx, "/addons/"+id, nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *Client) ListAuditRecords(ctx context.Context, o ListAuditRecordsOptions
}

u := fmt.Sprintf("%s?%s", auditBaseURL, v.Encode())
resp, err := c.get(ctx, u)
resp, err := c.get(ctx, u, nil)
if err != nil {
return ListAuditRecordsResponse{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion business_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (c *Client) GetBusinessService(id string) (*BusinessService, error) {

// GetBusinessServiceWithContext gets details about a business service.
func (c *Client) GetBusinessServiceWithContext(ctx context.Context, id string) (*BusinessService, error) {
resp, err := c.get(ctx, "/business_services/"+id)
resp, err := c.get(ctx, "/business_services/"+id, nil)
return getBusinessServiceFromResponse(resp, err, c.decodeJSON)
}

Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ func (c *Client) post(ctx context.Context, path string, payload interface{}, hea
return c.do(ctx, http.MethodPost, path, bytes.NewBuffer(data), headers)
}

func (c *Client) get(ctx context.Context, path string) (*http.Response, error) {
return c.do(ctx, http.MethodGet, path, nil, nil)
func (c *Client) get(ctx context.Context, path string, headers map[string]string) (*http.Response, error) {
return c.do(ctx, http.MethodGet, path, nil, headers)
}

const (
Expand Down
8 changes: 4 additions & 4 deletions escalation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *Client) ListEscalationPoliciesWithContext(ctx context.Context, o ListEs
return nil, err
}

resp, err := c.get(ctx, escPath+"?"+v.Encode())
resp, err := c.get(ctx, escPath+"?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func (c *Client) GetEscalationPolicyWithContext(ctx context.Context, id string,
return nil, err
}

resp, err := c.get(ctx, escPath+"/"+id+"?"+v.Encode())
resp, err := c.get(ctx, escPath+"/"+id+"?"+v.Encode(), nil)
return getEscalationPolicyFromResponse(c, resp, err)
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func (c *Client) GetEscalationRuleWithContext(ctx context.Context, escID string,
return nil, err
}

resp, err := c.get(ctx, escPath+"/"+escID+"/escalation_rules/"+id+"?"+v.Encode())
resp, err := c.get(ctx, escPath+"/"+escID+"/escalation_rules/"+id+"?"+v.Encode(), nil)
return getEscalationRuleFromResponse(c, resp, err)
}

Expand Down Expand Up @@ -253,7 +253,7 @@ func (c *Client) ListEscalationRules(escID string) (*ListEscalationRulesResponse

// ListEscalationRulesWithContext lists all of the escalation rules for an existing escalation policy.
func (c *Client) ListEscalationRulesWithContext(ctx context.Context, escID string) (*ListEscalationRulesResponse, error) {
resp, err := c.get(ctx, escPath+"/"+escID+"/escalation_rules")
resp, err := c.get(ctx, escPath+"/"+escID+"/escalation_rules", nil)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions event_orchestration.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *Client) ListOrchestrationsWithContext(ctx context.Context, o ListOrches
return nil, err
}

resp, err := c.get(ctx, eoPath+"?"+v.Encode())
resp, err := c.get(ctx, eoPath+"?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (c *Client) GetOrchestrationWithContext(ctx context.Context, id string, o *
return nil, err
}

resp, err := c.get(ctx, eoPath+"/"+id+"?"+v.Encode())
resp, err := c.get(ctx, eoPath+"/"+id+"?"+v.Encode(), nil)
return getOrchestrationFromResponse(c, resp, err)
}

Expand Down Expand Up @@ -201,7 +201,7 @@ func (c *Client) GetOrchestrationRouterWithContext(ctx context.Context, id strin
return nil, err
}

resp, err := c.get(ctx, eoPath+"/"+id+"/router"+"?"+v.Encode())
resp, err := c.get(ctx, eoPath+"/"+id+"/router"+"?"+v.Encode(), nil)
return getOrchestrationRouterFromResponse(c, resp, err)
}

Expand Down Expand Up @@ -300,7 +300,7 @@ func (c *Client) GetServiceOrchestrationWithContext(ctx context.Context, id stri
return nil, err
}

resp, err := c.get(ctx, eoPath+"/services/"+id+"?"+v.Encode())
resp, err := c.get(ctx, eoPath+"/services/"+id+"?"+v.Encode(), nil)
return getServiceOrchestrationFromResponse(c, resp, err)
}

Expand All @@ -316,7 +316,7 @@ func (c *Client) UpdateServiceOrchestrationWithContext(ctx context.Context, id s

// GetServiceOrchestrationActiveWithContext gets a service orchestration's active status.
func (c *Client) GetServiceOrchestrationActiveWithContext(ctx context.Context, id string) (*ServiceOrchestrationActive, error) {
resp, err := c.get(ctx, eoPath+"/services/"+id+"/active")
resp, err := c.get(ctx, eoPath+"/services/"+id+"/active", nil)
return getServiceOrchestrationActiveFromResponse(c, resp, err)
}

Expand Down Expand Up @@ -413,7 +413,7 @@ func (c *Client) GetOrchestrationUnroutedWithContext(ctx context.Context, id str
return nil, err
}

resp, err := c.get(ctx, eoPath+"/"+id+"/unrouted"+"?"+v.Encode())
resp, err := c.get(ctx, eoPath+"/"+id+"/unrouted"+"?"+v.Encode(), nil)
return getOrchestrationUnroutedFromResponse(c, resp, err)
}

Expand Down
4 changes: 2 additions & 2 deletions extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) ListExtensionsWithContext(ctx context.Context, o ListExtensionO
return nil, err
}

resp, err := c.get(ctx, "/extensions?"+v.Encode())
resp, err := c.get(ctx, "/extensions?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *Client) GetExtension(id string) (*Extension, error) {

// GetExtensionWithContext gets an extension by its ID.
func (c *Client) GetExtensionWithContext(ctx context.Context, id string) (*Extension, error) {
resp, err := c.get(ctx, "/extensions/"+id)
resp, err := c.get(ctx, "/extensions/"+id, nil)
return getExtensionFromResponse(c, resp, err)
}

Expand Down
4 changes: 2 additions & 2 deletions extension_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *Client) ListExtensionSchemasWithContext(ctx context.Context, o ListExte
return nil, err
}

resp, err := c.get(ctx, "/extension_schemas?"+v.Encode())
resp, err := c.get(ctx, "/extension_schemas?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand All @@ -90,7 +90,7 @@ func (c *Client) GetExtensionSchema(id string) (*ExtensionSchema, error) {

// GetExtensionSchemaWithContext gets a single extension schema.
func (c *Client) GetExtensionSchemaWithContext(ctx context.Context, id string) (*ExtensionSchema, error) {
resp, err := c.get(ctx, "/extension_schemas/"+id)
resp, err := c.get(ctx, "/extension_schemas/"+id, nil)
return getExtensionSchemaFromResponse(c, resp, err)
}

Expand Down
28 changes: 14 additions & 14 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c *Client) ListIncidentsWithContext(ctx context.Context, o ListIncidentsOp
return nil, err
}

resp, err := c.get(ctx, "/incidents?"+v.Encode())
resp, err := c.get(ctx, "/incidents?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func (c *Client) GetIncident(id string) (*Incident, error) {

// GetIncidentWithContext shows detailed information about an incident.
func (c *Client) GetIncidentWithContext(ctx context.Context, id string) (*Incident, error) {
resp, err := c.get(ctx, "/incidents/"+id)
resp, err := c.get(ctx, "/incidents/"+id, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -389,7 +389,7 @@ func (c *Client) ListIncidentNotes(id string) ([]IncidentNote, error) {

// ListIncidentNotesWithContext lists existing notes for the specified incident.
func (c *Client) ListIncidentNotesWithContext(ctx context.Context, id string) ([]IncidentNote, error) {
resp, err := c.get(ctx, "/incidents/"+id+"/notes")
resp, err := c.get(ctx, "/incidents/"+id+"/notes", nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -485,7 +485,7 @@ func (c *Client) ListIncidentAlertsWithContext(ctx context.Context, id string, o
return nil, err
}

resp, err := c.get(ctx, "/incidents/"+id+"/alerts?"+v.Encode())
resp, err := c.get(ctx, "/incidents/"+id+"/alerts?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -626,7 +626,7 @@ func (c *Client) ListIncidentLogEntriesWithContext(ctx context.Context, id strin
return nil, err
}

resp, err := c.get(ctx, "/incidents/"+id+"/log_entries?"+v.Encode())
resp, err := c.get(ctx, "/incidents/"+id+"/log_entries?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -669,18 +669,18 @@ type ResponderRequestTargetWrapper struct {

// ResponderRequestOptions defines the input options for the Create Responder function.
type ResponderRequestOptions struct {
From string `json:"-"`
Message string `json:"message"`
RequesterID string `json:"requester_id"`
From string `json:"-"`
Message string `json:"message"`
RequesterID string `json:"requester_id"`
Targets []ResponderRequestTargetWrapper `json:"responder_request_targets"`
}

// ResponderRequest contains the API structure for an incident responder request.
type ResponderRequest struct {
Incident Incident `json:"incident"`
Requester User `json:"requester,omitempty"`
RequestedAt string `json:"request_at,omitempty"`
Message string `json:"message,omitempty"`
Incident Incident `json:"incident"`
Requester User `json:"requester,omitempty"`
RequestedAt string `json:"request_at,omitempty"`
Message string `json:"message,omitempty"`
Targets []ResponderRequestTargetWrapper `json:"responder_request_targets"`
}

Expand Down Expand Up @@ -719,7 +719,7 @@ func (c *Client) GetIncidentAlert(incidentID, alertID string) (*IncidentAlertRes

// GetIncidentAlertWithContext gets the alert that triggered the incident.
func (c *Client) GetIncidentAlertWithContext(ctx context.Context, incidentID, alertID string) (*IncidentAlertResponse, error) {
resp, err := c.get(ctx, "/incidents/"+incidentID+"/alerts/"+alertID)
resp, err := c.get(ctx, "/incidents/"+incidentID+"/alerts/"+alertID, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -826,7 +826,7 @@ type RemoveIncidentNotificationSubscribersResponse struct {

// ListIncidentNotificationSubscribersWithContext lists notification subscribers for the specified incident.
func (c *Client) ListIncidentNotificationSubscribersWithContext(ctx context.Context, id string) (*ListIncidentNotificationSubscribersResponse, error) {
resp, err := c.get(ctx, "/incidents/"+id+"/status_updates/subscribers")
resp, err := c.get(ctx, "/incidents/"+id+"/status_updates/subscribers", nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions license.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ListLicenseAllocationsOptions struct {

func (c *Client) ListLicensesWithContext(ctx context.Context) (*ListLicensesResponse, error) {

resp, err := c.get(ctx, "/licenses")
resp, err := c.get(ctx, "/licenses", nil)
if err != nil {
return nil, err
}
Expand All @@ -69,7 +69,7 @@ func (c *Client) ListLicenseAllocationsWithContext(ctx context.Context, o ListLi
return nil, err
}

resp, err := c.get(ctx, "/license_allocations?"+v.Encode())
resp, err := c.get(ctx, "/license_allocations?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions log_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Client) ListLogEntriesWithContext(ctx context.Context, o ListLogEntries
return nil, err
}

resp, err := c.get(ctx, "/log_entries?"+v.Encode())
resp, err := c.get(ctx, "/log_entries?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (c *Client) GetLogEntryWithContext(ctx context.Context, id string, o GetLog
return nil, err
}

resp, err := c.get(ctx, "/log_entries/"+id+"?"+v.Encode())
resp, err := c.get(ctx, "/log_entries/"+id+"?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions maintenance_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *Client) ListMaintenanceWindowsWithContext(ctx context.Context, o ListMa
return nil, err
}

resp, err := c.get(ctx, "/maintenance_windows?"+v.Encode())
resp, err := c.get(ctx, "/maintenance_windows?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func (c *Client) GetMaintenanceWindowWithContext(ctx context.Context, id string,
return nil, err
}

resp, err := c.get(ctx, "/maintenance_windows/"+id+"?"+v.Encode())
resp, err := c.get(ctx, "/maintenance_windows/"+id+"?"+v.Encode(), nil)
return getMaintenanceWindowFromResponse(c, resp, err)
}

Expand Down
2 changes: 1 addition & 1 deletion notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *Client) ListNotificationsWithContext(ctx context.Context, o ListNotific
return nil, err
}

resp, err := c.get(ctx, "/notifications?"+v.Encode())
resp, err := c.get(ctx, "/notifications?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion on_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) ListOnCallsWithContext(ctx context.Context, o ListOnCallOptions
return nil, err
}

resp, err := c.get(ctx, "/oncalls?"+v.Encode())
resp, err := c.get(ctx, "/oncalls?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion priorites.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Client) ListPrioritiesWithContext(ctx context.Context, o ListPriorities
return nil, err
}

resp, err := c.get(ctx, "/priorities?"+v.Encode())
resp, err := c.get(ctx, "/priorities?"+v.Encode(), nil)
if err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions response_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type ListResponsePlaysOptions struct {
FilterForManualRun bool `url:"filter_for_manual_run,omitempty"`

Query string `url:"query,omitempty"`

From string
}

// ListResponsePlays lists existing response plays.
Expand All @@ -51,7 +53,11 @@ func (c *Client) ListResponsePlays(ctx context.Context, o ListResponsePlaysOptio
return nil, err
}

resp, err := c.get(ctx, "/response_plays?"+v.Encode())
h := map[string]string{
"From": o.From,
}

resp, err := c.get(ctx, "/response_plays?"+v.Encode(), h)
if err != nil {
return nil, err
}
Expand All @@ -76,7 +82,7 @@ func (c *Client) CreateResponsePlay(ctx context.Context, rp ResponsePlay) (Respo

// GetResponsePlay gets details about an existing response play.
func (c *Client) GetResponsePlay(ctx context.Context, id string) (ResponsePlay, error) {
resp, err := c.get(ctx, "/response_plays/"+id)
resp, err := c.get(ctx, "/response_plays/"+id, nil)
return getResponsePlayFromResponse(c, resp, err)
}

Expand Down
Loading

0 comments on commit bcffd24

Please sign in to comment.