mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 15:16:05 -06:00
Open up RegisterVehicle result processing for timestamps on denials
This commit is contained in:
36
api.go
36
api.go
@@ -293,22 +293,27 @@ func RegisterVehicle(formParams map[string]string, propertyId uint, residentProf
|
||||
}
|
||||
htmlString := string(html)
|
||||
|
||||
// Success can be measured with the presence of either "Approved" or "Denied" (if neither, it's an error)
|
||||
if strings.Contains(htmlString, "Approved") {
|
||||
result := &RegistrationResult{success: true}
|
||||
result := &RegistrationResult{success: strings.Contains(htmlString, "Approved")}
|
||||
|
||||
// Sanity check that a proper result was returned
|
||||
if !result.success && !strings.Contains(htmlString, "Denied") {
|
||||
return nil, fmt.Errorf("unexpected response: %s", htmlString)
|
||||
}
|
||||
|
||||
// Parse the HTML response
|
||||
doc, err := goquery.NewDocumentFromReader(bytes.NewBufferString(htmlString))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse HTML of approved registration result partial: %w", err)
|
||||
}
|
||||
|
||||
// Success can be measured with the presence of either "Approved" or "Denied" (if neither, it's an error)
|
||||
if result.success {
|
||||
// Search for 'data-vehicle-id' with regex
|
||||
vehicleIdMatches := vehicleIdPattern.FindStringSubmatch(htmlString)
|
||||
if len(vehicleIdMatches) > 1 {
|
||||
result.vehicleId = vehicleIdMatches[1]
|
||||
}
|
||||
|
||||
// Find the confirmation code
|
||||
doc, err := goquery.NewDocumentFromReader(bytes.NewBufferString(htmlString))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse HTML of approved registration result partial: %w", err)
|
||||
}
|
||||
|
||||
// Look for a 'p' tag that contains the text 'Confirmation Code:'
|
||||
var sibling *goquery.Selection
|
||||
doc.Find("div.circle-inner > p").Each(func(i int, s *goquery.Selection) {
|
||||
@@ -324,6 +329,7 @@ func RegisterVehicle(formParams map[string]string, propertyId uint, residentProf
|
||||
if sibling != nil {
|
||||
result.confirmationCode = sibling.Next().Text()
|
||||
}
|
||||
}
|
||||
|
||||
// Find timestamp: look for a 'strong' tag that contains 'Registration Date/Time:' inside a p, inside a div.circle-inner
|
||||
var parent *goquery.Selection
|
||||
@@ -331,7 +337,8 @@ func RegisterVehicle(formParams map[string]string, propertyId uint, residentProf
|
||||
// If we've already found the element, stop searching
|
||||
if parent != nil {
|
||||
return
|
||||
} else if strings.Contains(s.Text(), "Registration Date/Time:") {
|
||||
} else if strings.Contains(s.Text(), "Date/Time:") {
|
||||
// Will start with 'Denied' or 'Registration'
|
||||
parent = s.Parent()
|
||||
}
|
||||
})
|
||||
@@ -357,15 +364,6 @@ func RegisterVehicle(formParams map[string]string, propertyId uint, residentProf
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Confirmed denial, cleanly return
|
||||
if strings.Contains(htmlString, "Denied") {
|
||||
// TODO: Find and parse timestamp
|
||||
return &RegistrationResult{success: false}, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("unexpected response")
|
||||
}
|
||||
|
||||
// RegisterEmailConfirmation sends a request to the server to send a confirmation email regarding a vehicle's registration.
|
||||
|
||||
Reference in New Issue
Block a user