Example #1
0
func Test_NewRequestLanguageInterpolation(t *testing.T) {
	r, err := wiki.NewRequest("example.com", "Test", "sv")
	if err != nil {
		t.Errorf("Could not create request: %s\n", err)
	}

	expected := "example.com?action=query&converttitles=&exintro=&explaintext=" +
		"&format=json&inprop=url&prop=extracts%7Cinfo&redirects=&titles=Test"
	if r.String() != expected {
		t.Errorf("Expected %s got %s", expected, r.String())
	}

	r, err = wiki.NewRequest("%s.example.com", "Test", "sv")
	if err != nil {
		t.Errorf("Could not create request: %s\n", err)
	}

	expected = "sv.example.com?action=query&converttitles=&exintro=" +
		"&explaintext=&format=json&inprop=url&prop=extracts%7Cinfo" +
		"&redirects=&titles=Test"
	if r.String() != expected {
		t.Errorf("Expected %s got %s", expected, r.String())
	}
}
Example #2
0
File: main.go Project: underyx/wiki
func getPage(url, language *string) *wiki.Page {
	query := strings.Title(strings.Join(flag.Args(), " "))
	req, err := wiki.NewRequest(*url, query, *language)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not create request %s\n", err)
		os.Exit(RequestErrorExitStatus)
	}

	resp, err := req.Execute()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not execute request %s\n", err)
		os.Exit(RequestErrorExitStatus)
	}

	page, err := resp.Page()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not parse data %s\n", err)
		os.Exit(ParsingErrorExitStatus)
	}

	return page
}