Documentation
¶
Overview ¶
Package ads asks NASA's Astrophysics Data System for papers, one search a call.
ADS wants a token with every request, and limits how many requests each endpoint answers in a day. When it asks us to stop, nothing more is asked: there are no retries here, and no loops. The token is sent in a header and is in no error, ever.
Index ¶
Constants ¶
const Session = "ADS_SESSION"
Session is the variable that names where the token is kept: celestial-data-secrets ads-login writes it, and celestial-data ads reads it.
const TokenFile = "ads-token"
TokenFile is the name of the token's file beside the secrets' config, where it is kept when Session names nowhere.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads the token Save kept in path. It refuses a link, a folder, anything but a plain file, a file anyone but its owner can read, one that holds no token, and one longer than a token.
It checks the file it opened, not the name, before it reads, and never waits on a pipe in a token's place. No error holds the token.
func NewGentle ¶ added in v0.0.4
NewGentle is the gentle that asks ADS, on a clock, with a source of randomness for the jitter a policy with tries would use. Wrap the Doer of a search in web.Through with it, and ADS's stops and paces are the web package's, so nothing here paces or reads a Retry-After.
func Policy ¶ added in v0.0.4
Policy is how ADS is asked: its own numbers, and the web package's default for any it does not name.
ADS limits requests by the day and publishes no pace, so the pace is one we picked. A request is never asked again after a failure with no word, since ADS counts each one against the day, and a search is a GET with no body, so no POST is repeated either.
func Save ¶
Save keeps a token in path, readable by its owner alone, over a token kept there before, so a search need not ask 1Password for it again.
It refuses an empty token, and a link, a folder or a file anyone else can read in the token's place. No error holds the token.
The token is written to a new file of its own beside path, then put in path's place, so a link put there later is replaced and not followed, and a write that fails leaves the token kept before as it was.
Types ¶
type Doer ¶
Doer is what a search is sent through. An *http.Client is one.
func Resetting ¶ added in v0.0.4
Resetting is a Doer for the web package's gentle to wrap. ADS says when the day's limit resets in X-RateLimit-Reset, as seconds since 1970, and the web package reads only Retry-After.
So a 429 that has a reset ahead and no Retry-After is given one, as an HTTP date at that reset, and the gentle leaves ADS alone until then. Any other answer, and any failure to send, is given as it came.
A reset that cannot be read, or is not ahead of the clock, is left as it is, and the gentle rests as long as it rests when ADS says no time. A date that has passed is never handed on: the gentle reads such a date as no wait, and ADS is to rest here.
type Found ¶
type Found struct {
// contains filtered or unexported fields
}
Found is what a search found.
func Search ¶
func Search(ctx context.Context, doer Doer, token, query string, most int, agent string) (*Found, error)
Search asks ADS one question and gives what it found: at most so many papers, the newest first. It sends one request and does not retry. It refuses a missing token or query, and fewer than one paper, before it sends anything.
The token goes in the Authorization header and in no error. The agent is how the request names itself.
A 401 is ADS refusing the token. A 429 is ADS asking us to stop: its error is a *Stopped, for errors.As. Any other status but 200 is an error that names it.
func (*Found) Count ¶
Count is how many papers ADS says match the query. It may be more than the papers it gave.
type Paper ¶
type Paper struct {
// contains filtered or unexported fields
}
Paper is a paper ADS found.
func (Paper) ArXiv ¶
ArXiv is the paper's arXiv id, as the papers verb fetches by, or none when ADS knows of no copy on arXiv.