nasaapod

package
v0.11.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaImage = "image"
	MediaVideo = "video"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Opts

type Opts func(*Request)

func WithAPIKey

func WithAPIKey(apiKey string) Opts

WithAPIKey returns function for setting Request.APIKey.

func WithCount

func WithCount(count int) Opts

WithCount returns function for setting Request.Count.

func WithDate

func WithDate(date values.Date) Opts

WithDate returns function for setting Request.Date.

func WithEndDate

func WithEndDate(endDate values.Date) Opts

WithEndDate returns function for setting Request.EndDate.

func WithStartDate

func WithStartDate(startDate values.Date) Opts

WithStartDate returns function for setting Request.StartDate.

func WithThumbs

func WithThumbs(thumbs bool) Opts

WithThumbs returns function for setting Request.Thumbs.

type Request

type Request struct {
	Date      values.Date `json:"date,omitempty"`       // The date of the APOD image to retrieve
	StartDate values.Date `json:"start_date,omitempty"` // The start of a date range, when requesting date for a range of dates. Cannot be used with date.
	EndDate   values.Date `json:"end_date,omitempty"`   // The end of the date range, when used with start_date.
	Count     int         `json:"count,omitempty"`      // If this is specified then count randomly chosen images will be returned. Cannot be used with date or start_date and end_date.
	Thumbs    bool        `json:"thumbs,omitempty"`     // Return the URL of video thumbnail. If an APOD is not a video, this parameter is ignored.
	APIKey    string      `json:"api_key"`              // api.nasa.gov key for expanded usage
}

Request is for context of APOD API.

func New

func New(opts ...Opts) *Request

New returns new Request instance for APOD API.

func (*Request) Encode

func (req *Request) Encode() (string, error)

Encode returns JSON string.

func (*Request) Get

func (req *Request) Get(ctx context.Context) ([]*Response, error)

Get method gets APOD data from NASA API, and returns []*Response instance.

func (*Request) String

func (req *Request) String() string

Stringger method.

type Response

type Response struct {
	Copyright      string      `json:"copyright,omitempty"`
	Date           values.Date `json:"date,omitempty"`
	Explanation    string      `json:"explanation,omitempty"`
	HdUrl          string      `json:"hdurl,omitempty"`
	MediaType      string      `json:"media_type,omitempty"`
	ServiceVersion string      `json:"service_version,omitempty"`
	Title          string      `json:"title,omitempty"`
	Url            string      `json:"url,omitempty"`
	ThumbnailUrl   string      `json:"thumbnail_url,omitempty"`
}

Response is response data from NASA APOD API.

func (*Response) Encode

func (res *Response) Encode(w io.Writer) error

Encode method writes encoded response data to writer by JSON format.

func (*Response) ImageFile

func (res *Response) ImageFile(ctx context.Context, dir string) (string, error)

func (*Response) WebPage

func (res *Response) WebPage() string

WebPage method returns web page of APOD.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL