Split off efa_client module
This commit is contained in:
parent
dc4180320b
commit
892012bc1c
143
efa_client.go
Normal file
143
efa_client.go
Normal file
@ -0,0 +1,143 @@
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
import "net/url"
|
||||
import "strings"
|
||||
|
||||
type EFAClient interface {
|
||||
GetName() string
|
||||
BuildRequest(string) (*http.Request, error)
|
||||
}
|
||||
|
||||
var allEfaClients []EFAClient = []EFAClient{
|
||||
BwegtEFAClient{},
|
||||
VRNEFAClient{},
|
||||
KVVEFAClient{},
|
||||
VAGEFAClient{},
|
||||
}
|
||||
|
||||
type VRNEFAClient struct {
|
||||
}
|
||||
|
||||
func (c VRNEFAClient) GetName() string {
|
||||
return "VRN"
|
||||
}
|
||||
|
||||
func (c VRNEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
// Create request object
|
||||
req, err := http.NewRequest("GET", "https://www.vrn.de/mngvrn/XML_DM_REQUEST", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Configure our request
|
||||
query := url.Values{}
|
||||
query.Set("coordOutputFormat", "EPSG:4326")
|
||||
query.Set("depType", "stopEvents")
|
||||
query.Set("includeCompleteStopSeq", "0")
|
||||
query.Set("limit", "10")
|
||||
query.Set("locationServerActive", "0")
|
||||
query.Set("mode", "direct")
|
||||
query.Set("name_dm", stopId)
|
||||
query.Set("outputFormat", "json")
|
||||
query.Set("type_dm", "stop")
|
||||
query.Set("useOnlyStops", "1")
|
||||
query.Set("useRealtime", "1")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type KVVEFAClient struct {
|
||||
}
|
||||
|
||||
func (c KVVEFAClient) GetName() string {
|
||||
return "KVV"
|
||||
}
|
||||
|
||||
func (c KVVEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
form := url.Values{}
|
||||
form.Set("action", "XSLT_DM_REQUEST")
|
||||
form.Set("name_dm", stopId)
|
||||
form.Set("type_dm", "stop")
|
||||
form.Set("useRealtime", "1")
|
||||
form.Set("limit", "10")
|
||||
form.Set("mode", "direct")
|
||||
form.Set("useRealtime", "1")
|
||||
form.Set("outputFormat", "json")
|
||||
body := strings.NewReader(form.Encode())
|
||||
|
||||
req, err := http.NewRequest("POST", "https://www.kvv.de/tunnelEfaDirect.php", body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "coolio/1.0")
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type BwegtEFAClient struct {
|
||||
}
|
||||
|
||||
func (c BwegtEFAClient) GetName() string {
|
||||
return "bwegt"
|
||||
}
|
||||
|
||||
func (c BwegtEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
// Create request object
|
||||
req, err := http.NewRequest("GET", "https://www.bwegt.de/bwegt-efa/XML_DM_REQUEST", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Configure our request
|
||||
query := url.Values{}
|
||||
query.Set("coordOutputFormat", "EPSG:4326")
|
||||
query.Set("depType", "stopEvents")
|
||||
query.Set("includeCompleteStopSeq", "0")
|
||||
query.Set("limit", "10")
|
||||
query.Set("locationServerActive", "0")
|
||||
query.Set("mode", "direct")
|
||||
query.Set("name_dm", stopId)
|
||||
query.Set("outputFormat", "json")
|
||||
query.Set("type_dm", "stop")
|
||||
query.Set("useOnlyStops", "1")
|
||||
query.Set("useRealtime", "1")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type VAGEFAClient struct {
|
||||
}
|
||||
|
||||
func (c VAGEFAClient) GetName() string {
|
||||
return "VAG"
|
||||
}
|
||||
|
||||
func (c VAGEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
// Create request object
|
||||
req, err := http.NewRequest("GET", "https://efa.vagfr.de/vagfr3/XSLT_DM_REQUEST", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Configure our request
|
||||
query := url.Values{}
|
||||
query.Set("coordOutputFormat", "EPSG:4326")
|
||||
query.Set("depType", "stopEvents")
|
||||
query.Set("includeCompleteStopSeq", "0")
|
||||
query.Set("limit", "10")
|
||||
query.Set("locationServerActive", "0")
|
||||
query.Set("mode", "direct")
|
||||
query.Set("name_dm", stopId)
|
||||
query.Set("outputFormat", "json")
|
||||
query.Set("type_dm", "stop")
|
||||
query.Set("useOnlyStops", "1")
|
||||
query.Set("useRealtime", "1")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
return req, nil
|
||||
}
|
139
main.go
139
main.go
@ -6,7 +6,6 @@ import "errors"
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "net/http"
|
||||
import "net/url"
|
||||
import "os"
|
||||
import "slices"
|
||||
import "strings"
|
||||
@ -47,144 +46,6 @@ type DMDateTime struct {
|
||||
Minute string `json:"minute"`
|
||||
}
|
||||
|
||||
type EFAClient interface {
|
||||
GetName() string
|
||||
BuildRequest(string) (*http.Request, error)
|
||||
}
|
||||
|
||||
var allEfaClients []EFAClient = []EFAClient{
|
||||
BwegtEFAClient{},
|
||||
VRNEFAClient{},
|
||||
KVVEFAClient{},
|
||||
VAGEFAClient{},
|
||||
}
|
||||
|
||||
type VRNEFAClient struct {
|
||||
}
|
||||
|
||||
func (c VRNEFAClient) GetName() string {
|
||||
return "VRN"
|
||||
}
|
||||
|
||||
func (c VRNEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
// Create request object
|
||||
req, err := http.NewRequest("GET", "https://www.vrn.de/mngvrn/XML_DM_REQUEST", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Configure our request
|
||||
query := url.Values{}
|
||||
query.Set("coordOutputFormat", "EPSG:4326")
|
||||
query.Set("depType", "stopEvents")
|
||||
query.Set("includeCompleteStopSeq", "0")
|
||||
query.Set("limit", "10")
|
||||
query.Set("locationServerActive", "0")
|
||||
query.Set("mode", "direct")
|
||||
query.Set("name_dm", stopId)
|
||||
query.Set("outputFormat", "json")
|
||||
query.Set("type_dm", "stop")
|
||||
query.Set("useOnlyStops", "1")
|
||||
query.Set("useRealtime", "1")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type KVVEFAClient struct {
|
||||
}
|
||||
|
||||
func (c KVVEFAClient) GetName() string {
|
||||
return "KVV"
|
||||
}
|
||||
|
||||
func (c KVVEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
form := url.Values{}
|
||||
form.Set("action", "XSLT_DM_REQUEST")
|
||||
form.Set("name_dm", stopId)
|
||||
form.Set("type_dm", "stop")
|
||||
form.Set("useRealtime", "1")
|
||||
form.Set("limit", "10")
|
||||
form.Set("mode", "direct")
|
||||
form.Set("useRealtime", "1")
|
||||
form.Set("outputFormat", "json")
|
||||
body := strings.NewReader(form.Encode())
|
||||
|
||||
req, err := http.NewRequest("POST", "https://www.kvv.de/tunnelEfaDirect.php", body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "coolio/1.0")
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type BwegtEFAClient struct {
|
||||
}
|
||||
|
||||
func (c BwegtEFAClient) GetName() string {
|
||||
return "bwegt"
|
||||
}
|
||||
|
||||
func (c BwegtEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
// Create request object
|
||||
req, err := http.NewRequest("GET", "https://www.bwegt.de/bwegt-efa/XML_DM_REQUEST", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Configure our request
|
||||
query := url.Values{}
|
||||
query.Set("coordOutputFormat", "EPSG:4326")
|
||||
query.Set("depType", "stopEvents")
|
||||
query.Set("includeCompleteStopSeq", "0")
|
||||
query.Set("limit", "10")
|
||||
query.Set("locationServerActive", "0")
|
||||
query.Set("mode", "direct")
|
||||
query.Set("name_dm", stopId)
|
||||
query.Set("outputFormat", "json")
|
||||
query.Set("type_dm", "stop")
|
||||
query.Set("useOnlyStops", "1")
|
||||
query.Set("useRealtime", "1")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
type VAGEFAClient struct {
|
||||
}
|
||||
|
||||
func (c VAGEFAClient) GetName() string {
|
||||
return "VAG"
|
||||
}
|
||||
|
||||
func (c VAGEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||
// Create request object
|
||||
req, err := http.NewRequest("GET", "https://efa.vagfr.de/vagfr3/XSLT_DM_REQUEST", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Configure our request
|
||||
query := url.Values{}
|
||||
query.Set("coordOutputFormat", "EPSG:4326")
|
||||
query.Set("depType", "stopEvents")
|
||||
query.Set("includeCompleteStopSeq", "0")
|
||||
query.Set("limit", "10")
|
||||
query.Set("locationServerActive", "0")
|
||||
query.Set("mode", "direct")
|
||||
query.Set("name_dm", stopId)
|
||||
query.Set("outputFormat", "json")
|
||||
query.Set("type_dm", "stop")
|
||||
query.Set("useOnlyStops", "1")
|
||||
query.Set("useRealtime", "1")
|
||||
req.URL.RawQuery = query.Encode()
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func FetchDepartures(c EFAClient, stopId string) (DMResponse, error) {
|
||||
req, err := c.BuildRequest(stopId)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user