Documentation
¶
Index ¶
- Constants
- func GenerateOAuth2Config(conf OAuth2BaseConfig) (oac oauth2.Config)
- func GetUserAuthorizationURL(oac oauth2.Config, uniqID string) (userAuthURL string)
- func RetreiveUserRealAuthorizationURL(ctx context.Context, oac oauth2.Config, uniqID string, ...) (userRealAuthURL string, err error)
- type AuthenticatedClient
- func NewClientWithAuthorizationCode(ctx context.Context, oac oauth2.Config, authCode string, ...) (client AuthenticatedClient, err error)
- func NewClientWithClientCredentials(ctx context.Context, oac oauth2.Config, username, password string, ...) (client AuthenticatedClient, err error)
- func NewClientWithTokens(ctx context.Context, oac oauth2.Config, previousTokens *oauth2.Token, ...) (client AuthenticatedClient, err error)
- type Controller
- type HTTPStatusGenericError
- type HTTPStatusOKError
- type HTTPStatusOKErrors
- type OAuth2BaseConfig
- type RequestStats
- type RequestStatusOKPayload
- type UnexpectedHTTPCode
Constants ¶
const ( // NetatmoAPIAuthURL is the netatmo oauth2 authorize URL NetatmoAPIAuthURL = "https://api.netatmo.com/oauth2/authorize" // NetatmoAPITokenURL is the netatmo oauth2 token URL NetatmoAPITokenURL = "https://api.netatmo.com/oauth2/token" )
const ( // ScopeStationRead - to retrieve weather station data (Getstationsdata, Getmeasure) ScopeStationRead = "read_station" // ScopeThermostatRead - to retrieve thermostat data (Homestatus, Getroommeasure...) ScopeThermostatRead = "read_thermostat" // ScopeThermostatWrite - to set up the thermostat (Synchomeschedule, Setroomthermpoint...) ScopeThermostatWrite = "write_thermostat" // ScopeCameraRead - to retrieve Smart Indoor Cameradata (Gethomedata, Getcamerapicture...) ScopeCameraRead = "read_camera" // ScopeCameraWrite - to inform the Smart Indoor Camera that a specific person or everybody has left the Home (Setpersonsaway, Setpersonshome) ScopeCameraWrite = "write_camera" // ScopeCameraAccess - to access the camera, the videos and the live stream ScopeCameraAccess = "access_camera" // ScopePresenceRead - to retrieve Smart Outdoor Camera data (Gethomedata, Getcamerapicture...) ScopePresenceRead = "read_presence" // ScopePresenceAccess - to access the camera, the videos and the live stream ScopePresenceAccess = "access_presence" // ScopeSmokeDetectorRead - to retrieve the Smart Smoke Alarm informations and events (Gethomedata, Geteventsuntil...) ScopeSmokeDetectorRead = "read_smokedetector" // ScopeHomeCoachRead - to read data coming from Smart Indoor Air Quality Monitor (gethomecoachsdata) ScopeHomeCoachRead = "read_homecoach" )
const (
// NetatmoAPIBaseURL is the base URL for all API calls
NetatmoAPIBaseURL = "https://api.netatmo.com/api/"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateOAuth2Config ¶
func GenerateOAuth2Config(conf OAuth2BaseConfig) (oac oauth2.Config)
GenerateOAuth2Config generates a complete OAuth2 config for the Netatmo API
func GetUserAuthorizationURL ¶
GetUserAuthorizationURL returns the Netatmo OAuth2 standard URL for user authorization. Unfortunately, Netatmo requires you to access it with POST, in order for the Netatmo servers to answer back the real URL with a 302. This can be annoying if you want to show/transmit your user a simple GET url: in that case, you can use the RetreiveUserRealAuthorizationURL() function in order to make the POST for you and retrieve the real GET generated URL by the Netatmo servers. See step 1 of https://dev.netatmo.com/apidocumentation/oauth#authorization-code
func RetreiveUserRealAuthorizationURL ¶
func RetreiveUserRealAuthorizationURL(ctx context.Context, oac oauth2.Config, uniqID string, customClient *http.Client) (userRealAuthURL string, err error)
RetreiveUserRealAuthorizationURL is an helper to retrieve the real auth URL you must redirect your user to in order for him to allow your app and trigger your redirect URL set in your app profil. THe returned URL is GETabble. customClient can be nil.
Types ¶
type AuthenticatedClient ¶
type AuthenticatedClient interface { ExecuteNetatmoAPIRequest(ctx context.Context, method, endpoint string, urlValues url.Values, body io.Reader, destination interface{}) (http.Header, RequestStats, error) GetTokens() oauth2.Token }
AuthenticatedClient represents a Netatmo API client needed by the subpackages to query the API. This package provides a reference implementation, see below.
func NewClientWithAuthorizationCode ¶
func NewClientWithAuthorizationCode(ctx context.Context, oac oauth2.Config, authCode string, customClient *http.Client) (client AuthenticatedClient, err error)
NewClientWithAuthorizationCode returns an initialized and ready to use Netatmo API client. authCode is generated by Netatmo once the client has accepted the access thru the auth URL (see GetOfflineAuthURL()). Matches to the 4th step of the OAuth2 autorization code grant type: https://dev.netatmo.com/apidocumentation/oauth#authorization-code . customClient can be nil.
func NewClientWithClientCredentials ¶
func NewClientWithClientCredentials(ctx context.Context, oac oauth2.Config, username, password string, customClient *http.Client) (client AuthenticatedClient, err error)
NewClientWithClientCredentials returns an initialized and ready to use Netatmo API client. https://dev.netatmo.com/apidocumentation/oauth#client-credential customClient can be nil
func NewClientWithTokens ¶
func NewClientWithTokens(ctx context.Context, oac oauth2.Config, previousTokens *oauth2.Token, customClient *http.Client) (client AuthenticatedClient, err error)
NewClientWithTokens allows to restore an already authenticated client with saved tokens. To check how to retrieve a client tokens, check GetTokens(). customClient can be nil
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller can act as a netatmo API Client. Do not instantiate directly, use ExecuteNetatmoAPIReaquest(), NewClientWithClientCredentials() or NewClientWithToken() instead.
func (*Controller) ExecuteNetatmoAPIRequest ¶
func (c *Controller) ExecuteNetatmoAPIRequest(ctx context.Context, method, endpoint string, urlValues url.Values, body io.Reader, destination interface{}) (headers http.Header, rs RequestStats, err error)
ExecuteNetatmoAPIRequest takes care of all the HTTP logic as well as JSON parsing and error handling
func (*Controller) GetTokens ¶
func (c *Controller) GetTokens() (tokens oauth2.Token)
GetTokens returns a copy of the client tokens. Might not be safe to call to use while the client is used, use to save state once the client is not used any more (ex: stopping/shutdown)
type HTTPStatusGenericError ¶
type HTTPStatusGenericError struct { HTTPCode int `` NetatmoCode int `json:"code"` Message string `json:"message"` }
HTTPStatusGenericError is used to represent a non 200 HTTP error
func (HTTPStatusGenericError) Error ¶
func (hsge HTTPStatusGenericError) Error() string
type HTTPStatusOKError ¶
HTTPStatusOKError represents a single API error while the HTTP request has returned 200
func (HTTPStatusOKError) Error ¶
func (hsoe HTTPStatusOKError) Error() string
type HTTPStatusOKErrors ¶
type HTTPStatusOKErrors []HTTPStatusOKError
HTTPStatusOKErrors represents https://dev.netatmo.com/apidocumentation/general#status-ok
func (HTTPStatusOKErrors) Error ¶
func (hsoes HTTPStatusOKErrors) Error() string
type OAuth2BaseConfig ¶
type OAuth2BaseConfig struct { ClientID string ClientSecret string Scopes []string // see the string constants begenning with "ScopeXXX" // RedirectURL must match the one set on your application profil on the dev portal // mandatory if you are using authorization code workflow, leave empty for client credentials workflow RedirectURL string }
OAuth2BaseConfig contains basic OAuth2 informations allowing to build the full conf with GenerateOAuth2Config().
type RequestStats ¶
RequestStats contains the request stats sent by the netatmo API servers after a query
type RequestStatusOKPayload ¶
type RequestStatusOKPayload struct { Body *json.RawMessage `json:"body"` Errors HTTPStatusOKErrors `json:"errors"` Status string `json:"status"` // ex: "ok" TimeExec float64 `json:"time_exec"` // ex: 0.1116938591003418 TimeServer int64 `json:"time_server"` // ex: 1621453691 }
RequestStatusOKPayload is the generic payload received from the netatmo API servers
type UnexpectedHTTPCode ¶
UnexpectedHTTPCode will be used for any unexpected HTTP error codes
func (UnexpectedHTTPCode) Error ¶
func (uhc UnexpectedHTTPCode) Error() string