Пример #1
0
func (ah *GoogleAddressHandler) AddressesAutocomplete(q string) t.AddressPackage {
	rows := []t.AddressF{}
	result := t.AddressPackage{Rows: &rows}
	suff := "/place/autocomplete/json"
	url := GOOGLE_API_URL + suff
	//	log.Printf(fmt.Sprintf("location= %v,%v", ah.orbit.Lat, ah.orbit.Lon))
	address_result := GoogleResultAddress{}
	params := map[string]string{
		"components": "country:ru",
		"language":   "ru",
		"location":   fmt.Sprintf("%v,%v", ah.orbit.Lat, ah.orbit.Lon),
		"radius":     fmt.Sprintf("%v", ah.orbit.Radius),
		"types":      "address",
		"input":      q,
		"key":        ah.key,
	}
	body, err := u.GET(url, &params)
	if err != nil {
		log.Printf("GOOGLE ERROR! Can not get addres from %v [%+v]\n because %v", url, params, err)
		return result
	}
	err = json.Unmarshal(*body, &address_result)
	if err != nil {
		log.Printf("GOOGLE ERROR! Google Adress Supplier unmarshal error [%+v]", string(*body))
		return result
	}

	result = address_result.ToFastAddress()
	return result
}
Пример #2
0
func (ah *GoogleAddressHandler) GetDetailPlace(place_id string) (*GoogleDetailPlaceResult, error) {
	from_info, err := u.GET(GOOGLE_API_URL+"/place/details/json", &map[string]string{
		"placeid":  place_id,
		"key":      ah.key,
		"language": "ru",
	})
	if err != nil || from_info == nil {
		log.Printf("ERROR! GetDetailPlace IN GET: %v", err)
		return nil, err
	}

	addr_details := GoogleDetailPlaceResult{}

	err = json.Unmarshal(*from_info, &addr_details)
	if err != nil {
		log.Printf("ERROR! GetDetailPlace IN UNMARSHALL: %v", err)
		return nil, err
	}
	if addr_details.Status != "OK" {
		log.Printf("ERROR! GetDetailPlace GOOGLE STATUS: %v", addr_details.Status)
		return nil, errors.New(addr_details.Status)

	}
	return &addr_details, nil
}
func get_streets(name string) []g.DictItem {
	res, err := utils.GET(address_str, &map[string]string{"q": name})
	if err != nil {
		log.Printf("Error at get streets", err)
		panic(err)
	}
	s_res := []g.DictItem{}
	err = json.Unmarshal(*res, &s_res)
	if err != nil {
		log.Printf(err.Error())
	}
	//	log.Printf("Result is %+v", s_res)
	return s_res
}
Пример #4
0
func Load(code string, url string) (*PostTrackingWrapper, error) {
	data, err := u.GET(url, &map[string]string{"code": code})
	if err != nil {
		log.Printf("RUPOST LOAD err %v at getting request %v?code=%v", err, url, code)
		return nil, err
	}
	psw := PostTrackingWrapper{}
	err = json.Unmarshal(*data, &psw)
	if err != nil {
		log.Printf("RUPOST LOAD err %v\n at unmarshal %q ", err, string(*data))
		return nil, err
	}
	return &psw, nil
}
func get_street(name, out_name string) s.InField {
	res, err := utils.GET(address_str, &map[string]string{"q": name})
	if err != nil {
		log.Printf("Error at get streets", err)
		panic(err)
	}
	s_res := []g.DictItem{}
	err = json.Unmarshal(*res, &s_res)
	if err != nil {
		log.Printf(err.Error())
	}
	log.Printf("Result is %+v", s_res)
	result := s.InField{Name: out_name, Type: "dict", Data: s.InFieldData{Value: s_res[0].Key, Text: s_res[0].Title}}
	return result
}
func TestTaxiInfinityFail(t *testing.T) {
	conf := c.ReadTestConfigInRecursive()
	db := d.NewMainDb(conf.Main.Database.ConnString, conf.Main.Database.Name)
	taxi_conf := conf.Taxis["fake"]

	t.Logf("taxi api configuration for %+v:\n%v", taxi_conf.Name, taxi_conf.Api)
	external := i.GetTestInfAPI(taxi_conf.Api)

	external_api := external.(taxi.TaxiInterface)
	external_address_supplier := external.(taxi.AddressSupplier)

	apiMixin := taxi.ExternalApiMixin{API: external_api}

	carsCache := taxi.NewCarsCache(external_api)
	notifier := n.NewNotifier(conf.Main.CallbackAddr, taxi_conf.Chat.Key, db)

	address_handler, address_supplier := GetAddressInstruments(conf, taxi_conf.Name, external_address_supplier)
	configStore := d.NewConfigurationStorage(conf.Main.ConfigDatabase)
	botContext := taxi.FormTaxiBotContext(&apiMixin, db, configStore, taxi_conf, address_handler, carsCache)
	controller := m.FormBotController(botContext, db)

	t.Logf("Was create bot context: %+v\n", botContext)
	http.HandleFunc(fmt.Sprintf("/taxi/%v", taxi_conf.Name), controller)

	go func() {
		taxiContext := taxi.TaxiContext{API: external_api, DataBase: db, Cars: carsCache, Notifier: notifier}
		t.Logf("Will start order watcher for [%v]", botContext.Name)
		taxi.TaxiOrderWatch(&taxiContext, botContext)
	}()

	http.HandleFunc(fmt.Sprintf("/taxi/%v/streets", taxi_conf.Name), func(w http.ResponseWriter, r *http.Request) {
		geo.StreetsSearchController(w, r, address_supplier)
	})

	go func() {
		server_address := fmt.Sprintf(":%v", conf.Main.Port)
		t.Logf("\nStart listen and serving at: %v\n", server_address)
		server := &http.Server{
			Addr: server_address,
		}
		server.ListenAndServe()
	}()

	u.After(external_api.IsConnected, func() {
		inf_api := external.(*i.InfinityAPI)
		for i, _ := range inf_api.ConnStrings {
			inf_api.ConnStrings[i] += "w"
		}
	})

	_, err := u.GET(taxi_conf.DictUrl, &map[string]string{"q": "лесос"})
	if err != nil {
		t.Error("Error at getting street %v", err)
	}

	out_res, err := tu.POST(fmt.Sprintf("http://localhost:%v/taxi/%v", conf.Main.Port, taxi_conf.Name), &structs.InPkg{
		Message: &structs.InMessage{
			ID: u.GenStringId(),
			Commands: &[]structs.InCommand{
				structs.InCommand{Action: "information", Title: "information"},
			},
		},
		From:     "test user",
		UserData: &structs.InUserData{Name: "TEST"},
	})

	if err != nil {
		t.Errorf("Error at unmarshal result info %v", err)
	}

	if out_res == nil {
		t.Error("Out info result is nil!")
	} else {
		if out_res.Message.Type != "chat" {
			t.Errorf("Out message type != chat, but == %v", out_res.Message.Type)
		}
		ch, _ := configStore.GetChatConfig(taxi_conf.Chat.CompanyId)

		if out_res.Message.Body != ch.Information {
			t.Errorf("Out message body != info in config, but == %v", out_res.Message.Body)
		}
	}

}