nettoyage

gestion d'erreur
This commit is contained in:
Laurent Le Houerou 2020-05-27 15:35:02 +04:00
parent 2dd8c960d1
commit 61c15fae6b
12 changed files with 152 additions and 331 deletions

160
arlo.go
View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
import ( import (
@ -46,74 +30,111 @@ func NewArlo() (arlo *Arlo) {
} }
} }
func (a *Arlo) get(url string, result interface{}) error {
var errorResponse ErrorResponse
resp, err := a.client.R().
SetResult(result).
SetError(&errorResponse).
Get(url)
if err != nil {
return err
}
if resp.IsError() {
return fmt.Errorf(errorResponse.Reason)
}
return nil
}
func (a *Arlo) post(url string, body interface{}, result interface{}, xcloudId string) error {
var errorResponse ErrorResponse
request := a.client.R().
SetBody(body).
SetResult(result).
SetError(&errorResponse)
if xcloudId != "" {
request.SetHeader("xcloudId", xcloudId)
}
resp, err := request.Post(url)
if err != nil {
return err
}
if resp.IsError() {
return fmt.Errorf(errorResponse.Reason)
}
return nil
}
func (a *Arlo) put(url string, result interface{}, xcloudId string) error {
var errorResponse ErrorResponse
request := a.client.R().
SetResult(result).
SetError(&errorResponse)
if xcloudId != "" {
request.SetHeader("xcloudId", xcloudId)
}
resp, err := request.Put(url)
if err != nil {
return err
}
if resp.IsError() {
return fmt.Errorf(errorResponse.Reason)
}
return nil
}
func (a *Arlo) Login(ctx context.Context, user string, pass string) error { func (a *Arlo) Login(ctx context.Context, user string, pass string) error {
var loginResponse LoginResponse var loginResponse LoginResponse
_, err := a.client.R(). err := a.post(LoginV2Uri, map[string]string{
SetBody(map[string]string{ "email": user,
"email": user, "password": pass,
"password": pass, }, &loginResponse, "")
}).
SetResult(&loginResponse). // or SetResult(AuthSuccess{}).
Post(LoginV2Uri)
if err != nil { if err != nil {
return fmt.Errorf("failed to login: %v", err) return fmt.Errorf("posting login request: %v", err)
} }
if !loginResponse.Success { if !loginResponse.Success {
return fmt.Errorf("failed to login") return fmt.Errorf("no success but no error")
} }
// Cache the auth token.
a.client.SetHeader("Authorization", loginResponse.Data.Token) a.client.SetHeader("Authorization", loginResponse.Data.Token)
// Save the account info with the arlo struct.
a.Account = loginResponse.Data a.Account = loginResponse.Data
// Get the devices, which also caches them on the arlo object.
if _, err := a.GetDevices(ctx); err != nil { if _, err := a.GetDevices(ctx); err != nil {
return fmt.Errorf("getting devices: %v", err) return fmt.Errorf("getting devices: %v", err)
} }
return nil return nil
} }
func (a *Arlo) Logout() error { func (a *Arlo) Logout() error {
var response Status var response BaseResponse
_, err := a.client.R(). err := a.put(LogoutUri, &response, "")
SetResult(&response).
Put(LogoutUri)
if err != nil { if err != nil {
return fmt.Errorf("logging out: %v", err) return err
} }
if response.Success == false { if !response.Success {
return fmt.Errorf("logging out: %s", response.Reason) return fmt.Errorf("no success but no error")
} }
return nil return nil
} }
func (a *Arlo) GetSession() (*Session, error) { func (a *Arlo) GetSession() (*Session, error) {
var response SessionResponse var response SessionResponse
_, err := a.client.R(). err := a.get(SessionUri, &response)
SetResult(&response).
Get(SessionUri)
if err != nil { if err != nil {
return nil, fmt.Errorf("getting session: %v", err) return nil, err
} }
if response.Success == false { if !response.Success {
return nil, fmt.Errorf("getting session: %s", response.Reason) return nil, fmt.Errorf("no success but no error")
} }
return &response.Data, nil return &response.Data, nil
} }
func (a *Arlo) GetDevices(ctx context.Context) (*Devices, error) { func (a *Arlo) GetDevices(ctx context.Context) (*Devices, error) {
var response DeviceResponse var response DeviceResponse
_, err := a.client.R(). err := a.get(fmt.Sprintf(DevicesUri, time.Now().Format("20060102")), &response)
SetResult(&response).
Get(fmt.Sprintf(DevicesUri, time.Now().Format("20060102")))
if err != nil { if err != nil {
return nil, fmt.Errorf("getting devices: %v", err) return nil, err
} }
if !response.Success { if !response.Success {
return nil, fmt.Errorf("failed to get devices") return nil, fmt.Errorf("no success but no error")
} }
if len(response.Data) == 0 { if len(response.Data) == 0 {
return nil, fmt.Errorf("no device found") return nil, fmt.Errorf("no device found")
@ -149,45 +170,12 @@ func (a *Arlo) GetDevices(ctx context.Context) (*Devices, error) {
// GetProfile returns the user profile for the currently logged in user. // GetProfile returns the user profile for the currently logged in user.
func (a *Arlo) GetProfile() (*UserProfile, error) { func (a *Arlo) GetProfile() (*UserProfile, error) {
var response UserProfileResponse var response UserProfileResponse
_, err := a.client.R(). err := a.get(ProfileUri, &response)
SetResult(&response).
Get(ProfileUri)
if err != nil { if err != nil {
return nil, fmt.Errorf("getting user profile: %v", err) return nil, err
} }
if response.Success == false { if !response.Success {
return nil, fmt.Errorf("getting user profile: %s", response.Reason) return nil, fmt.Errorf("no success but no error")
} }
return &response.Data, nil return &response.Data, nil
} }
//// UpdateDisplayOrder sets the display order according to the order defined in the DeviceOrder given.
//func (a *Arlo) UpdateDisplayOrder(d DeviceOrder) error {
// resp, err := a.post(CameraOrderUri, "", d, nil)
// return checkRequest(resp, err, "failed to display order")
//}
//
//// UpdateProfile takes a first and last name, and updates the user profile with that information.
//func (a *Arlo) UpdateProfile(firstName, lastName string) error {
// body := map[string]string{"firstName": firstName, "lastName": lastName}
// resp, err := a.put(ProfileUri, "", body, nil)
// return checkRequest(resp, err, "failed to update profile")
//}
//
//func (a *Arlo) UpdatePassword(pass string) error {
// body := map[string]string{"currentPassword": a.pass, "newPassword": pass}
// resp, err := a.post(UpdatePasswordUri, "", body, nil)
// if err := checkRequest(resp, err, "failed to update password"); err != nil {
// return err
// }
//
// a.pass = pass
//
// return nil
//}
//
//func (a *Arlo) UpdateFriends(f Friend) error {
// resp, err := a.put(FriendsUri, "", f, nil)
// return checkRequest(resp, err, "failed to update friends")
//}

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
import ( import (
@ -108,6 +92,14 @@ type Rule struct {
ID string `json:"id"` ID string `json:"id"`
} }
type CalendarMode struct {
Active bool `json:"active"`
Schedule []struct {
ModeID string `json:"modeId"`
StartTime int `json:"startTime"`
} `json:"schedule"`
}
// Basestations is a slice of Basestation objects. // Basestations is a slice of Basestation objects.
type Basestations []*Basestation type Basestations []*Basestation
@ -217,16 +209,13 @@ forLoop:
} }
func (b *Basestation) Unsubscribe() error { func (b *Basestation) Unsubscribe() error {
var response Status var response BaseResponse
_, err := b.arlo.client.R(). err := b.arlo.put(UnsubscribeUri, &response, b.XCloudId)
SetResult(&response).
SetHeader("xcloudId", b.XCloudId).
Put(UnsubscribeUri)
if err != nil { if err != nil {
return fmt.Errorf("unsubscribing from event stream: %v", err) return err
} }
if response.Success == false { if !response.Success {
return fmt.Errorf("unsubscribing from event stream: %s", response.Reason) return fmt.Errorf("no success but no error")
} }
return nil return nil
} }
@ -240,34 +229,19 @@ func (b *Basestation) Disconnect() error {
} }
// Ping makes a call to the subscriptions endpoint. The Arlo event stream requires this message to be sent every 30s. // Ping makes a call to the subscriptions endpoint. The Arlo event stream requires this message to be sent every 30s.
func (b *Basestation) Ping() error {
payload := EventStreamPayload{
Action: "set",
Resource: fmt.Sprintf("subscriptions/%s_%s", b.UserId, TransIdPrefix),
PublishResponse: false,
Properties: map[string][1]string{"devices": {b.DeviceId}},
From: fmt.Sprintf("%s_%s", b.UserId, TransIdPrefix),
To: b.DeviceId,
}
if _, err := b.makeEventStreamRequest(payload); err != nil {
return err
}
return nil
}
func (b *Basestation) NotifyEventStream(payload EventStreamPayload) error { func (b *Basestation) NotifyEventStream(payload EventStreamPayload) error {
var response Status var response ErrorResponse
_, err := b.arlo.client.R(). err := b.arlo.post(fmt.Sprintf(NotifyUri, b.DeviceId), payload, &response, b.XCloudId)
SetBody(payload).
SetResult(&response).
SetHeader("xcloudId", b.XCloudId).
Post(fmt.Sprintf(NotifyUri, b.DeviceId))
if err != nil { if err != nil {
return fmt.Errorf("notifying event stream: %v", err) return err
} }
if response.Success == false { if !response.Success {
return fmt.Errorf("notifying event stream: %s", response.Reason) if response.Reason != "" {
return fmt.Errorf(response.Reason)
} else {
return fmt.Errorf("no success but no error")
}
} }
return nil return nil
} }
@ -294,6 +268,14 @@ func (b *Basestation) makeRequest(action string, resource string, publishRespons
return nil return nil
} }
func (b *Basestation) Ping() error {
err := b.makeRequest("set", fmt.Sprintf("subscriptions/%s_%s", b.UserId, TransIdPrefix), false, map[string][1]string{"devices": {b.DeviceId}}, nil)
if err != nil {
return fmt.Errorf("getting basestation %s state: %v", b.DeviceName, err)
}
return nil
}
func (b *Basestation) GetState() (*BaseStationState, error) { func (b *Basestation) GetState() (*BaseStationState, error) {
var state BaseStationState var state BaseStationState
err := b.makeRequest("get", "basestation", false, nil, &state) err := b.makeRequest("get", "basestation", false, nil, &state)
@ -321,16 +303,13 @@ func (b *Basestation) GetRules() ([]Rule, error) {
return resp.Rules, nil return resp.Rules, nil
} }
func (b *Basestation) GetCalendarMode() (response *EventStreamResponse, err error) { func (b *Basestation) GetCalendarMode() (*CalendarMode, error) {
payload := EventStreamPayload{ var calendarMode CalendarMode
Action: "get", err := b.makeRequest("get", "schedule", false, nil, &calendarMode)
Resource: "schedule", if err != nil {
PublishResponse: false, return nil, fmt.Errorf("getting calendar mode: %v", err)
From: fmt.Sprintf("%s_%s", b.UserId, TransIdPrefix),
To: b.DeviceId,
} }
return &calendarMode, nil
return b.makeEventStreamRequest(payload)
} }
// SetCalendarMode toggles calendar mode. // SetCalendarMode toggles calendar mode.
@ -385,16 +364,12 @@ func (b *Basestation) SetCustomMode(mode string) error {
return nil return nil
} }
func (b *Basestation) DeleteMode(mode string) (response *EventStreamResponse, err error) { func (b *Basestation) DeleteMode(mode string) error {
payload := EventStreamPayload{ err := b.makeRequest("delete", fmt.Sprintf("modes/%s", mode), true, nil, nil)
Action: "delete", if err != nil {
Resource: fmt.Sprintf("modes/%s", mode), return fmt.Errorf("deleting mode %s: %v", mode, err)
PublishResponse: true,
From: fmt.Sprintf("%s_%s", b.UserId, TransIdPrefix),
To: b.DeviceId,
} }
return nil
return b.makeEventStreamRequest(payload)
} }
func (b *Basestation) Arm() error { func (b *Basestation) Arm() error {

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
import ( import (

View File

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"git.lehouerou.net/laurent/arlo-go" "git.lehouerou.net/laurent/arlo-go"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -19,7 +20,12 @@ func main() {
} }
for _, b := range a.Basestations { for _, b := range a.Basestations {
err := b.SetCustomMode("mode3") _, err := b.GetModes()
if err != nil {
log.Error(err)
}
log.Info("ok")
err = b.DeleteMode("mode5")
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
const ( const (

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
// A Device is the device data, this can be a camera, basestation, arloq, etc. // A Device is the device data, this can be a camera, basestation, arloq, etc.

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
import ( import (

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
// LibraryMetaData is the library meta data. // LibraryMetaData is the library meta data.

View File

@ -1,19 +0,0 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo
// TODO: Add support for "lights" type of devices.

View File

@ -1,71 +1,54 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
// URL is part of the Status message fragment returned by most calls to the Arlo API. type BaseResponse struct {
// URL is only populated when Success is false.
type Data struct {
Message string `json:"message,omitempty"`
Reason string `json:"reason,omitempty"`
Error string `json:"error,omitempty"`
}
// Status is the message fragment returned from most http calls to the Arlo API.
type Status struct {
Data `json:"URL,omitempty"`
Success bool `json:"success"` Success bool `json:"success"`
} }
// LoginResponse is an intermediate struct used when parsing data from the Login() call. type ErrorDetail struct {
Message string `json:"message"`
Reason string `json:"reason"`
Error string `json:"error"`
}
type ErrorResponse struct {
BaseResponse
ErrorDetail `json:"data,omitempty"`
}
type LoginResponse struct { type LoginResponse struct {
Data Account BaseResponse
Status Data Account `json:"data"`
} }
type SessionResponse struct { type SessionResponse struct {
Data Session BaseResponse
Status Data Session `json:"data"`
} }
type UserProfileResponse struct { type UserProfileResponse struct {
Data UserProfile BaseResponse
Status Data UserProfile `json:"data"`
} }
// DeviceResponse is an intermediate struct used when parsing data from the GetDevices() call.
type DeviceResponse struct { type DeviceResponse struct {
Data Devices BaseResponse
Status Data Devices `json:"data"`
} }
// LibraryMetaDataResponse is an intermediate struct used when parsing data from the GetLibraryMetaData() call. // LibraryMetaDataResponse is an intermediate struct used when parsing data from the GetLibraryMetaData() call.
type LibraryMetaDataResponse struct { type LibraryMetaDataResponse struct {
Data LibraryMetaData BaseResponse
Status Data LibraryMetaData `json:"data"`
} }
type LibraryResponse struct { type LibraryResponse struct {
Data Library BaseResponse
Status Data Library `json:"data"`
} }
type CvrPlaylistResponse struct { type CvrPlaylistResponse struct {
Data CvrPlaylist BaseResponse
Status Data CvrPlaylist `json:"data"`
} }
type Stream struct { type Stream struct {
@ -73,13 +56,13 @@ type Stream struct {
} }
type StreamResponse struct { type StreamResponse struct {
Data Stream BaseResponse
Status Data Stream `json:"data"`
} }
type RecordingResponse struct { type RecordingResponse struct {
Data Stream BaseResponse
Status Data Stream `json:"data"`
} }
type EventStreamResponse struct { type EventStreamResponse struct {

View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
/* /*

16
util.go
View File

@ -1,19 +1,3 @@
/*
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package arlo package arlo
import ( import (