Documentation ¶
Index ¶
- Constants
- Variables
- func WithCount(count int) *optionCount
- func WithDate(date time.Time) *optionDate
- func WithDateRange(start, end time.Time) *optionDateRange
- func WithThumbs() *optionThumbs
- type Client
- func (c *Client) Execute(req *Request) ([]Metadata, error)
- func (c *Client) FetchHdImage(m *Metadata) (string, io.Reader, error)
- func (c *Client) FetchImage(m *Metadata) (string, io.Reader, error)
- func (c *Client) FetchThumbnailImage(m *Metadata) (string, io.Reader, error)
- func (c *Client) ForDate(date time.Time) (*Metadata, error)
- func (c *Client) Random(n int) ([]Metadata, error)
- func (c *Client) Today() (*Metadata, error)
- func (c *Client) WithHttpClient(hc *http.Client) *optionHttpClient
- type Metadata
- type Option
- type Request
Constants ¶
const (
DefaultApiUrl = "https://api.nasa.gov/planetary/apod"
)
Variables ¶
var ( ErrNotFound = errors.New("picture of the day not found") ErrUnexpectedExtras = errors.New("picture of the day returned multiple values when only a single was expected") )
Functions ¶
func WithCount ¶
func WithCount(count int) *optionCount
WithCount adds the count option to the request.
func WithDateRange ¶
WithDateRange sets an option on the request to retrieve data associated with the given date range.
func WithThumbs ¶
func WithThumbs() *optionThumbs
WithThumbs modifies the request to request the thumbnail URL to the response metadata. This has no effect unless the MediaType is "video" in the response.
Types ¶
type Client ¶
type Client struct { // BaseURL is the URL to use to reach the NASA APOD service. BaseUrl string // ApiKey is the API key to use when reaching NASA APOD. ApiKey string // contains filtered or unexported fields }
Client is a NASA Picture of the Day client with methods for pulling down metadata about images and the image data itself.
func New ¶
New returns a NASA Picture of the Day client you can use to pull down metadata about the pictures of the day or the images themselves.
The key is the API key from NASA's API Key page.
func (*Client) FetchHdImage ¶
FetchHdImage fetches the image from the URL in Metadata.HdUrl and return the content type from the HTTP response and an io.Reader containing the image data or an error.
func (*Client) FetchImage ¶
FetchImage fetches the image from the URL in Metadata.Url and returns the content type set on the HTTP response and an io.Reader containing the file or an error.
func (*Client) FetchThumbnailImage ¶
FetchThumbnailImage fetches the image from teh URL in Metadata.ThumbnailUrl and returns the content type returned in the HTTP response and an io.Reader containing the image data or an error.
func (*Client) ForDate ¶
ForDate fetches the metadata related to the picture of the day on another date.
func (*Client) WithHttpClient ¶
WithHttpClient modifies the NASA Picture of the Day client by setting a custom HTTP client. Otherwise, it will just use http.DefaultClient.
type Metadata ¶
type Metadata struct { // Copyright is the copyright information attached to the image. This is // unset if the image is in the public domain. Copyright string `json:"copyright,omitempty"` // Date is the date that this image is/was the picture of the day. Date time.Time `json:"date,omitempty"` // Explanation describes the image. Explanation string `json:"explanation,omitempty"` // HdUrl is the URL to fetch the high definition image. HdUrl string `json:"hdurl,omitempty"` // MediaType is the media type of the picture. This can be "image" or // "video". MediaType string `json:"media_type,omitempty"` // ServiceVersion is the version of the NASA APOD service (always "v1" as of // this writing). ServiceVersion string `json:"service_version,omitempty"` // Title is the title given to the image. Title string `json:"title,omitempty"` // Url is the URL to fetch the lower definition image. Url string `json:"url,omitempty"` // ThumbnailUrl is the URL to fetch the video thumbnail from (if requested and the MediaType is "video"). ThumbnailUrl string `json:"-"` }
Metadata represents the information about an individual NASA Picture of the Day.
type Option ¶
type Option interface { // Apply is used by the option to modify the request to send. Apply(*http.Request) // Dateish returns true if the option is date-related. Only one date-related // option is permitted. Dateish() bool }
Option describes the interface to modify the APOD request.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the base request for NASA Picture of the day.
func NewRequest ¶
NewRequest returns a request.