wmata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LineCodeAll    = ""
	LineCodeBlue   = "BL"
	LineCodeGreen  = "GR"
	LineCodeOrange = "OR"
	LineCodeRed    = "RD"
	LineCodeSilver = "SV"
	LineCodeYellow = "YL"

	APIKeyHeader = "api_key"
)

Variables

This section is empty.

Functions

func CloseResponseBody

func CloseResponseBody(response *http.Response)

CloseResponseBody is a helper function to close response body and log error

Types

type Client

type Client struct {
	APIKey     string
	HTTPClient HTTPClient
}

Client is a wmata specific http client that includes authentication information

func NewWMATAClient

func NewWMATAClient(apiKey string, httpClient http.Client) *Client

NewWMATAClient returns a new client to make requests to the WMATA API

func NewWMATADefaultClient

func NewWMATADefaultClient(apiKey string) *Client

NewWMATADefaultClient returns a new client to make requests to the WMATA API This creates a default http.Client with a 30 second timeout

func (*Client) BuildAndSendGetRequest

func (client *Client) BuildAndSendGetRequest(responseFormat ResponseType, url string, queryParams map[string]string, apiResponse interface{}) error

BuildAndSendGetRequest constructs and sends a generic HTTP GET request against the WMATA API

func (*Client) ValidateAPIKey

func (client *Client) ValidateAPIKey() (int, error)

ValidateAPIKey sends a validation request to the WMATA API to verify the given API works and that WMATA is available. Returns 200, nil if able to connect and receive a success (200) response from WMATA - otherwise returns status code and error message

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type ResponseType

type ResponseType int
const (
	JSON ResponseType = iota
	XML
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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