sourceforge

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sourceforge adds support for the SourceForge releases RSS feed.

Example
package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"reflect"

	"gopkg.in/jarcoal/httpmock.v1"

	"github.com/victorpopkov/go-appcast/provider/sourceforge"
	"github.com/victorpopkov/go-appcast/source"
)

func testdataPath(paths ...string) string {
	testdataPath := "./testdata/"

	pwd, err := os.Getwd()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	return filepath.Join(pwd, testdataPath, filepath.Join(paths...))
}

func testdata(paths ...string) []byte {
	content, err := ioutil.ReadFile(testdataPath(paths...))
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	return content
}

func main() {
	// mock the request
	content := testdata("unmarshal/example.xml")
	httpmock.ActivateNonDefault(source.DefaultClient.HTTPClient)
	httpmock.RegisterResponder("GET", "https://sourceforge.net/projects/wesnoth/rss", httpmock.NewBytesResponder(200, content))
	defer httpmock.DeactivateAndReset()

	// example
	src, err := source.NewRemote("https://sourceforge.net/projects/wesnoth/rss")
	if err != nil {
		panic(err)
	}

	a := sourceforge.New(src)

	err = a.LoadSource()
	if err != nil {
		panic(err)
	}

	p, errors := a.Unmarshal()
	if p == nil && len(errors) > 0 {
		panic(errors[0])
	}

	fmt.Print("Errors:\n\n")
	for _, err := range errors {
		fmt.Println(err)
	}

	fmt.Printf("%-10s %s\n", "\nType:", reflect.TypeOf(a.Source().Appcast()))
	fmt.Printf("%-9s %s\n", "Checksum:", a.Source().Checksum())
	fmt.Printf("%-9s %d total\n\n", "Releases:", a.Releases().Len())

	fmt.Print("Filtering:\n\n")
	fmt.Printf("%12s %d total\n", "Before:", a.Releases().Len())

	// apply some filters
	a.Releases().FilterByMediaType("application/x-bzip2")
	a.Releases().FilterByTitle("wesnoth-1.14", true)
	a.Releases().FilterByUrl("dmg")
	defer a.Releases().ResetFilters() // reset

	fmt.Printf("%12s %d total\n\n", "After:", a.Releases().Len())

	if a.Releases().Len() > 0 {
		r := a.Releases().First()
		fmt.Print("First release details:\n\n")
		fmt.Printf("%12s %s\n", "Version:", r.Version())
		fmt.Printf("%12s %v\n", "Pre-release:", r.IsPreRelease())
		fmt.Printf("%12s %s\n", "Title:", r.Title())
		fmt.Printf("%12s %v\n\n", "Published:", r.PublishedDateTime())

		d := r.Downloads()[0]
		fmt.Printf("%12s %d total\n\n", "Downloads:", len(r.Downloads()))
		fmt.Printf("%12s %s\n", "URL:", d.Url())
		fmt.Printf("%12s %s\n", "Type:", d.Filetype())
		fmt.Printf("%12s %d\n", "Length:", d.Length())
	}

}
Output:

Errors:

release #51 (no version)
release #71 (no version)
release #72 (no version)
release #73 (no version)
release #92 (no version)

Type:     *sourceforge.Appcast
Checksum: 880cf7f2f6aa0aa0d859f1fc06e4fbcbba3d4de15fa9736bf73c07accb93ce36
Releases: 95 total

Filtering:

     Before: 95 total
      After: 10 total

First release details:

    Version: 1.13.14
Pre-release: false
      Title: /wesnoth/wesnoth-1.13.14/Wesnoth_1.13.14.dmg
  Published: Sun, 15 Apr 2018 08:45:18 UTC

  Downloads: 1 total

        URL: https://sourceforge.net/projects/wesnoth/files/wesnoth/wesnoth-1.13.14/Wesnoth_1.13.14.dmg/download
       Type: application/x-bzip2; charset=binary
     Length: 439082409

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Appcast

type Appcast struct {
	appcaster.Appcast
}

Appcast represents the appcast itself.

func New

func New(src ...interface{}) *Appcast

New returns a new Appcast instance pointer. The source can be passed as a parameter.

func (*Appcast) Unmarshal

func (a *Appcast) Unmarshal() (appcaster.Appcaster, []error)

Unmarshal unmarshals the Appcast.source.content into the Appcast.releases.

It returns both: the supported provider-specific appcast implementing the Appcaster interface and an errors slice.

type Appcaster

type Appcaster interface {
	appcaster.Appcaster
}

Appcaster is the interface that wraps the Appcast methods.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL