mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 07:15:57 -06:00
Simplify onRequest/onResponse/client.Do calls with doRequest
This commit is contained in:
20
api.go
20
api.go
@@ -50,18 +50,14 @@ func onResponse(res *http.Response) {
|
||||
func reload() {
|
||||
// Ring the doorbell
|
||||
req := BuildRequest("GET", "/", nil)
|
||||
onRequest(req)
|
||||
res, _ := client.Do(req)
|
||||
onResponse(res)
|
||||
doRequest(req)
|
||||
|
||||
// Ring the second doorbell (seems to be a way of validating whether a client is a 'browser' or not)
|
||||
req = BuildRequest("GET", "/index.php", map[string]string{
|
||||
"width": "1920",
|
||||
"height": "1080",
|
||||
})
|
||||
onRequest(req)
|
||||
res, _ = client.Do(req)
|
||||
onResponse(res)
|
||||
doRequest(req)
|
||||
|
||||
// Verify that a PHPSESSID cookie is present
|
||||
site_cookies := client.Jar.Cookies(req.URL)
|
||||
@@ -111,9 +107,7 @@ func GetLocations() []Location {
|
||||
req := BuildRequestWithBody("POST", "/register-get-properties-from-name", nil, bytes.NewBufferString(body))
|
||||
SetTypicalHeaders(req, nil, nil, true)
|
||||
|
||||
onRequest(req)
|
||||
res, err := client.Do(req)
|
||||
onResponse(res)
|
||||
res, err := doRequest(req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -164,10 +158,8 @@ func GetForm(id uint) GetFormResult {
|
||||
body := fmt.Sprintf("propertyIdSelected=%d&propertySource=parking-snap", id)
|
||||
req := BuildRequestWithBody("POST", "/register-get-vehicle-form", nil, bytes.NewBufferString(body))
|
||||
SetTypicalHeaders(req, nil, nil, false)
|
||||
onRequest(req)
|
||||
|
||||
res, _ := client.Do(req)
|
||||
onResponse(res)
|
||||
res, _ := doRequest(req)
|
||||
|
||||
html, _ := io.ReadAll(res.Body)
|
||||
htmlString := string(html)
|
||||
@@ -204,10 +196,8 @@ func GetVipForm(id uint, guestCode string) GetFormResult {
|
||||
body := fmt.Sprintf("propertyIdSelected=%d&propertySource=parking-snap&guestCode=%s", id, guestCode)
|
||||
req := BuildRequestWithBody("POST", "/register-get-vehicle-form", nil, bytes.NewBufferString(body))
|
||||
SetTypicalHeaders(req, nil, nil, false)
|
||||
onRequest(req)
|
||||
|
||||
res, _ := client.Do(req)
|
||||
onResponse(res)
|
||||
res, _ := doRequest(req)
|
||||
|
||||
html, _ := io.ReadAll(res.Body)
|
||||
htmlString := string(html)
|
||||
|
||||
@@ -80,6 +80,14 @@ func SetTypicalHeaders(req *http.Request, contentType *string, referrer *string,
|
||||
}
|
||||
}
|
||||
|
||||
// doRequest performs the given request and calls onRequest and onResponse.
|
||||
func doRequest(request *http.Request) (*http.Response, error) {
|
||||
onRequest(request)
|
||||
response, error := client.Do(request)
|
||||
onResponse(response)
|
||||
return response, error
|
||||
}
|
||||
|
||||
// GetRandomItems returns N random items from the given array.
|
||||
// The seed_value is used to control the output.
|
||||
// If the array is not a slice, an error is returned.
|
||||
|
||||
4
scan.go
4
scan.go
@@ -21,10 +21,8 @@ func Scan() {
|
||||
body := fmt.Sprintf("propertyIdSelected=%d&propertySource=parking-snap", location.id)
|
||||
req := BuildRequestWithBody("POST", "/register-get-vehicle-form", nil, bytes.NewBufferString(body))
|
||||
SetTypicalHeaders(req, nil, nil, false)
|
||||
onRequest(req)
|
||||
res, _ := doRequest(req)
|
||||
|
||||
res, _ := client.Do(req)
|
||||
onResponse(res)
|
||||
html, _ := io.ReadAll(res.Body)
|
||||
|
||||
html_path := filepath.Join("./forms", fmt.Sprintf("%d.html", location.id))
|
||||
|
||||
Reference in New Issue
Block a user