-
Notifications
You must be signed in to change notification settings - Fork 3
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 #6 from ashleygeorgeclarke/matrix-dimensions
added matrix dimension read, delete
- Loading branch information
Showing
3 changed files
with
96 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package pim | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type ( | ||
MatrixDimensions service | ||
MatrixDimension struct { | ||
DimensionID int64 `json:"dimension_id"` | ||
DimensionName map[string]string `json:"dimension_name,omitempty"` | ||
DimensionOrder int `json:"dimension_order"` | ||
Status string `json:"status"` | ||
AddedByChangedBy | ||
} | ||
) | ||
|
||
func (s *MatrixDimensions) Read(ctx context.Context, opts *ListOptions) (*[]MatrixDimension, *http.Response, error) { | ||
urlStr := "matrix/dimension" | ||
u, err := addOptions(urlStr, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest(http.MethodGet, u.String(), nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
dataResp := new([]MatrixDimension) | ||
resp, err := s.client.Do(ctx, req, dataResp) | ||
return dataResp, resp, err | ||
} | ||
|
||
func (s *MatrixDimensions) Delete(ctx context.Context, dimensionID int) (*IDResponse, *http.Response, error) { | ||
u := fmt.Sprintf("matrix/dimension/%d", dimensionID) | ||
|
||
req, err := s.client.NewRequest(http.MethodDelete, u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
id := new(IDResponse) | ||
resp, err := s.client.Do(ctx, req, id) | ||
return id, resp, err | ||
} |
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,41 @@ | ||
package pim | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMatrixDimension_Read(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/matrix/dimension", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, http.MethodGet) | ||
_, err := fmt.Fprint(w, ` | ||
[ | ||
{ | ||
"dimension_order":1 | ||
}, | ||
{ | ||
"dimension_order":2 | ||
} | ||
] | ||
`) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
opts := NewListOptions(nil, nil, nil, false) | ||
result, _, err := client.MatrixDimensions.Read(context.Background(), opts) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
assert.Equal(t, 2, len(*result)) | ||
res := *result | ||
assert.Equal(t, 1, res[0].DimensionOrder) | ||
assert.Equal(t, 2, res[1].DimensionOrder) | ||
} |