Skip to content

Commit

Permalink
range updates
Browse files Browse the repository at this point in the history
  • Loading branch information
techBeck03 committed Mar 4, 2021
1 parent 2132b73 commit b68bf98
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
39 changes: 33 additions & 6 deletions range.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import (
)

const (
rangeBasePath = "range"
rangeBasePath = "range"
rangeReturnFields = "network,network_view,start_addr,end_addr,disable,comment,extattrs"
)

// GetRangeByRef gets range by reference
func (c *Client) GetRangeByRef(ref string) (Range, error) {
func (c *Client) GetRangeByRef(ref string, queryParams map[string]string) (Range, error) {
var ret Range
queryParams := map[string]string{
"_return_fields": "network,network_view,start_addr,end_addr,disable,comment,extattrs",

if queryParams == nil {
queryParams = map[string]string{
"_return_fields": rangeReturnFields,
}
} else {
queryParams["_return_fields"] = rangeReturnFields
}

queryParamString := c.BuildQuery(queryParams)
request, err := c.CreateJSONRequest(http.MethodGet, fmt.Sprintf("%s?%s", ref, queryParamString), nil)
if err != nil {
Expand All @@ -29,10 +36,30 @@ func (c *Client) GetRangeByRef(ref string) (Range, error) {
return ret, nil
}

// GetRangeByQuery gets range by reference
func (c *Client) GetRangeByQuery(queryParams map[string]string) (Range, error) {
var ret Range

queryParams["_return_fields"] = rangeReturnFields

queryParamString := c.BuildQuery(queryParams)
request, err := c.CreateJSONRequest(http.MethodGet, fmt.Sprintf("%s?%s", rangeBasePath, queryParamString), nil)
if err != nil {
return ret, err
}

err = c.Call(request, &ret)
if err != nil {
return ret, err
}

return ret, nil
}

// CreateRange creates range
func (c *Client) CreateRange(rangeObject *Range) error {
queryParams := map[string]string{
"_return_fields": "network,network_view,start_addr,end_addr,disable,comment,extattrs",
"_return_fields": rangeReturnFields,
}
queryParamString := c.BuildQuery(queryParams)
request, err := c.CreateJSONRequest(http.MethodPost, fmt.Sprintf("%s?%s", rangeBasePath, queryParamString), rangeObject)
Expand All @@ -51,7 +78,7 @@ func (c *Client) CreateRange(rangeObject *Range) error {
func (c *Client) UpdateRange(ref string, rangeObject Range) (Range, error) {
var ret Range
queryParams := map[string]string{
"_return_fields": "network,network_view,start_addr,end_addr,disable,comment,extattrs",
"_return_fields": rangeReturnFields,
}
queryParamString := c.BuildQuery(queryParams)
request, err := c.CreateJSONRequest(http.MethodPut, fmt.Sprintf("%s?%s", ref, queryParamString), rangeObject)
Expand Down
2 changes: 1 addition & 1 deletion range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCreateRange(t *testing.T) {
}

func TestGetRange(t *testing.T) {
rangeObject, err := rangeClient.GetRangeByRef(testRange.Ref)
rangeObject, err := rangeClient.GetRangeByRef(testRange.Ref, nil)
if err != nil {
t.Errorf("Error retrieving range: %s", err)
}
Expand Down

0 comments on commit b68bf98

Please sign in to comment.