Esempio n. 1
0
func TestClient(t *testing.T) {
	config := search.Config{}
	_, err := search.NewClient(config)
	if err != nil {
		t.Fatalf("unexpected error.  expected %v, actual %v", nil, err)
	}
}
Esempio n. 2
0
File: visit.go Progetto: coveo/uabot
// NewVisit     Creates a new visit to the search page
// _searchtoken The token used to be able to search
// _uatoken     The token used to send usage analytics events
// _useragent   The user agent the analytics events will see
func NewVisit(_searchtoken string, _uatoken string, _useragent string, language string, c *Config) (*Visit, error) {

	InitLogger(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)

	v := Visit{}
	v.Config = c

	v.WaitBetweenActions = !c.DontWaitBetweenVisits
	v.Anonymous = false
	if c.AllowAnonymous {
		var threshold float64
		if c.AnonymousThreshold > 0 {
			threshold = c.AnonymousThreshold
		} else {
			threshold = DEFAULTANONYMOUSTHRESHOLD
		}
		if rand.Float64() <= threshold {
			v.Anonymous = true
			Info.Printf("Anonymous visit")
		}
	}
	if !v.Anonymous {
		v.Username = buildUserEmail(c)
		Info.Printf("New visit from %s", v.Username)
	}
	//Info.Printf("On device %s", _useragent)
	if language != "" {
		v.Language = language
	} else {
		if len(v.Config.Languages) > 0 {
			v.Language = v.Config.Languages[rand.Intn(len(v.Config.Languages))]
		} else {
			v.Language = "en"
		}
	}
	Info.Printf("Language of visit : %s", v.Language)

	// Create the http searchClient
	searchConfig := search.Config{Token: _searchtoken, UserAgent: _useragent, Endpoint: c.SearchEndpoint}
	searchClient, err := search.NewClient(searchConfig)
	if err != nil {
		return nil, err
	}
	v.SearchClient = searchClient

	// Create the http UAClient
	ip := c.RandomIPs[rand.Intn(len(c.RandomIPs))]
	v.IP = ip
	uaConfig := ua.Config{Token: _uatoken, UserAgent: _useragent, IP: ip, Endpoint: c.AnalyticsEndpoint}
	uaClient, err := ua.NewClient(uaConfig)
	if err != nil {
		return nil, err
	}
	v.UAClient = uaClient

	return &v, nil
}