surflinef

package module
v2.8.0 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: 9 Imported by: 2

README

SurflineF

Build Status

An API client for fetching data from the Surfline API v2.

Installation

Make sure to use versions 2.x.x or greater in your go.mod file.

Usage

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

Conditions

Conditions - Base URL

https://services.surfline.com/kbyg/regions/forecasts/conditions

Conditions - Known Query Params
  • subregionId (string) - Can get this from the taxonomy API
  • days (integer) - Greater than 1 and less than 6 (unless logged in)
  • accessToken (string) - Allows gathering data for more than 6 days out
Conditions - Example URL

https://services.surfline.com/kbyg/regions/forecasts/conditions?subregionId=58581a836630e24c44878fd4&days=6

Conditions - Data Structure
{
  "timestamp": 1581148800,
  "forecaster": {
    "name": "Schaler Perry",
    "avatar": "https://www.gravatar.com/avatar/ea1e9a0c570c61d61dec3cf6ea26a85e?d=mm"
  },
  "human": true,
  "observation": "NW swell continues. Deep mid-morning high tide.",
  "am": {
    "maxHeight": 3,
    "minHeight": 2,
    "plus": false,
    "humanRelation": "2-3 ft – knee to waist high",
    "occasionalHeight": null,
    "rating": "FAIR"
  },
  "pm": {
    "maxHeight": 3,
    "minHeight": 2,
    "plus": false,
    "humanRelation": "2-3 ft – knee to waist high",
    "occasionalHeight": null,
    "rating": "POOR_TO_FAIR"
  }
}

Tides

Tides - Base URL

https://services.surfline.com/kbyg/spots/forecasts/tides

Tides - Known Query Params
  • spotId (string) - Can get this from the taxonomy API
  • days (integer) - Greater than 1 and less than 6 (unless logged in)
  • accessToken (string) - Allows gathering data for more than 6 days out
Tides - Example URL

https://services.surfline.com/kbyg/spots/forecasts/tides?spotId=5842041f4e65fad6a7708814&days=6

Tides - Data Structure
{
  "timestamp": 1581062400,
  "type": "NORMAL",
  "height": 2.33
}

Taxonomy

Taxonomy - Base URL

https://services.surfline.com/taxonomy

Taxonomy - Known Query Params
  • type (string) - Can be a few things... taxonomy is one but not sure about others
  • id (string) - ID of the taxonomy record (continent, country, region or area)
  • maxDepth (integer) - Depth of the taxonomy search. Use 0 for searches for continents, country, regions and areas. Use 1 for area to find contained spots
Taxonomy - Example URL

https://services.surfline.com/taxonomy?type=taxonomy&id=58f7ed51dadb30820bb38791&maxDepth=0

Taxonomy - Data Structure

Taxonomy is a slightly recursive data structure (seems like single depth even though you can query for more levels of depth). Basically, a taxonomy record contains a list of other taxonomy records that lie within in (liesIn).

{
  "_id": "58f7ed51dadb30820bb38791",
  "geonameId": 6255149,
  "type": "geoname",
  "liesIn": [],
  "geonames": {},
  "location": {},
  "enumeratedPath": ",Earth,North America",
  "name": "North America",
  "category": "geonames",
  "hasSpots": true,
  "associated": {},
  "in": [],
  "contains": []
}

Wave

Wave - Base URL

https://services.surfline.com/kbyg/spots/forecasts/wave

Wave - Known Query Params
  • spotId (string) - Can get this from the taxonomy API
  • days (integer) - Greater than 1 and less than 6 (unless logged in)
  • intervalHours (integer) - The amount of data points per day (1 - 24; 6 would give 4 data points per day)
  • maxHeights (boolean) - Not exactly sure what this is for... false is the norm, while true will remove most info and only leave the surf.max measurement
  • accessToken (string) - Allows gathering data for more than 6 days out
Wave - Example URL

https://services.surfline.com/kbyg/spots/forecasts/wave?spotId=5842041f4e65fad6a7708814&days=1&intervalHours=24&maxHeights=false

Wave - Data Structure
{
  "timestamp": 1610438400,
  "surf": {
    "min": 2.23,
    "max": 3.22,
    "optimalScore": 0
  },
  "swells": [
    {
      "height": 1.8,
      "period": 15,
      "direction": 267.19,
      "directionMin": 263.67,
      "optimalScore": 1
    }
  ]
}

Login

Login - Base URL

https://services.surfline.com/trusted/token

Login - Known Query Params
  • isShortLived (boolean) - Not really sure... when the app logs in, it uses false
Login - Example URL

https://services.surfline.com/trusted/token?isShortLived=false

Login - Known Payload

The authorizationString is static. It's the base64 encoded values of the client ID and secret for the Surfline app separated by a colon (:). You need to supply your own username and password values.

{
  "authorizationString": "Basic NWM1OWU3YzNmMGI2Y2IxYWQwMmJhZjY2OnNrX1FxWEpkbjZOeTVzTVJ1MjdBbWcz",
  "device_id": "",
  "device_type": "",
  "forced": true,
  "grant_type": "password",
  "password": "foo",
  "username": "bar"
}
Login - Data Structure

Success (tokens modified):

{
  "access_token": "43foodae4ca3d74b59dd96fd8a82a135f914d1b2",
  "refresh_token": "c8667107c8fd7957d50865093e9d82925bar33a3",
  "expires_in": 3592000,
  "token_type": "Bearer"
}

Error (Invalid login credentials):

{
  "error": "invalid_request",
  "error_description": "Invalid email and password combination"
}

Documentation

Index

Constants

View Source
const ConditionsBaseURL = "https://services.surfline.com/kbyg/regions/forecasts/conditions"

ConditionsBaseURL is the base URL for the regional conditions service

View Source
const LoginBaseURL = "https://services.surfline.com/trusted/token"
View Source
const TaxonomyBaseURL = "https://services.surfline.com/taxonomy"

TaxonomyBaseURL is the base URL for the taxonomy service

View Source
const TidesBaseURL = "https://services.surfline.com/kbyg/spots/forecasts/tides"

TidesBaseURL is the base URL for the spot tides service

View Source
const WaveBaseURL = "https://services.surfline.com/kbyg/spots/forecasts/wave"

WaveBaseURL is the base URL for the wave/swell service

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL *url.URL
}

Client is the SurflineF HTTP Client.

func (*Client) FullURL

func (c *Client) FullURL(qs string) string

FullURL formats the query string and Client BaseUrl

func (*Client) Get

func (c *Client) Get(u *url.URL) (*http.Response, error)

Get is just a wrapper for http.Get

func (*Client) GetConditions

func (c *Client) GetConditions(cq ConditionsQuery) (ConditionsResponse, error)

GetConditions fetches a ConditionsResponse from the API

func (*Client) GetTaxonomy added in v2.2.0

func (c *Client) GetTaxonomy(tq TaxonomyQuery) (Taxonomy, error)

GetTaxonomy fetches a Taxonomy from the API

func (*Client) GetTides

func (c *Client) GetTides(tq TidesQuery) (TidesResponse, error)

GetTides fetches a TidesResponse from the API

func (*Client) GetWave added in v2.4.0

func (c *Client) GetWave(wq WaveQuery) (WaveResponse, error)

GetWave fetches a WaveResponse from the API

func (*Client) PostLogin added in v2.7.0

func (c *Client) PostLogin(lq LoginQuery, lp LoginPayload) (LoginResponse, error)

type Condition

type Condition struct {
	Timestamp   int        `json:"timestamp"`
	Forecaster  Forecaster `json:"forecaster"`
	Human       bool       `json:"human"`
	Observation string     `json:"observation"`
	AM          Report     `json:"am"`
	PM          Report     `json:"pm"`
}

Condition is the JSON struct for a daily condition

type ConditionsAssociated added in v2.5.0

type ConditionsAssociated struct {
	Units     Units `json:"units"`
	UTCOffset int32 `json:"utcOffset"`
}

ConditionsAssociated is associated info to go along with the Conditions API response It includes units of measurement and utc offset for timezones

type ConditionsQuery added in v2.5.0

type ConditionsQuery struct {
	SubregionID string `url:"subregionId"`
	Days        int    `url:"days"`
	AccessToken string `url:"accesstoken,omitempty"`
}

ConditionsQuery is used to build Conditions query params

type ConditionsResponse

type ConditionsResponse struct {
	Associated ConditionsAssociated `json:"associated"`
	Data       conditonsData        `json:"data"`
}

ConditionsResponse is the root JSON struct for condition data

type ErrorLoginResponse added in v2.7.0

type ErrorLoginResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type Forecaster

type Forecaster struct {
	Name   string `json:"name"`
	Avatar string `json:"avatar"`
}

Forecaster is the JSON struct for the forecaster

type Location added in v2.4.0

type Location struct {
	Lon float64 `json:"lon"`
	Lat float64 `json:"lat"`
}

Location contains Lat and Lon(g) for related places

type LoginPayload added in v2.7.0

type LoginPayload struct {
	AuthorizationString string `json:"authorizationString"`
	DeviseID            string `json:"device_id"`
	DeviseType          string `json:"device_type"`
	Forced              bool   `json:"forced"`
	GrantType           string `json:"grant_type"`
	Password            string `json:"password"`
	Username            string `json:"username"`
}

func DefaultLoginPayload added in v2.7.0

func DefaultLoginPayload(username string, password string) LoginPayload

type LoginQuery added in v2.7.0

type LoginQuery struct {
	IsShortLived bool `url:"isShortLived"`
}

type LoginResponse added in v2.7.0

type LoginResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
	TokenType    string `json:"token_type"`
}

type Report

type Report struct {
	MaxHeight        float64 `json:"maxHeight"`
	MinHeight        float64 `json:"minHeight"`
	HumanRelation    string  `json:"humanRelation"`
	Rating           string  `json:"rating"`
	Plus             bool    `json:"plus"`
	OccasionalHeight float64 `json:"occasionalHeight"`
}

Report is the JSON struct of a report (for the AM or PM)

type Surf added in v2.4.0

type Surf struct {
	Min          float64 `json:"min"`
	Max          float64 `json:"max"`
	OptimalScore int     `json:"optimalScore"`
}

Surf is the JSON struct for an interval's nearshore height At least... I think it is nearshore height

type Swell added in v2.4.0

type Swell struct {
	Height       float64 `json:"height"`
	Period       int     `json:"period"`
	Direction    float64 `json:"direction"`
	DirectionMin float64 `json:"directionMin"`
	OptimalScore int     `json:"optimalScore"`
}

Swell is the JSON struct for an interval's individual swell

type Taxonomy added in v2.2.0

type Taxonomy struct {
	ID        string     `json:"_id"`
	Spot      string     `json:"spot"`      // different kind of ID for spots
	Subregion string     `json:"subregion"` // different kind of ID for subregions
	Type      string     `json:"type"`      // ["geoname", "spot", "subregion"]
	Name      string     `json:"name"`
	HasSpots  bool       `json:"hasSpots"`
	Contains  []Taxonomy `json:"contains"`
}

Taxonomy is the JSON struct for a daily condition

type TaxonomyQuery added in v2.2.0

type TaxonomyQuery struct {
	ID       string `url:"id"`
	MaxDepth int    `url:"maxDepth"`
	Type     string `url:"type"`
}

TaxonomyQuery is used to build Taxonomy query params

type Tide

type Tide struct {
	Timestamp int     `json:"timestamp"`
	Type      string  `json:"type"`
	Height    float64 `json:"height"`
}

Tide is the JSON struct for a tide reading

type TidesAssociated added in v2.5.0

type TidesAssociated struct {
	Units        Units    `json:"units"`
	UTCOffset    int32    `json:"utcOffset"`
	TideLocation Location `json:"tideLocation"`
}

TidesAssociated is associated info to go along with the Tide API response It includes units of measurement, utc offset for timezones, related locations, etc

type TidesQuery added in v2.5.0

type TidesQuery struct {
	SpotID      string `url:"spotId"`
	Days        int    `url:"days"`
	AccessToken string `url:"accesstoken,omitempty"`
}

TidesQuery is used to build Tides query params

type TidesResponse

type TidesResponse struct {
	Associated TidesAssociated `json:"associated"`
	Data       tidesData       `json:"data"`
}

TidesResponse is the root JSON struct for tide data

type Units added in v2.4.0

type Units struct {
	Temperature string `json:"temperature"`
	TideHeight  string `json:"tideHeight"`
	SwellHeight string `json:"swellHeight"`
	WaveHeight  string `json:"waveHeight"`
	WindSpeed   string `json:"windSpeed"`
	Model       string `json:"model"`
}

Units is a collection of units for measurements (heights, speeds, etc)

type Wave added in v2.4.0

type Wave struct {
	Timestamp int     `json:"timestamp"`
	Surf      Surf    `json:"surf"`
	Swells    []Swell `json:"swells"`
}

Wave is the JSON struct for an interval's swells

type WaveAssociated added in v2.5.0

type WaveAssociated struct {
	Units            Units    `json:"units"`
	UTCOffset        int32    `json:"utcOffset"`
	Location         Location `json:"location"`
	ForecastLocation Location `json:"forecastLocation"`
	OffshoreLocation Location `json:"offshoreLocation"`
}

WaveAssociated is associated info to go along with the Wave API response It includes units of measurement, utc offset for timezones, related locations, etc

type WaveQuery added in v2.5.0

type WaveQuery struct {
	SpotID        string `url:"spotId"`
	Days          int    `url:"days"`
	IntervalHours int    `url:"intervalHours"`
	MaxHeights    bool   `url:"maxHeights"`
	AccessToken   string `url:"accesstoken,omitempty"`
}

WaveQuery is used to build Wave query params

type WaveResponse added in v2.4.0

type WaveResponse struct {
	Associated WaveAssociated `json:"associated"`
	Data       waveData       `json:"data"`
}

WaveResponse is the root JSON struct for wave data

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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