surflinef

package module
v1.0.2-0...-957d7ec Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

README

SurflineF

Build Status

An API client for fetching Forecasts from the Surfline API.

Check out the v2 folder for the API client for the Surfline API v2.

Installation

Simply run go get github.com/mhelmetag/surflinef and start using it in your own apps!

Note: I believe any go version over 1.11 will get upset with how I do my weird JSON unmarshalling (because of Surfline's weird API data types). I would recommend using v2 anyways...

Usage

The full example for fetching a Forecast (and other info) can be found in examples/main.go and can be run with go run examples/main.go.

Surfline API URL

http://api.surfline.com/v1/forecasts

Known Query Params

  • resources (string) - Possible values: [surf, analysis, wind, weather, tide, sort] (optional resources for forecast)
  • days (integer) - Greater than 1 (unsure of upper limit; confirmed to go above 10 but data usually becomes unknown/blank after that)
  • getAllSpots (boolean) - true will get all spot forecasts in the subregion (meaning an array of forecasts)
  • aggregate (boolean) - true enables aggregate fields for the Surf resource
  • units (string) - Possible values: [e, m] (e is feet and m is meters)
  • fullAnalysis (boolean) - true adds fields like brief_outlook, best_bet, extended_outlook and others to the larger Analysis JSON object
  • showOptimal (boolean) - Not sure what this does yet
  • interpolate (boolean) - Not sure what this does yet

Example API Calls

Found in the network tab when browsing around the Surfline site:

http://api.surfline.com/v1/forecasts/2141?&callback=jQuery18001517130109550182_1474259459851&resources=resources%3Dwind%2Csurf%2Canalysis%2Cweather%2Ctide%2Csort&days=17&aggregate=true&units=e&_=1474259492858

http://api.surfline.com/v1/forecasts/2141?resources=analysis&units=e&days=1&fullAnalysis=true

http://api.surfline.com/v1/forecasts/2141?resources=surf,analysis&days=1&getAllSpots=true&units=e&interpolate=false&showOptimal=false

http://api.surfline.com/v1/forecasts/4991?resources=surf&days=1&getAllSpots=false&units=e&interpolate=true&showOptimal=false

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analysis

type Analysis struct {
	GeneralCondition []string
	GeneralText      []string
	SurfMax          []string
	SurfMin          []string
	SurfRange        []string
	SurfText         []string
	Units            string
}

Analysis is a collection of high-level surf info.

type Client

type Client struct {
	BaseURL *url.URL
	// contains filtered or unexported fields
}

Client is the SurflineF HTTP Client.

func DefaultClient

func DefaultClient() (*Client, error)

DefaultClient returns a default configured SurflineF Client.

func (*Client) GetForecast

func (c *Client) GetForecast(srID string, query string) (Forecast, error)

GetForecast grabs a Forecast from surfline with the provided Sub Region ID and Query string.

type DataPoint

type DataPoint struct {
	Localtime string  `json:"Localtime"`
	Unixtime  int     `json:"time"`
	Type      string  `json:"type"`
	Height    float32 `json:"height"`
}

DataPoint is a single tide prediction.

type Forecast

type Forecast struct {
	Analysis
	Tide
	Surf
	Weather
	Wind
}

Forecast is the root JSON struct for forecast data.

func (*Forecast) UnmarshalJSON

func (f *Forecast) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom unmarshaller for Forecast.

type Query

type Query struct {
	Resources    []string `url:"resources,comma,omitempty"`
	Days         int      `url:"days,omitempty"`
	GetAllSpots  bool     `url:"getAllSpots,omitempty"`
	Aggregate    bool     `url:"aggregate,omitempty"`
	Units        string   `url:"units,omitempty"`
	FullAnalysis bool     `url:"fullAnalysis,omitempty"`
	ShowOptimal  bool     `url:"showOptimal,omitempty"`
	Interpolate  bool     `url:"interpolate,omitempty"`
}

Query is used to build Forecast query params. False, nil or empty values are ignored.

func (*Query) QueryString

func (q *Query) QueryString() (string, error)

QueryString builds a query string from a Query.

type Surf

type Surf struct {
	SwellDirection1    [][]int     `json:"swell_direction1"`
	SwellDirection2    [][]int     `json:"swell_direction2"`
	SwellDirection3    [][]int     `json:"swell_direction3"`
	SwellPeriod1       [][]float32 `json:"swell_period1"`
	SwellPeriod2       [][]float32 `json:"swell_period2"`
	SwellPeriod3       [][]float32 `json:"swell_period3"`
	SwellHeight1       [][]float32 `json:"swell_height1"`
	SwellHeight2       [][]float32 `json:"swell_height2"`
	SwellHeight3       [][]float32 `json:"swell_height3"`
	SurfMin            [][]float32 `json:"surf_min"`
	SurfMax            [][]float32 `json:"surf_max"`
	PeriodSchedule     [][]string  `json:"periodSchedule"`
	DateStamp          [][]string  `json:"dateStamp"`
	Units              string      `json:"units"`
	AggregatePeriod    [][]float32 `json:"agg_period1"`
	AggregateHeight    [][]float32 `json:"agg_height1"`
	AggregateSpread    [][]int     `json:"agg_spread1"`
	AggregateDirection [][]int     `json:"agg_direction1"`
	AggregateLocation  [][]int     `json:"agg_location"`
	AggregateSurfMin   [][]float32 `json:"agg_surf_min"`
	AggregateSurfMax   [][]float32 `json:"agg_surf_max"`
}

Surf is a collection of detailed swell info. Agregate data is only available when the aggregate query param is true for the Forecast.

type Tide

type Tide struct {
	DataPoints []DataPoint `json:"dataPoints"`
}

Tide is a collection of tide predictions.

type Weather

type Weather struct {
	DateStamp   []string  `json:"dateStamp"`
	TempMax     []float32 `json:"temp_max"`
	TempMin     []float32 `json:"temp_min"`
	WeatherType []string  `json:"weather_type"`
	Units       string    `json:"units"`
}

Weather is a collection of weather info.

type Wind

type Wind struct {
	DateStamp      [][]string  `json:"dateStamp"`
	PeriodSchedule [][]string  `json:"periodSchedule"`
	WindDirection  [][]float32 `json:"wind_direction"`
	WindSpeed      [][]float32 `json:"wind_speed"`
	Units          string      `json:"units"`
}

Wind is a collection of wind info.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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