Esempio n. 1
0
func (h Hubbub) subscription(s content.Subscription, f content.Feed, subscribe bool) {
	var err error

	fdata := f.Data()
	u := callbackURL(h.config, h.pattern, fdata.Id)

	body := url.Values{}
	body.Set("hub.callback", u)
	if subscribe {
		h.logger.Infoln("Subscribing to hubbub for " + f.String() + " with url " + u)
		body.Set("hub.mode", "subscribe")
	} else {
		h.logger.Infoln("Unsubscribing to hubbub for " + f.String() + " with url " + u)
		body.Set("hub.mode", "unsubscribe")
	}
	body.Set("hub.topic", fdata.Link)

	buf := util.BufferPool.GetBuffer()
	defer util.BufferPool.Put(buf)

	buf.WriteString(body.Encode())
	req, _ := http.NewRequest("POST", s.Data().Link, buf)
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("From", h.config.Hubbub.From)

	resp, err := h.client.Do(req)

	if err != nil {
		err = SubscriptionError{error: err, Subscription: s}
	} else if resp.StatusCode != 202 {
		err = SubscriptionError{error: errors.New("Expected response status 202, got " + resp.Status), Subscription: s}
	}

	if err == nil {
		if subscribe {
			h.subscribe <- s
		} else {
			h.unsubscribe <- s
		}
	} else {
		fdata.SubscribeError = err.Error()
		h.logger.Printf("Error subscribing to hub feed '%s': %s\n", f, err)

		f.Data(fdata)
		f.Update()
		if f.HasErr() {
			h.logger.Printf("Error updating feed database record for '%s': %s\n", f, f.Err())
		}

		h.removeFeed <- f
	}
}
Esempio n. 2
0
func TestImplements(t *testing.T) {
	var article content.Article

	r := NewRepo(nil, nil)

	article = r.Article()
	article.Data()

	var userArticle content.UserArticle

	userArticle = r.UserArticle(nil)
	userArticle.Data()

	var scoredArticle content.ScoredArticle

	scoredArticle = r.ScoredArticle()
	scoredArticle.Data()

	var feed content.Feed

	feed = r.Feed()
	feed.Data()

	var userFeed content.UserFeed

	userFeed = r.UserFeed(nil)
	userFeed.Data()

	var taggedFeed content.TaggedFeed

	taggedFeed = r.TaggedFeed(nil)
	taggedFeed.Data()

	r.HasErr()

	var subscription content.Subscription

	subscription = r.Subscription()
	subscription.Data()

	var tag content.Tag

	tag = r.Tag(nil)
	tag.Value()

	var user content.User

	user = r.User()
	user.Data()
}