예제 #1
0
func (a *Api) GetListingsWithValues(v url.Values) (*PropertyListingResults, error) {
	req, err := a.NewRequest(apiURL, apiMethod, PropertyListingOptions{})
	if err != nil {
		return nil, err
	}
	q := req.URL.Query()
	for key, values := range v {
		for _, value := range values {
			q.Add(key, value)
		}
	}
	req.URL.RawQuery = q.Encode()
	log.Printf("out request: %v", req.URL.String())
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var rawResult RawPropertyListingResults
	err = json.Unmarshal(body, &rawResult)
	if err != nil {
		return nil, err
	}
	var result PropertyListingResults
	err = recode.Recode(rawResult, &result)
	if err != nil {
		return nil, err
	}
	return &result, nil
}
예제 #2
0
func (a *Api) GetListings(opt *PropertyListingOptions) (*PropertyListingResults, error) {
	req, err := a.NewRequest(apiURL, apiMethod, opt)
	if err != nil {
		return nil, err
	}
	log.Print(req.URL.String())
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var rawResult RawPropertyListingResults
	err = json.Unmarshal(body, &rawResult)
	if err != nil {
		return nil, err
	}
	var result PropertyListingResults
	err = recode.Recode(rawResult, &result)
	if err != nil {
		return nil, err
	}
	return &result, nil
}