nihreporter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package nihreporter is the library behind the nihreporter command line: the HTTP client, request shaping, and the typed data models for the NIH Reporter API.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load. Build your endpoint calls and JSON decoding on top of it.

Index

Constants

View Source
const Host = "reporter.nih.gov"

Host is the NIH Reporter site, used for Locate / URI resolution.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP *http.Client
	// contains filtered or unexported fields
}

Client talks to the NIH Reporter API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with the default config.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client using the given config.

func (*Client) GetProject

func (c *Client) GetProject(ctx context.Context, projectNum string) (*Project, error)

GetProject fetches a single project by project number.

func (*Client) SearchByOrg

func (c *Client) SearchByOrg(ctx context.Context, orgName string, limit, offset int) ([]*Project, int, error)

SearchByOrg searches grants by organization name.

func (*Client) SearchByPI

func (c *Client) SearchByPI(ctx context.Context, lastName string, limit, offset int) ([]*Project, int, error)

SearchByPI searches grants by PI last name.

func (*Client) SearchProjects

func (c *Client) SearchProjects(ctx context.Context, query string, limit, offset int) ([]*Project, int, error)

SearchProjects searches grants by text query.

type Config

type Config struct {
	BaseURL   string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
	UserAgent string
}

Config carries the tunable parameters for the NIH Reporter client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the NIH Reporter API.

type Domain

type Domain struct{}

Domain is the nihreporter driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id). Any non-empty string is treated as a project number.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Project

type Project struct {
	ID           int      `json:"id"            kit:"id"` // appl_id
	ProjectNum   string   `json:"project_num"`
	Title        string   `json:"title"`
	Abstract     string   `json:"abstract,omitempty"`
	FiscalYear   int      `json:"fiscal_year,omitempty"`
	AwardAmount  int64    `json:"award_amount,omitempty"`
	StartDate    string   `json:"start_date,omitempty"`
	EndDate      string   `json:"end_date,omitempty"`
	PINames      []string `json:"pi_names,omitempty"`
	OrgName      string   `json:"org_name,omitempty"`
	OrgState     string   `json:"org_state,omitempty"`
	ActivityCode string   `json:"activity_code,omitempty"`
	Agency       string   `json:"agency,omitempty"`
	Terms        []string `json:"terms,omitempty"`
}

Project is an NIH research grant record.

Jump to

Keyboard shortcuts

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