Exemplo n.º 1
0
func New(cachefile string) *Client {
	c := cache.New(time.Minute*60*24*7, time.Minute*60)
	if _, err := os.Stat(cachefile); err == nil {
		err := c.LoadFile(cachefile)
		if err != nil {
			log.Fatal("Failed to load cache from file: " + cachefile)
		}
	}

	timeout := time.Duration(180 * time.Second)
	client := &http.Client{
		Timeout: timeout,
	}
	return &Client{false, "http://services.tvrage.com", "", c, cachefile, client}
}
Exemplo n.º 2
0
func New(host string, login string, protocol string, mak int, cachefile string) *Tivo {
	c := cache.New(time.Second*3600, time.Minute*60)
	if _, err := os.Stat(cachefile); err == nil {
		err := c.LoadFile(cachefile)
		if err != nil {
			log.Fatal("Failed to load cache from file: " + cachefile)
		}
	}

	// downloads get interrupted when the timeout is too short
	timeout := time.Duration(0 * time.Second)
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}

	jar, err := cookiejar.New(&cookiejar.Options{})
	if err != nil {
		log.Fatal(err.Error())
	}

	client := &http.Client{
		Timeout:   timeout,
		Transport: tr,
		Jar:       jar,
	}

	baseuri := fmt.Sprintf("%s://%s/TiVoConnect", protocol, host)
	return &Tivo{
		false,
		baseuri,
		mak,
		"TiVo DVR",
		login,
		host,
		protocol,
		false,
		c,
		cachefile,
		client,
	}
}
Exemplo n.º 3
0
func New(cachefile string) *Client {
	c := cache.New(time.Minute*60*24*7, time.Minute*60)
	if _, err := os.Stat(cachefile); err == nil {
		err := c.LoadFile(cachefile)
		if err != nil {
			log.Println("Failed to load cache from file: " + cachefile)
		}
	}

	timeout := time.Duration(180 * time.Second)
	client := &http.Client{
		Timeout: timeout,
	}

	return &Client{
		Cache:     c,
		CacheFile: cachefile,
		BaseURI:   "http://api.tvmaze.com",
		Client:    client,
	}
}
Exemplo n.º 4
0
func NewInMemoryStore(defaultExpiration time.Duration) *InMemoryStore {
	return &InMemoryStore{*cache.New(defaultExpiration, time.Minute)}
}