Skip to content

Commit

Permalink
added maintenace_window,tags,priority,incident_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dheeruk12 committed Jul 18, 2022
1 parent 4b309b2 commit 8217b26
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 34 deletions.
39 changes: 21 additions & 18 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@ type Config struct {
}

type Client struct {
baseURL *url.URL
client *http.Client
Config *Config
Teams *TeamService
Services *Service
Schedules *ScheduleService
Roles *RoleService
Integrations *IntegrationServerice
Incidents *IncidentService
Esp *EspService
Members *MemberService
Invite *InviteService
Users *UserService
AlertRules *AlertRuleService
Priority *PriorityService
Tags *TagsService
baseURL *url.URL
client *http.Client
Config *Config
Teams *TeamService
Services *Service
Schedules *ScheduleService
Roles *RoleService
Integrations *IntegrationServerice
Incidents *IncidentService
Esp *EspService
Members *MemberService
Invite *InviteService
Users *UserService
AlertRules *AlertRuleService
Priority *PriorityService
Tags *TagsService
MaintenanceWindow *MaintenanceWindowService
}

type Response struct {
Expand Down Expand Up @@ -79,6 +80,7 @@ func NewClient(config *Config) (*Client, error) {
c.AlertRules = &AlertRuleService{c}
c.Priority = &PriorityService{c}
c.Tags = &TagsService{c}
c.MaintenanceWindow = &MaintenanceWindowService{c}

return c, nil

Expand Down Expand Up @@ -154,9 +156,10 @@ func (c *Client) checkResponse(res *Response) error {

func (c *Client) decodeErrorResponse(res *Response) error {

v := &errorResponse{Error: &Error{ErrorResponse: res}}
v := &errorResponse{Error: &Error{ErrorResponse: res, Code: res.Response.StatusCode}}
if err := c.DecodeJSON(res, v); err != nil {
return fmt.Errorf("%s API call to %s failed: %v", res.Response.Request.Method, res.Response.Request.URL.String(), res.Response.Status)

return fmt.Errorf("%s APIs call to %s failed: %v", res.Response.Request.Method, res.Response.Request.URL.String(), res.Response.Status)
}

return v.Error
Expand Down
2 changes: 1 addition & 1 deletion client/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ type Error struct {
}

func (e *Error) Error() string {
return fmt.Sprintf("%s API call to %s failed %v. Code: %d, Errors: %v, Message: %s", e.ErrorResponse.Response.Request.Method, e.ErrorResponse.Response.Request.URL.String(), e.ErrorResponse.Response.Status, e.Code, e.Errors, e.Message)
return fmt.Sprintf("%s API call to %s failed %v. Errors: %s, Message: %s", e.ErrorResponse.Response.Request.Method, e.ErrorResponse.Response.Request.URL.String(), e.ErrorResponse.Response.Status, e.ErrorResponse.Response.Request.Body, e.Message)
}
90 changes: 90 additions & 0 deletions client/maintenance_window.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package client

import (
"encoding/json"
"fmt"
)

type MaintenanceWindowService service

type ServiceMaintenance struct {
UniqueID string `json:"unique_id,omitempty"`
Service string `json:"service"`
}

type MaintenanceWindow struct {
UniqueID string `json:"unique_id,omitempty"`
Name string `json:"name"`
RepeatInterval int `json:"repeat_interval,omitempty"`
RepeatUntil string `json:"repeat_until,omitempty"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
TimeZone string `json:"time_zone"`
Services []ServiceMaintenance `json:"services"`
Creation_Date string `json:"creation_date"`
}

func (c *MaintenanceWindowService) CreateMaintenanceWindow(team string, maintenance *MaintenanceWindow) (*MaintenanceWindow, error) {
path := fmt.Sprintf("/api/account/teams/%s/maintenance/", team)
body, err := c.client.newRequestDo("POST", path, maintenance)
if err != nil {
return nil, err
}
var s MaintenanceWindow
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *MaintenanceWindowService) UpdateMaintenanceWindow(team string, maintenance_id string, maintenance *MaintenanceWindow) (*MaintenanceWindow, error) {
path := fmt.Sprintf("/api/account/teams/%s/maintenance/%s/", team, maintenance_id)
body, err := c.client.newRequestDo("PUT", path, maintenance)
if err != nil {
return nil, err
}
var s MaintenanceWindow
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *MaintenanceWindowService) GetMaintenanceWindows(team string) ([]MaintenanceWindow, error) {
path := fmt.Sprintf("/api/account/teams/%s/maintenance/", team)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s []MaintenanceWindow
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return s, nil
}

func (c *MaintenanceWindowService) DeleteMaintenanceWindow(team string, maintenance_id string) error {
path := fmt.Sprintf("/api/account/teams/%s/maintenance/%s/", team, maintenance_id)
_, err := c.client.newRequestDo("DELETE", path, nil)
if err != nil {
return err
}
return nil
}

func (c *MaintenanceWindowService) GetMaintenanceWindowById(team string, maintenance_id string) (*MaintenanceWindow, error) {
path := fmt.Sprintf("/api/account/teams/%s/maintenance/%s/", team, maintenance_id)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s MaintenanceWindow
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}
17 changes: 13 additions & 4 deletions client/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import (
type PriorityService service

type Priority struct {
Unique_Id string `json:"unique_id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Color string `json:"color"`
Team int `json:"team,omitempty"`
Creation_Date string `json:"creation_date,omitempty"`
}

type ReadPriority struct {
Unique_Id string `json:"unique_id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Expand All @@ -30,27 +39,27 @@ func (c *PriorityService) CreatePriority(team string, priority *Priority) (*Prio
return &s, nil
}

func (c *PriorityService) GetPriority(team string) ([]Priority, error) {
func (c *PriorityService) GetPriority(team string) ([]ReadPriority, error) {
path := fmt.Sprintf("/api/account/teams/%s/priority/", team)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s []Priority
var s []ReadPriority
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return s, nil
}

func (c *PriorityService) GetPriorityById(team, id string) (*Priority, error) {
func (c *PriorityService) GetPriorityById(team, id string) (*ReadPriority, error) {
path := fmt.Sprintf("/api/account/teams/%s/priority/%s/", team, id)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s Priority
var s ReadPriority
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
Expand Down
12 changes: 7 additions & 5 deletions client/schedules.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ type Restrictions struct {
Duration int `json:"duration"`
StartDayOfWeek int `json:"start_day_of_week"`
StartTimeOfDay string `json:"start_time_of_day"`
Unique_Id string `json:"unique_id",omitempty`
Unique_Id string `json:"unique_id,omitempty"`
}
type Users struct {
User string `json:"user"`
Position int `json:"position"`
Unique_Id string `json:"unique_id",omitempty`
Unique_Id string `json:"unique_id,omitempty"`
}

type Overrides struct {
Name string `json:"name"`
User string `json:"user"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Unique_Id string `json:"unique_id",omitempty`
Unique_Id string `json:"unique_id,omitempty"`
}
type Layers struct {
ShiftLength int `json:"shift_length"`
Expand All @@ -42,13 +42,15 @@ type Layers struct {
type CreateUserLayer struct {
User string `json:"user"`
}

type CreateLayers struct {
ShiftLength int `json:"shift_length"`
Name string `json:"name"`
RotationStartTime string `json:"rotation_start_time"`
RotationEndTime string `json:"rotation_end_time"`
RestrictionType int `json:"restriction_type",omitempty`
Users []CreateUserLayer `json:"users"`
Restrictions []Restrictions `json:"restrictions"`
}

type CreateSchedule struct {
Expand All @@ -59,15 +61,15 @@ type CreateSchedule struct {
Team string `json:"team"`
Layers []CreateLayers `json:"layers"`
Overrides []Overrides `json:"overrides"`
Unique_Id string `json:"unique_id",omitempty`
Unique_Id string `json:"unique_id,omitempty"`
}
type Schedules struct {
Name string `json:"name"`
Description string `json:"description"`
Summary string `json:"summary"`
Time_zone string `json:"time_zone"`
Team string `json:"team"`
Unique_Id string `json:"unique_id",omitempty`
Unique_Id string `json:"unique_id,omitempty"`
Layers []Layers `json:"layers"`
Overrides []Overrides `json:"overrides"`
}
Expand Down
32 changes: 27 additions & 5 deletions client/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
type TagsService service

type Tag struct {
Unique_Id string `json:"unique_id,omitempty"`
Name string `json:"name"`
Color string `json:"color"`
Team int `json:"team,omitempty"`
Creation_Date string `json:"creation_date,omitempty"`
}

type ReadTag struct {
Unique_Id string `json:"unique_id,omitempty"`
Name string `json:"name"`
Color string `json:"color"`
Expand All @@ -29,35 +37,49 @@ func (c *TagsService) CreateTag(team string, tags *Tag) (*Tag, error) {
return &s, nil
}

func (c *TagsService) GetPriority(team string) ([]Tag, error) {
func (c *TagsService) UpdateTag(team string, tag_id string, tags *Tag) (*Tag, error) {
path := fmt.Sprintf("/api/account/teams/%s/tags/%s/", team, tag_id)
body, err := c.client.newRequestDo("PUT", path, tags)
if err != nil {
return nil, err
}
var s Tag
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *TagsService) GetTags(team string) ([]ReadTag, error) {
path := fmt.Sprintf("/api/account/teams/%s/tags/", team)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s []Tag
var s []ReadTag
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return s, nil
}

func (c *TagsService) GetPriorityById(team, id string) (*Tag, error) {
func (c *TagsService) GetTagId(team, id string) (*ReadTag, error) {
path := fmt.Sprintf("/api/account/teams/%s/tags/%s/", team, id)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s Tag
var s ReadTag
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *TagsService) DeletePriority(team, id string) error {
func (c *TagsService) DeleteTag(team, id string) error {
path := fmt.Sprintf("/api/account/teams/%s/tags/%s/", team, id)
_, err := c.client.newRequestDo("DELETE", path, nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type GetUsers struct {
}

func (c *UserService) GetUsers(email string) ([]GetUsers, error) {
path := "/api/account/users"
path := "/api/account/users/"

body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
Expand Down

0 comments on commit 8217b26

Please sign in to comment.