-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcompat.go
More file actions
46 lines (41 loc) · 1.63 KB
/
Copy pathcompat.go
File metadata and controls
46 lines (41 loc) · 1.63 KB
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
// Convenience wrappers that accept an explicit API key for quick, one-off calls.
package nasa
import (
"context"
"fmt"
"time"
)
// APODGet retrieves the APOD for a specific date using the given API key.
// The date must be in "YYYY-MM-DD" format. This is a convenience wrapper;
// for repeated use, prefer [NewClient] to avoid creating a new client per call.
func APODGet(apiKey string, date string) (*APODImage, error) {
t, err := time.Parse(dateFormat, date)
if err != nil {
return nil, fmt.Errorf("nasa: invalid date %q: %w", date, err)
}
c := NewClient(WithAPIKey(apiKey))
return c.APOD.Get(context.Background(), t)
}
// APODTodayWithKey retrieves today's APOD using the given API key. This is a
// convenience wrapper; for repeated use, prefer [NewClient] to avoid creating
// a new client per call.
func APODTodayWithKey(apiKey string) (*APODImage, error) {
c := NewClient(WithAPIKey(apiKey))
return c.APOD.Today(context.Background())
}
// NEOFeedWithKey retrieves near-earth objects for a date range using the given
// API key. Dates must be in "YYYY-MM-DD" format. This is a convenience
// wrapper; for repeated use, prefer [NewClient] to avoid creating a new client
// per call.
func NEOFeedWithKey(apiKey string, startDate string, endDate string) (*NEOFeed, error) {
start, err := time.Parse(dateFormat, startDate)
if err != nil {
return nil, fmt.Errorf("nasa: invalid start date %q: %w", startDate, err)
}
end, err := time.Parse(dateFormat, endDate)
if err != nil {
return nil, fmt.Errorf("nasa: invalid end date %q: %w", endDate, err)
}
c := NewClient(WithAPIKey(apiKey))
return c.NEO.Feed(context.Background(), start, end)
}