Пример #1
0
func GetAllCustomers(timestamp string) {
	var url string
	var bcr []Customer
	var count = 0
	var sum = 0
	page := 1
	// set url
	url = api_url + fmt.Sprintf("customers?page=%d&limit=250", page)
	fmt.Println("Writing Pgae1.csv ...")
	// call http GET to BC api
	utils.HttpGet(url, http_header, &bcr)
	// write to csv
	count = WriteToCSV(bcr, page, timestamp)
	// update customer sum
	sum = count + sum
	fmt.Println(fmt.Sprintf("... Page1.csv has %d customers.", count))

	for len(bcr) == 250 {
		// more than one page
		page += 1
		// reset url
		url = api_url + fmt.Sprintf("customers?page=%d&limit=250", page)
		fmt.Println(fmt.Sprintf("Writing Pgae%d.csv ...", page))
		utils.HttpGet(url, http_header, &bcr)
		count = WriteToCSV(bcr, page, timestamp)
		fmt.Println(fmt.Sprintf("... Page%d.csv has %d customers.", page, count))
		sum = sum + count
	}
	fmt.Println("Total customers:", sum)
}
Пример #2
0
func ExportAddressFromBC(path string) []Address {
	var url string
	var address_book []Address
	page := 1
	customer_id_list := GetCustomerIDFromCSV(path)
	if customer_id_list != nil {
		for _, id := range customer_id_list {
			var addr []Address
			url = api_url + fmt.Sprintf("customers/%s/addresses?page=%d&limit=250", id, page)
			// call http GET to BC api
			utils.HttpGet(url, http_header, &addr)
			if addr != nil {
				address := addr[len(addr)-1]
				address.Phone = PhoneVerificationAndCleanUp(address.Phone)
				address_book = append(address_book, address)
			}
		}
	}
	return address_book
}