-
Notifications
You must be signed in to change notification settings - Fork 0
/
veveoclient.go
106 lines (88 loc) · 2 KB
/
veveoclient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"gopkg.in/readline.v1"
)
const (
xpid = "[email protected]"
custid = "passport"
rpr = "10"
ectJson = "5"
baseUrl = "http://roviapi.veveo.net/search"
)
var params map[string]string
func init() {
params = make(map[string]string)
params["XPID"] = xpid
params["custid"] = custid
params["RPR"] = rpr
params["ECT"] = ectJson
//map["W"] = ""
}
func prompt(name, historyFileName string) string {
prmpt := fmt.Sprintf("%v: ", name)
rl, err := readline.NewEx(&readline.Config{
Prompt: prmpt,
HistoryFile: "/tmp/" + historyFileName + ".tmp",
})
if err != nil {
panic(err)
}
defer rl.Close()
line, err := rl.Readline()
if err != nil { // io.EOF
return "quit"
}
return line
}
func searchTerm() (searchString string) {
fmt.Println("Enter search term (empty string to end):")
//fmt.Scanln(&searchString)
searchString = prompt("Search Term", "searchTerm")
return searchString
}
func getUrl(searchTerm string) string {
//url := fmt.Sprintf(baseUrl, xpid, custid, rpr, ectJson, searchTerm)
var Url *url.URL
Url, err := url.Parse(baseUrl)
if err != nil {
panic("Wrong base URL: " + baseUrl)
}
parameters := url.Values{}
for k, v := range params {
parameters.Add(k, v)
}
parameters.Add("W", searchTerm)
Url.RawQuery = parameters.Encode()
return Url.String()
}
func main() {
for {
searchterm := searchTerm()
if searchterm == "" {
break
}
url := getUrl(searchterm)
response, err := http.Get(url)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
fmt.Println("--------------------begin---------------------------")
fmt.Println("RQ:" + url)
fmt.Println("--------------------begin---------------------------")
fmt.Printf("%s\n", string(contents))
fmt.Println("---------------------end----------------------------")
}
}
}