Add support for RawURLValues to be defined in a request.

Noticed that each flexible asset type should have getters/setters
This commit is contained in:
Steven Polley 2018-07-22 20:06:08 -06:00
parent 99207293a2
commit 10e1864cad
2 changed files with 13 additions and 9 deletions

View File

@ -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)

View File

@ -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{}