Merge pull request #11 from anschelsc/master

Use the new xmlx changes
This commit is contained in:
jimt 2013-03-19 12:56:04 -07:00
commit 07f688de02
1 changed files with 17 additions and 1 deletions

18
feed.go
View File

@ -29,6 +29,7 @@ import (
"errors" "errors"
"fmt" "fmt"
xmlx "github.com/jteeuwen/go-pkg-xmlx" xmlx "github.com/jteeuwen/go-pkg-xmlx"
"net/http"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -90,7 +91,22 @@ func (this *Feed) LastUpdate() int64 { return this.lastupdate }
// This allows us to specify a custom character encoding conversion // This allows us to specify a custom character encoding conversion
// routine when dealing with non-utf8 input. Supply 'nil' to use the // routine when dealing with non-utf8 input. Supply 'nil' to use the
// default from Go's xml package. // default from Go's xml package.
//
// This is equivalent to calling FetchClient with http.DefaultClient
func (this *Feed) Fetch(uri string, charset xmlx.CharsetFunc) (err error) { func (this *Feed) Fetch(uri string, charset xmlx.CharsetFunc) (err error) {
return this.FetchClient(uri, http.DefaultClient, charset)
}
// Fetch retrieves the feed's latest content if necessary.
//
// The charset parameter overrides the xml decoder's CharsetReader.
// This allows us to specify a custom character encoding conversion
// routine when dealing with non-utf8 input. Supply 'nil' to use the
// default from Go's xml package.
//
// The client parameter allows the use of arbitrary network connections, for
// example the Google App Engine "URL Fetch" service.
func (this *Feed) FetchClient(uri string, client *http.Client, charset xmlx.CharsetFunc) (err error) {
if !this.CanUpdate() { if !this.CanUpdate() {
return return
} }
@ -101,7 +117,7 @@ func (this *Feed) Fetch(uri string, charset xmlx.CharsetFunc) (err error) {
// function parse it (rss 0.91, rss 0.92, rss 2, atom etc). // function parse it (rss 0.91, rss 0.92, rss 2, atom etc).
doc := xmlx.New() doc := xmlx.New()
if err = doc.LoadUri(uri, charset); err != nil { if err = doc.LoadUriClient(uri, client, charset); err != nil {
return return
} }
this.Type, this.Version = this.GetVersionInfo(doc) this.Type, this.Version = this.GetVersionInfo(doc)