144 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			144 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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
 | |
| }
 |