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:
parent
99207293a2
commit
10e1864cad
@ -32,8 +32,11 @@ type FlexibleAssetList struct {
|
|||||||
Links struct{ Links } `json:"links"`
|
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 {
|
func (itg *ITGAPI) GetFlexibleAssets(flexibleAssetTypeID int) error {
|
||||||
req := itg.NewRequest("/flexible_assets", "GET", nil)
|
req := itg.NewRequest("/flexible_assets", "GET", nil)
|
||||||
|
req.RawURLValues = fmt.Sprintf("filter[flexible_asset_type_id]=%d", flexibleAssetTypeID)
|
||||||
|
|
||||||
err := req.Do()
|
err := req.Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
return fmt.Errorf("request failed for %s: %s", req.RestAction, err)
|
||||||
|
@ -29,13 +29,14 @@ type ITGAPI struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
ITG *ITGAPI
|
ITG *ITGAPI
|
||||||
RestAction string
|
RestAction string
|
||||||
Method string //GET, POST, DELETE, etc
|
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
|
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
|
URLValues url.Values //Parameters sent to ITG for filtering by conditions that utilize strings
|
||||||
Page int
|
RawURLValues string //URL values must be a string. Raw URL values allow an int to be used, for instance in a filter
|
||||||
PageSize int
|
Page int
|
||||||
|
PageSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewITGAPI expects the API key to be passed to it
|
//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 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 {
|
if req.Page == 0 || req.PageSize == 0 {
|
||||||
itgurl.RawQuery = req.URLValues.Encode()
|
itgurl.RawQuery = fmt.Sprintf("%s%s", req.URLValues.Encode(), req.RawURLValues)
|
||||||
} else {
|
} 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{}
|
client := &http.Client{}
|
||||||
|
Loading…
Reference in New Issue
Block a user