Skip to content

Commit

Permalink
get arrivals by airport
Browse files Browse the repository at this point in the history
Signed-off-by: Navid Yaghoobi <[email protected]>
  • Loading branch information
navidys committed Nov 8, 2023
1 parent 237046b commit 3810630
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/gopensky/arrivals.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func runArrivals(cmd *cobra.Command, args []string) {
return
}

flights, err := gopensky.GetArrivalsByAirport(conn, "ymml", cmdBeginTime, cmdEndTime)
flights, err := gopensky.GetArrivalsByAirport(conn, cmdAirport, cmdBeginTime, cmdEndTime)
if err != nil {
log.Error().Msgf("%v", err)

Expand Down
4 changes: 1 addition & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ func (h apiResponse) processWithError(unmarshalInto interface{}) error {

func handleError(statusCode int, data []byte) error {
errorModel := httpModelError{
// Because: http.StatusText(statusCode),
Message: string(data),
ResponseCode: statusCode,
Message: fmt.Sprintf("%s %s", http.StatusText(statusCode), data),
}

return errorModel
Expand Down
9 changes: 0 additions & 9 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,9 @@ func (c connectionError) Unwrap() error {
}

type httpModelError struct {
// human error message, formatted for a human to read
// example: human error message
Message string `json:"message"`
// HTTP response code
// min: 400
ResponseCode int `json:"response"`
}

func (e httpModelError) Error() string {
return e.Message
}

func (e httpModelError) Code() int {
return e.ResponseCode
}
4 changes: 4 additions & 0 deletions states.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func GetStates(ctx context.Context, time int64, icao24 []string,
return nil, fmt.Errorf("client: %w", err)
}

if time < 0 {
return nil, ErrInvalidUnixTime
}

requestParams := getStateRequestParams(time, icao24, bBox, extended)

response, err := conn.doGetRequest(ctx, nil, "/states/all", requestParams)
Expand Down

0 comments on commit 3810630

Please sign in to comment.