-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from iLert/feature/support-hours-resource
Feature/support hours resource
- Loading branch information
Showing
6 changed files
with
312 additions
and
10 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
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
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
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/iLert/ilert-go/v3" | ||
) | ||
|
||
func main() { | ||
var apiToken = "your API token" | ||
client := ilert.NewClient(ilert.WithAPIToken(apiToken)) | ||
|
||
createSupportHourInput := &ilert.CreateSupportHourInput{ | ||
SupportHour: &ilert.SupportHour{ | ||
Name: "example", | ||
Timezone: "Europe/Berlin", | ||
SupportDays: &ilert.SupportDays{ | ||
MONDAY: &ilert.SupportDay{ | ||
Start: "09:00", | ||
End: "18:00", | ||
}, | ||
WEDNESDAY: &ilert.SupportDay{ | ||
Start: "09:00", | ||
End: "18:00", | ||
}, | ||
FRIDAY: &ilert.SupportDay{ | ||
Start: "09:00", | ||
End: "18:00", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
result, err := client.CreateSupportHour(createSupportHourInput) | ||
if err != nil { | ||
log.Println(result) | ||
log.Fatalln("ERROR:", err) | ||
} | ||
log.Printf("Support hour:\n\n %+v\n", result.SupportHour) | ||
} |
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,249 @@ | ||
package ilert | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
) | ||
|
||
// SupportHour definition https://api.ilert.com/api-docs/#tag/SupportHours | ||
type SupportHour struct { | ||
ID int64 `json:"id"` | ||
Name string `json:"name"` | ||
Teams []TeamShort `json:"teams,omitempty"` | ||
Timezone string `json:"timezone,omitempty"` | ||
SupportDays *SupportDays `json:"supportDays"` | ||
} | ||
|
||
// CreateSupportHourInput represents the input of a CreateSupportHour operation. | ||
type CreateSupportHourInput struct { | ||
_ struct{} | ||
SupportHour *SupportHour | ||
} | ||
|
||
// CreateSupportHourOutput represents the output of a CreateSupportHour operation. | ||
type CreateSupportHourOutput struct { | ||
_ struct{} | ||
SupportHour *SupportHour | ||
} | ||
|
||
// CreateSupportHour creates a new support hours resource. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours/post | ||
func (c *Client) CreateSupportHour(input *CreateSupportHourInput) (*CreateSupportHourOutput, error) { | ||
if input == nil { | ||
return nil, errors.New("input is required") | ||
} | ||
if input.SupportHour == nil { | ||
return nil, errors.New("support hour input is required") | ||
} | ||
resp, err := c.httpClient.R().SetBody(input.SupportHour).Post(apiRoutes.supportHours) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if apiErr := getGenericAPIError(resp, 201); apiErr != nil { | ||
return nil, apiErr | ||
} | ||
|
||
supportHour := &SupportHour{} | ||
err = json.Unmarshal(resp.Body(), supportHour) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &CreateSupportHourOutput{SupportHour: supportHour}, nil | ||
} | ||
|
||
// GetSupportHourInput represents the input of a GetSupportHour operation. | ||
type GetSupportHourInput struct { | ||
_ struct{} | ||
SupportHourID *int64 | ||
} | ||
|
||
// GetSupportHourOutput represents the output of a GetSupportHour operation. | ||
type GetSupportHourOutput struct { | ||
_ struct{} | ||
SupportHour *SupportHour | ||
} | ||
|
||
// GetSupportHour gets the support hours resource with specified id. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours~1{id}/get | ||
func (c *Client) GetSupportHour(input *GetSupportHourInput) (*GetSupportHourOutput, error) { | ||
if input == nil { | ||
return nil, errors.New("input is required") | ||
} | ||
if input.SupportHourID == nil { | ||
return nil, errors.New("support hour id is required") | ||
} | ||
|
||
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/%d", apiRoutes.supportHours, *input.SupportHourID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if apiErr := getGenericAPIError(resp, 200); apiErr != nil { | ||
return nil, apiErr | ||
} | ||
|
||
supportHour := &SupportHour{} | ||
err = json.Unmarshal(resp.Body(), supportHour) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &GetSupportHourOutput{SupportHour: supportHour}, nil | ||
} | ||
|
||
// GetSupportHoursInput represents the input of a GetSupportHours operation. | ||
type GetSupportHoursInput struct { | ||
_ struct{} | ||
|
||
// an integer specifying the starting point (beginning with 0) when paging through a list of entities | ||
StartIndex *int | ||
|
||
// the maximum number of results when paging through a list of entities. | ||
// Maximum: 100 | ||
MaxResults *int | ||
} | ||
|
||
// GetSupportHoursOutput represents the output of a GetSupportHours operation. | ||
type GetSupportHoursOutput struct { | ||
_ struct{} | ||
SupportHours []*SupportHour | ||
} | ||
|
||
// GetSupportHours lists existing support hours resources. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours/get | ||
func (c *Client) GetSupportHours(input *GetSupportHoursInput) (*GetSupportHoursOutput, error) { | ||
q := url.Values{} | ||
if input.StartIndex != nil { | ||
q.Add("start-index", strconv.Itoa(*input.StartIndex)) | ||
} | ||
if input.MaxResults != nil { | ||
q.Add("max-results", strconv.Itoa(*input.MaxResults)) | ||
} | ||
|
||
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s?%s", apiRoutes.supportHours, q.Encode())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if apiErr := getGenericAPIError(resp, 200); apiErr != nil { | ||
return nil, apiErr | ||
} | ||
|
||
supportHours := make([]*SupportHour, 0) | ||
err = json.Unmarshal(resp.Body(), &supportHours) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &GetSupportHoursOutput{SupportHours: supportHours}, nil | ||
} | ||
|
||
// SearchSupportHourInput represents the input of a SearchSupportHour operation. | ||
type SearchSupportHourInput struct { | ||
_ struct{} | ||
SupportHourName *string | ||
} | ||
|
||
// SearchSupportHourOutput represents the output of a SearchSupportHour operation. | ||
type SearchSupportHourOutput struct { | ||
_ struct{} | ||
SupportHour *SupportHour | ||
} | ||
|
||
// SearchSupportHour gets the support hours resource with specified name. | ||
func (c *Client) SearchSupportHour(input *SearchSupportHourInput) (*SearchSupportHourOutput, error) { | ||
if input == nil { | ||
return nil, errors.New("input is required") | ||
} | ||
if input.SupportHourName == nil { | ||
return nil, errors.New("support hour name is required") | ||
} | ||
|
||
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.supportHours, *input.SupportHourName)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if apiErr := getGenericAPIError(resp, 200); apiErr != nil { | ||
return nil, apiErr | ||
} | ||
|
||
supportHour := &SupportHour{} | ||
err = json.Unmarshal(resp.Body(), supportHour) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &SearchSupportHourOutput{SupportHour: supportHour}, nil | ||
} | ||
|
||
// UpdateSupportHourInput represents the input of a UpdateSupportHour operation. | ||
type UpdateSupportHourInput struct { | ||
_ struct{} | ||
SupportHourID *int64 | ||
SupportHour *SupportHour | ||
} | ||
|
||
// UpdateSupportHourOutput represents the output of a UpdateSupportHour operation. | ||
type UpdateSupportHourOutput struct { | ||
_ struct{} | ||
SupportHour *SupportHour | ||
} | ||
|
||
// UpdateSupportHour updates an existing support hours resource. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours~1{id}/put | ||
func (c *Client) UpdateSupportHour(input *UpdateSupportHourInput) (*UpdateSupportHourOutput, error) { | ||
if input == nil { | ||
return nil, errors.New("input is required") | ||
} | ||
if input.SupportHour == nil { | ||
return nil, errors.New("support hour input is required") | ||
} | ||
if input.SupportHourID == nil { | ||
return nil, errors.New("support hour id is required") | ||
} | ||
|
||
resp, err := c.httpClient.R().SetBody(input.SupportHour).Put(fmt.Sprintf("%s/%d", apiRoutes.supportHours, *input.SupportHourID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if apiErr := getGenericAPIError(resp, 200); apiErr != nil { | ||
return nil, apiErr | ||
} | ||
|
||
supportHour := &SupportHour{} | ||
err = json.Unmarshal(resp.Body(), supportHour) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &UpdateSupportHourOutput{SupportHour: supportHour}, nil | ||
} | ||
|
||
// DeleteSupportHourInput represents the input of a DeleteSupportHour operation. | ||
type DeleteSupportHourInput struct { | ||
_ struct{} | ||
SupportHourID *int64 | ||
} | ||
|
||
// DeleteSupportHourOutput represents the output of a DeleteSupportHour operation. | ||
type DeleteSupportHourOutput struct { | ||
_ struct{} | ||
} | ||
|
||
// DeleteSupportHour deletes the specified support hours resource. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours~1{id}/delete | ||
func (c *Client) DeleteSupportHour(input *DeleteSupportHourInput) (*DeleteSupportHourOutput, error) { | ||
if input == nil { | ||
return nil, errors.New("input is required") | ||
} | ||
if input.SupportHourID == nil { | ||
return nil, errors.New("support hour id is required") | ||
} | ||
|
||
resp, err := c.httpClient.R().Delete(fmt.Sprintf("%s/%d", apiRoutes.supportHours, *input.SupportHourID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if apiErr := getGenericAPIError(resp, 204); apiErr != nil { | ||
return nil, apiErr | ||
} | ||
|
||
return &DeleteSupportHourOutput{}, 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