From 10e1864cad90f77ca0adc4aff61ca1f12296f54d Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Sun, 22 Jul 2018 20:06:08 -0600 Subject: [PATCH] Add support for RawURLValues to be defined in a request. Noticed that each flexible asset type should have getters/setters --- itglue/flexible-assets.go | 3 +++ itglue/itglue.go | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/itglue/flexible-assets.go b/itglue/flexible-assets.go index 35e2a49..9fd08b8 100644 --- a/itglue/flexible-assets.go +++ b/itglue/flexible-assets.go @@ -32,8 +32,11 @@ type FlexibleAssetList struct { Links struct{ Links } `json:"links"` } +//Rather than a "GetFlexibleAssets", we need to implement getters for each flexible asset type. This should probably be automated and go code should be generated by some external program. func (itg *ITGAPI) GetFlexibleAssets(flexibleAssetTypeID int) error { req := itg.NewRequest("/flexible_assets", "GET", nil) + req.RawURLValues = fmt.Sprintf("filter[flexible_asset_type_id]=%d", flexibleAssetTypeID) + err := req.Do() if err != nil { return fmt.Errorf("request failed for %s: %s", req.RestAction, err) diff --git a/itglue/itglue.go b/itglue/itglue.go index 7019686..f75b42d 100644 --- a/itglue/itglue.go +++ b/itglue/itglue.go @@ -29,13 +29,14 @@ type ITGAPI struct { } type Request struct { - ITG *ITGAPI - RestAction string - Method string //GET, POST, DELETE, etc - Body []byte //In a GET request, this is an instance of the struct that the expected json data is to be unmarshaled into - URLValues url.Values //Parameters sent to ITG for filtering by conditions that utilize strings - Page int - PageSize int + ITG *ITGAPI + RestAction string + Method string //GET, POST, DELETE, etc + Body []byte //In a GET request, this is an instance of the struct that the expected json data is to be unmarshaled into + URLValues url.Values //Parameters sent to ITG for filtering by conditions that utilize strings + RawURLValues string //URL values must be a string. Raw URL values allow an int to be used, for instance in a filter + Page int + PageSize int } //NewITGAPI expects the API key to be passed to it @@ -60,9 +61,9 @@ func (req *Request) Do() error { //If pagination parameters are not being specified, then don't include them in the URL - not all endpoints will accept page and pagesize, they will 400 - bad request if req.Page == 0 || req.PageSize == 0 { - itgurl.RawQuery = req.URLValues.Encode() + itgurl.RawQuery = fmt.Sprintf("%s%s", req.URLValues.Encode(), req.RawURLValues) } else { - itgurl.RawQuery = fmt.Sprintf("%s&page[number]=%d&page[size]=%d", req.URLValues.Encode(), req.Page, req.PageSize) + itgurl.RawQuery = fmt.Sprintf("%s%s&page[number]=%d&page[size]=%d", req.URLValues.Encode(), req.RawURLValues, req.Page, req.PageSize) } client := &http.Client{}