-
Notifications
You must be signed in to change notification settings - Fork 240
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 #194 from PagerDuty/prs-04feb2020
Community Contributions -- 05 Feb 2020
- Loading branch information
Showing
10 changed files
with
602 additions
and
22 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,85 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/google/go-querystring/query" | ||
) | ||
|
||
type Extension struct { | ||
APIObject | ||
Name string `json:"name"` | ||
EndpointURL string `json:"endpoint_url"` | ||
ExtensionObjects []APIObject `json:"extension_objects"` | ||
ExtensionSchema APIObject `json:"extension_schema"` | ||
Config interface{} `json:"config"` | ||
} | ||
|
||
type ListExtensionResponse struct { | ||
APIListObject | ||
Extensions []Extension `json:"extensions"` | ||
} | ||
|
||
type ListExtensionOptions struct { | ||
APIListObject | ||
ExtensionObjectID string `url:"extension_object_id,omitempty"` | ||
ExtensionSchemaID string `url:"extension_schema_id,omitempty"` | ||
Query string `url:"query,omitempty"` | ||
} | ||
|
||
func (c *Client) ListExtensions(o ListExtensionOptions) (*ListExtensionResponse, error) { | ||
v, err := query.Values(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := c.get("/extensions?" + v.Encode()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var result ListExtensionResponse | ||
|
||
return &result, c.decodeJSON(resp, &result) | ||
} | ||
|
||
func (c *Client) CreateExtension(e *Extension) (*Extension, error) { | ||
resp, err := c.post("/extensions", e, nil) | ||
return getExtensionFromResponse(c, resp, err) | ||
} | ||
|
||
func (c *Client) DeleteExtension(id string) error { | ||
_, err := c.delete("/extensions/" + id) | ||
return err | ||
} | ||
|
||
func (c *Client) GetExtension(id string) (*Extension, error) { | ||
resp, err := c.get("/extensions/" + id) | ||
return getExtensionFromResponse(c, resp, err) | ||
} | ||
|
||
func (c *Client) UpdateExtension(id string, e *Extension) (*Extension, error) { | ||
resp, err := c.put("/extensions/"+id, e, nil) | ||
return getExtensionFromResponse(c, resp, err) | ||
} | ||
|
||
func getExtensionFromResponse(c *Client, resp *http.Response, err error) (*Extension, error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var target map[string]Extension | ||
if dErr := c.decodeJSON(resp, &target); dErr != nil { | ||
return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) | ||
} | ||
|
||
rootNode := "extension" | ||
|
||
t, nodeOK := target[rootNode] | ||
if !nodeOK { | ||
return nil, fmt.Errorf("JSON response does not have %s field", rootNode) | ||
} | ||
|
||
return &t, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/google/go-querystring/query" | ||
) | ||
|
||
type ExtensionSchema struct { | ||
APIObject | ||
IconURL string `json:"icon_url"` | ||
LogoURL string `json:"logo_url"` | ||
Label string `json:"label"` | ||
Key string `json:"key"` | ||
Description string `json:"description"` | ||
GuideURL string `json:"guide_url"` | ||
SendTypes []string `json:"send_types"` | ||
URL string `json:"url"` | ||
} | ||
|
||
type ListExtensionSchemaResponse struct { | ||
APIListObject | ||
ExtensionSchemas []ExtensionSchema `json:"extension_schemas"` | ||
} | ||
|
||
type ListExtensionSchemaOptions struct { | ||
APIListObject | ||
Query string `url:"query,omitempty"` | ||
} | ||
|
||
func (c *Client) ListExtensionSchemas(o ListExtensionSchemaOptions) (*ListExtensionSchemaResponse, error) { | ||
v, err := query.Values(o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := c.get("/extension_schemas?" + v.Encode()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var result ListExtensionSchemaResponse | ||
|
||
return &result, c.decodeJSON(resp, &result) | ||
} | ||
|
||
func (c *Client) GetExtensionSchema(id string) (*ExtensionSchema, error) { | ||
resp, err := c.get("/extension_schemas/" + id) | ||
return getExtensionSchemaFromResponse(c, resp, err) | ||
} | ||
|
||
func getExtensionSchemaFromResponse(c *Client, resp *http.Response, err error) (*ExtensionSchema, error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var target map[string]ExtensionSchema | ||
if dErr := c.decodeJSON(resp, &target); dErr != nil { | ||
return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) | ||
} | ||
|
||
rootNode := "extension_schema" | ||
t, nodeOK := target[rootNode] | ||
if !nodeOK { | ||
return nil, fmt.Errorf("JSON response does not have %s field", rootNode) | ||
} | ||
|
||
return &t, nil | ||
} |
Oops, something went wrong.