/
stop.go
50 lines (40 loc) · 1.53 KB
/
stop.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
package sptrans
import (
"fmt"
)
const (
defaultStopPath = "Parada/Buscar"
defaultStopLinePath = "Parada/BuscarParadasPorLinha"
defaultStopCorridorPath = "Parada/BuscarParadasPorCorredor"
)
// StopService provide functions to request stops endpoints
type StopService service
// Stop structure, see documentation on http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo/Documentacao.aspx?1#docApi-paradas
type Stop struct {
Id int64 `json:"cp"`
Name string `json:"np"`
Address string `json:"ed"`
Latitude float64 `json:"py"`
Longitude float64 `json:"px"`
}
// Search performs a search of the bus stops based on the parameter informed (stop name or address)
func (r *StopService) Search(filter string) ([]*Stop, error) {
path := fmt.Sprintf("%s?termosBusca=%s", defaultStopPath, filter)
var stops []*Stop
_, err := r.client.Request("GET", path, nil, &stops)
return stops, err
}
// SearchByLine performs a search of the bus stops based on the line id
func (r *StopService) SearchByLine(lineId int) ([]*Stop, error) {
path := fmt.Sprintf("%s?codigoLinha=%d", defaultStopLinePath, lineId)
var stops []*Stop
_, err := r.client.Request("GET", path, nil, &stops)
return stops, err
}
// SearchByCorridor performs a search of the bus stops based on the corridor id
func (r *StopService) SearchByCorridor(corridorId int) ([]*Stop, error) {
path := fmt.Sprintf("%s?codigoCorredor=%d", defaultStopCorridorPath, corridorId)
var stops []*Stop
_, err := r.client.Request("GET", path, nil, &stops)
return stops, err
}