diff --git a/access_codes.go b/access_codes.go index 62b1fec..9b43af2 100644 --- a/access_codes.go +++ b/access_codes.go @@ -5,71 +5,406 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" + time "time" ) type AccessCodesCreateRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - StartsAt *string `json:"starts_at,omitempty" url:"starts_at,omitempty"` - EndsAt *string `json:"ends_at,omitempty" url:"ends_at,omitempty"` - Code *string `json:"code,omitempty" url:"code,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` - AttemptForOfflineDevice *bool `json:"attempt_for_offline_device,omitempty" url:"attempt_for_offline_device,omitempty"` - CommonCodeKey *string `json:"common_code_key,omitempty" url:"common_code_key,omitempty"` - PreferNativeScheduling *bool `json:"prefer_native_scheduling,omitempty" url:"prefer_native_scheduling,omitempty"` - UseBackupAccessCodePool *bool `json:"use_backup_access_code_pool,omitempty" url:"use_backup_access_code_pool,omitempty"` - AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"allow_external_modification,omitempty"` - IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"is_external_modification_allowed,omitempty"` - UseOfflineAccessCode *bool `json:"use_offline_access_code,omitempty" url:"use_offline_access_code,omitempty"` - IsOfflineAccessCode *bool `json:"is_offline_access_code,omitempty" url:"is_offline_access_code,omitempty"` - IsOneTimeUse *bool `json:"is_one_time_use,omitempty" url:"is_one_time_use,omitempty"` - MaxTimeRounding *MaxTimeRounding `json:"max_time_rounding,omitempty" url:"max_time_rounding,omitempty"` + DeviceId string `json:"device_id" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + StartsAt *string `json:"starts_at,omitempty" url:"-"` + EndsAt *string `json:"ends_at,omitempty" url:"-"` + Code *string `json:"code,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` + AttemptForOfflineDevice *bool `json:"attempt_for_offline_device,omitempty" url:"-"` + CommonCodeKey *string `json:"common_code_key,omitempty" url:"-"` + PreferNativeScheduling *bool `json:"prefer_native_scheduling,omitempty" url:"-"` + UseBackupAccessCodePool *bool `json:"use_backup_access_code_pool,omitempty" url:"-"` + AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"-"` + IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"-"` + UseOfflineAccessCode *bool `json:"use_offline_access_code,omitempty" url:"-"` + IsOfflineAccessCode *bool `json:"is_offline_access_code,omitempty" url:"-"` + IsOneTimeUse *bool `json:"is_one_time_use,omitempty" url:"-"` + MaxTimeRounding *MaxTimeRounding `json:"max_time_rounding,omitempty" url:"-"` } type AccessCodesCreateMultipleRequest struct { - DeviceIds []string `json:"device_ids,omitempty" url:"device_ids,omitempty"` - BehaviorWhenCodeCannotBeShared *AccessCodesCreateMultipleRequestBehaviorWhenCodeCannotBeShared `json:"behavior_when_code_cannot_be_shared,omitempty" url:"behavior_when_code_cannot_be_shared,omitempty"` - PreferredCodeLength *float64 `json:"preferred_code_length,omitempty" url:"preferred_code_length,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - StartsAt *string `json:"starts_at,omitempty" url:"starts_at,omitempty"` - EndsAt *string `json:"ends_at,omitempty" url:"ends_at,omitempty"` - Code *string `json:"code,omitempty" url:"code,omitempty"` - AttemptForOfflineDevice *bool `json:"attempt_for_offline_device,omitempty" url:"attempt_for_offline_device,omitempty"` - PreferNativeScheduling *bool `json:"prefer_native_scheduling,omitempty" url:"prefer_native_scheduling,omitempty"` - UseBackupAccessCodePool *bool `json:"use_backup_access_code_pool,omitempty" url:"use_backup_access_code_pool,omitempty"` - AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"allow_external_modification,omitempty"` - IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"is_external_modification_allowed,omitempty"` - UseOfflineAccessCode *bool `json:"use_offline_access_code,omitempty" url:"use_offline_access_code,omitempty"` - IsOfflineAccessCode *bool `json:"is_offline_access_code,omitempty" url:"is_offline_access_code,omitempty"` - IsOneTimeUse *bool `json:"is_one_time_use,omitempty" url:"is_one_time_use,omitempty"` - MaxTimeRounding *MaxTimeRounding `json:"max_time_rounding,omitempty" url:"max_time_rounding,omitempty"` + DeviceIds []string `json:"device_ids,omitempty" url:"-"` + BehaviorWhenCodeCannotBeShared *AccessCodesCreateMultipleRequestBehaviorWhenCodeCannotBeShared `json:"behavior_when_code_cannot_be_shared,omitempty" url:"-"` + PreferredCodeLength *float64 `json:"preferred_code_length,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + StartsAt *string `json:"starts_at,omitempty" url:"-"` + EndsAt *string `json:"ends_at,omitempty" url:"-"` + Code *string `json:"code,omitempty" url:"-"` + AttemptForOfflineDevice *bool `json:"attempt_for_offline_device,omitempty" url:"-"` + PreferNativeScheduling *bool `json:"prefer_native_scheduling,omitempty" url:"-"` + UseBackupAccessCodePool *bool `json:"use_backup_access_code_pool,omitempty" url:"-"` + AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"-"` + IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"-"` + UseOfflineAccessCode *bool `json:"use_offline_access_code,omitempty" url:"-"` + IsOfflineAccessCode *bool `json:"is_offline_access_code,omitempty" url:"-"` + IsOneTimeUse *bool `json:"is_one_time_use,omitempty" url:"-"` + MaxTimeRounding *MaxTimeRounding `json:"max_time_rounding,omitempty" url:"-"` } type AccessCodesDeleteRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - AccessCodeId string `json:"access_code_id" url:"access_code_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + AccessCodeId string `json:"access_code_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type AccessCodesGenerateCodeRequest struct { - DeviceId string `json:"device_id" url:"device_id"` + DeviceId string `json:"device_id" url:"-"` } type AccessCodesGetRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - AccessCodeId *string `json:"access_code_id,omitempty" url:"access_code_id,omitempty"` - Code *string `json:"code,omitempty" url:"code,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + AccessCodeId *string `json:"access_code_id,omitempty" url:"-"` + Code *string `json:"code,omitempty" url:"-"` } type AccessCodesListRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - AccessCodeIds []string `json:"access_code_ids,omitempty" url:"access_code_ids,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` + DeviceId string `json:"device_id" url:"-"` + AccessCodeIds []string `json:"access_code_ids,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` } type AccessCodesPullBackupAccessCodeRequest struct { + AccessCodeId string `json:"access_code_id" url:"-"` +} + +type AccessCode struct { + // Unique identifier for a group of access codes that share the same code. + CommonCodeKey *string `json:"common_code_key,omitempty" url:"common_code_key,omitempty"` + // Indicates whether the code is set on the device according to a preconfigured schedule. + IsScheduledOnDevice *bool `json:"is_scheduled_on_device,omitempty" url:"is_scheduled_on_device,omitempty"` + // Nature of the access code. Values are "ongoing" for access codes that are active continuously until deactivated manually or "time_bound" for access codes that have a specific duration. + Type AccessCodeType `json:"type" url:"type"` + // Indicates whether the access code is waiting for a code assignment. + IsWaitingForCodeAssignment *bool `json:"is_waiting_for_code_assignment,omitempty" url:"is_waiting_for_code_assignment,omitempty"` + // Unique identifier for the access code. AccessCodeId string `json:"access_code_id" url:"access_code_id"` + // Unique identifier for the device associated with the access code. + DeviceId string `json:"device_id" url:"device_id"` + // Name of the access code. Enables administrators and users to identify the access code easily, especially when there are numerous access codes. + Name *string `json:"name,omitempty" url:"name,omitempty"` + // Code used for access. Typically, a numeric or alphanumeric string. + Code *string `json:"code,omitempty" url:"code,omitempty"` + // Date and time at which the access code was created. + CreatedAt time.Time `json:"created_at" url:"created_at"` + Errors interface{} `json:"errors,omitempty" url:"errors,omitempty"` + Warnings interface{} `json:"warnings,omitempty" url:"warnings,omitempty"` + // Indicates whether Seam manages the access code. + IsManaged bool `json:"is_managed" url:"is_managed"` + // Date and time at which the time-bound access code becomes active. + StartsAt *time.Time `json:"starts_at,omitempty" url:"starts_at,omitempty"` + // Date and time after which the time-bound access code becomes inactive. + EndsAt *time.Time `json:"ends_at,omitempty" url:"ends_at,omitempty"` + // Current status of the access code within the operational lifecycle. Values are "setting," a transitional phase that indicates that the code is being configured or activated; "set", which indicates that the code is active and operational; "unset," which indicates a deactivated or unused state, either before activation or after deliberate deactivation; "removing," which indicates a transitional period in which the code is being deleted or made inactive; and "unknown," which indicates an indeterminate state, due to reasons such as system errors or incomplete data, that highlights a potential need for system review or troubleshooting. + Status AccessCodeStatus `json:"status" url:"status"` + // Indicates whether a backup access code is available for use if the primary access code is lost or compromised. + IsBackupAccessCodeAvailable bool `json:"is_backup_access_code_available" url:"is_backup_access_code_available"` + // Indicates whether the access code is a backup code. + IsBackup *bool `json:"is_backup,omitempty" url:"is_backup,omitempty"` + // Identifier of the pulled backup access code. Used to associate the pulled backup access code with the original access code. + PulledBackupAccessCodeId *string `json:"pulled_backup_access_code_id,omitempty" url:"pulled_backup_access_code_id,omitempty"` + // Indicates whether changes to the access code from external sources are permitted. + IsExternalModificationAllowed bool `json:"is_external_modification_allowed" url:"is_external_modification_allowed"` + // Indicates whether the access code can only be used once. If "true," the code becomes invalid after the first use. + IsOneTimeUse bool `json:"is_one_time_use" url:"is_one_time_use"` + // Indicates whether the access code is intended for use in offline scenarios. If "true," this code can be created on a device without a network connection. + IsOfflineAccessCode bool `json:"is_offline_access_code" url:"is_offline_access_code"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCode) GetCommonCodeKey() *string { + if a == nil { + return nil + } + return a.CommonCodeKey +} + +func (a *AccessCode) GetIsScheduledOnDevice() *bool { + if a == nil { + return nil + } + return a.IsScheduledOnDevice +} + +func (a *AccessCode) GetType() AccessCodeType { + if a == nil { + return "" + } + return a.Type +} + +func (a *AccessCode) GetIsWaitingForCodeAssignment() *bool { + if a == nil { + return nil + } + return a.IsWaitingForCodeAssignment +} + +func (a *AccessCode) GetAccessCodeId() string { + if a == nil { + return "" + } + return a.AccessCodeId +} + +func (a *AccessCode) GetDeviceId() string { + if a == nil { + return "" + } + return a.DeviceId +} + +func (a *AccessCode) GetName() *string { + if a == nil { + return nil + } + return a.Name +} + +func (a *AccessCode) GetCode() *string { + if a == nil { + return nil + } + return a.Code +} + +func (a *AccessCode) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AccessCode) GetErrors() interface{} { + if a == nil { + return nil + } + return a.Errors +} + +func (a *AccessCode) GetWarnings() interface{} { + if a == nil { + return nil + } + return a.Warnings +} + +func (a *AccessCode) GetIsManaged() bool { + if a == nil { + return false + } + return a.IsManaged +} + +func (a *AccessCode) GetStartsAt() *time.Time { + if a == nil { + return nil + } + return a.StartsAt +} + +func (a *AccessCode) GetEndsAt() *time.Time { + if a == nil { + return nil + } + return a.EndsAt +} + +func (a *AccessCode) GetStatus() AccessCodeStatus { + if a == nil { + return "" + } + return a.Status +} + +func (a *AccessCode) GetIsBackupAccessCodeAvailable() bool { + if a == nil { + return false + } + return a.IsBackupAccessCodeAvailable +} + +func (a *AccessCode) GetIsBackup() *bool { + if a == nil { + return nil + } + return a.IsBackup +} + +func (a *AccessCode) GetPulledBackupAccessCodeId() *string { + if a == nil { + return nil + } + return a.PulledBackupAccessCodeId +} + +func (a *AccessCode) GetIsExternalModificationAllowed() bool { + if a == nil { + return false + } + return a.IsExternalModificationAllowed +} + +func (a *AccessCode) GetIsOneTimeUse() bool { + if a == nil { + return false + } + return a.IsOneTimeUse +} + +func (a *AccessCode) GetIsOfflineAccessCode() bool { + if a == nil { + return false + } + return a.IsOfflineAccessCode +} + +func (a *AccessCode) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *AccessCode) UnmarshalJSON(data []byte) error { + type embed AccessCode + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + StartsAt *internal.DateTime `json:"starts_at,omitempty"` + EndsAt *internal.DateTime `json:"ends_at,omitempty"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AccessCode(unmarshaler.embed) + a.CreatedAt = unmarshaler.CreatedAt.Time() + a.StartsAt = unmarshaler.StartsAt.TimePtr() + a.EndsAt = unmarshaler.EndsAt.TimePtr() + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *AccessCode) MarshalJSON() ([]byte, error) { + type embed AccessCode + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + StartsAt *internal.DateTime `json:"starts_at,omitempty"` + EndsAt *internal.DateTime `json:"ends_at,omitempty"` + }{ + embed: embed(*a), + CreatedAt: internal.NewDateTime(a.CreatedAt), + StartsAt: internal.NewOptionalDateTime(a.StartsAt), + EndsAt: internal.NewOptionalDateTime(a.EndsAt), + } + return json.Marshal(marshaler) +} + +func (a *AccessCode) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Current status of the access code within the operational lifecycle. Values are "setting," a transitional phase that indicates that the code is being configured or activated; "set", which indicates that the code is active and operational; "unset," which indicates a deactivated or unused state, either before activation or after deliberate deactivation; "removing," which indicates a transitional period in which the code is being deleted or made inactive; and "unknown," which indicates an indeterminate state, due to reasons such as system errors or incomplete data, that highlights a potential need for system review or troubleshooting. +type AccessCodeStatus string + +const ( + AccessCodeStatusSetting AccessCodeStatus = "setting" + AccessCodeStatusSet AccessCodeStatus = "set" + AccessCodeStatusUnset AccessCodeStatus = "unset" + AccessCodeStatusRemoving AccessCodeStatus = "removing" + AccessCodeStatusUnknown AccessCodeStatus = "unknown" +) + +func NewAccessCodeStatusFromString(s string) (AccessCodeStatus, error) { + switch s { + case "setting": + return AccessCodeStatusSetting, nil + case "set": + return AccessCodeStatusSet, nil + case "unset": + return AccessCodeStatusUnset, nil + case "removing": + return AccessCodeStatusRemoving, nil + case "unknown": + return AccessCodeStatusUnknown, nil + } + var t AccessCodeStatus + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (a AccessCodeStatus) Ptr() *AccessCodeStatus { + return &a +} + +// Nature of the access code. Values are "ongoing" for access codes that are active continuously until deactivated manually or "time_bound" for access codes that have a specific duration. +type AccessCodeType string + +const ( + AccessCodeTypeTimeBound AccessCodeType = "time_bound" + AccessCodeTypeOngoing AccessCodeType = "ongoing" +) + +func NewAccessCodeTypeFromString(s string) (AccessCodeType, error) { + switch s { + case "time_bound": + return AccessCodeTypeTimeBound, nil + case "ongoing": + return AccessCodeTypeOngoing, nil + } + var t AccessCodeType + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (a AccessCodeType) Ptr() *AccessCodeType { + return &a +} + +type MaxTimeRounding string + +const ( + MaxTimeRoundingOneHour MaxTimeRounding = "1hour" + MaxTimeRoundingOneDay MaxTimeRounding = "1day" + MaxTimeRoundingOneH MaxTimeRounding = "1h" + MaxTimeRoundingOneD MaxTimeRounding = "1d" +) + +func NewMaxTimeRoundingFromString(s string) (MaxTimeRounding, error) { + switch s { + case "1hour": + return MaxTimeRoundingOneHour, nil + case "1day": + return MaxTimeRoundingOneDay, nil + case "1h": + return MaxTimeRoundingOneH, nil + case "1d": + return MaxTimeRoundingOneD, nil + } + var t MaxTimeRounding + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (m MaxTimeRounding) Ptr() *MaxTimeRounding { + return &m } type AccessCodesCreateMultipleRequestBehaviorWhenCodeCannotBeShared string @@ -98,7 +433,26 @@ type AccessCodesCreateMultipleResponse struct { AccessCodes []*AccessCode `json:"access_codes,omitempty" url:"access_codes,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesCreateMultipleResponse) GetAccessCodes() []*AccessCode { + if a == nil { + return nil + } + return a.AccessCodes +} + +func (a *AccessCodesCreateMultipleResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesCreateMultipleResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesCreateMultipleResponse) UnmarshalJSON(data []byte) error { @@ -108,17 +462,22 @@ func (a *AccessCodesCreateMultipleResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesCreateMultipleResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesCreateMultipleResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -129,7 +488,33 @@ type AccessCodesCreateResponse struct { AccessCode *AccessCode `json:"access_code,omitempty" url:"access_code,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesCreateResponse) GetActionAttempt() *ActionAttempt { + if a == nil { + return nil + } + return a.ActionAttempt +} + +func (a *AccessCodesCreateResponse) GetAccessCode() *AccessCode { + if a == nil { + return nil + } + return a.AccessCode +} + +func (a *AccessCodesCreateResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesCreateResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesCreateResponse) UnmarshalJSON(data []byte) error { @@ -139,17 +524,22 @@ func (a *AccessCodesCreateResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesCreateResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesCreateResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -159,7 +549,26 @@ type AccessCodesDeleteResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesDeleteResponse) GetActionAttempt() *ActionAttempt { + if a == nil { + return nil + } + return a.ActionAttempt +} + +func (a *AccessCodesDeleteResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesDeleteResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesDeleteResponse) UnmarshalJSON(data []byte) error { @@ -169,17 +578,22 @@ func (a *AccessCodesDeleteResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesDeleteResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesDeleteResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -189,7 +603,26 @@ type AccessCodesGenerateCodeResponse struct { GeneratedCode *AccessCode `json:"generated_code,omitempty" url:"generated_code,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesGenerateCodeResponse) GetGeneratedCode() *AccessCode { + if a == nil { + return nil + } + return a.GeneratedCode +} + +func (a *AccessCodesGenerateCodeResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesGenerateCodeResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesGenerateCodeResponse) UnmarshalJSON(data []byte) error { @@ -199,17 +632,22 @@ func (a *AccessCodesGenerateCodeResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesGenerateCodeResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesGenerateCodeResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -219,7 +657,26 @@ type AccessCodesGetResponse struct { AccessCode *AccessCode `json:"access_code,omitempty" url:"access_code,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesGetResponse) GetAccessCode() *AccessCode { + if a == nil { + return nil + } + return a.AccessCode +} + +func (a *AccessCodesGetResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesGetResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesGetResponse) UnmarshalJSON(data []byte) error { @@ -229,17 +686,22 @@ func (a *AccessCodesGetResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesGetResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesGetResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -249,7 +711,26 @@ type AccessCodesListResponse struct { AccessCodes []*AccessCode `json:"access_codes,omitempty" url:"access_codes,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesListResponse) GetAccessCodes() []*AccessCode { + if a == nil { + return nil + } + return a.AccessCodes +} + +func (a *AccessCodesListResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesListResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesListResponse) UnmarshalJSON(data []byte) error { @@ -259,17 +740,22 @@ func (a *AccessCodesListResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesListResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesListResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -279,7 +765,26 @@ type AccessCodesPullBackupAccessCodeResponse struct { BackupAccessCode *AccessCode `json:"backup_access_code,omitempty" url:"backup_access_code,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesPullBackupAccessCodeResponse) GetBackupAccessCode() *AccessCode { + if a == nil { + return nil + } + return a.BackupAccessCode +} + +func (a *AccessCodesPullBackupAccessCodeResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesPullBackupAccessCodeResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesPullBackupAccessCodeResponse) UnmarshalJSON(data []byte) error { @@ -289,17 +794,22 @@ func (a *AccessCodesPullBackupAccessCodeResponse) UnmarshalJSON(data []byte) err return err } *a = AccessCodesPullBackupAccessCodeResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesPullBackupAccessCodeResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -331,7 +841,26 @@ type AccessCodesUpdateResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessCodesUpdateResponse) GetActionAttempt() *ActionAttempt { + if a == nil { + return nil + } + return a.ActionAttempt +} + +func (a *AccessCodesUpdateResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessCodesUpdateResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessCodesUpdateResponse) UnmarshalJSON(data []byte) error { @@ -341,39 +870,44 @@ func (a *AccessCodesUpdateResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessCodesUpdateResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessCodesUpdateResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) } type AccessCodesUpdateRequest struct { - Name *string `json:"name,omitempty" url:"name,omitempty"` - StartsAt *string `json:"starts_at,omitempty" url:"starts_at,omitempty"` - EndsAt *string `json:"ends_at,omitempty" url:"ends_at,omitempty"` - Code *string `json:"code,omitempty" url:"code,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` - AttemptForOfflineDevice *bool `json:"attempt_for_offline_device,omitempty" url:"attempt_for_offline_device,omitempty"` - PreferNativeScheduling *bool `json:"prefer_native_scheduling,omitempty" url:"prefer_native_scheduling,omitempty"` - UseBackupAccessCodePool *bool `json:"use_backup_access_code_pool,omitempty" url:"use_backup_access_code_pool,omitempty"` - AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"allow_external_modification,omitempty"` - IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"is_external_modification_allowed,omitempty"` - UseOfflineAccessCode *bool `json:"use_offline_access_code,omitempty" url:"use_offline_access_code,omitempty"` - IsOfflineAccessCode *bool `json:"is_offline_access_code,omitempty" url:"is_offline_access_code,omitempty"` - IsOneTimeUse *bool `json:"is_one_time_use,omitempty" url:"is_one_time_use,omitempty"` - MaxTimeRounding *MaxTimeRounding `json:"max_time_rounding,omitempty" url:"max_time_rounding,omitempty"` - AccessCodeId string `json:"access_code_id" url:"access_code_id"` - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - Type *AccessCodesUpdateRequestType `json:"type,omitempty" url:"type,omitempty"` - IsManaged *bool `json:"is_managed,omitempty" url:"is_managed,omitempty"` + Name *string `json:"name,omitempty" url:"-"` + StartsAt *string `json:"starts_at,omitempty" url:"-"` + EndsAt *string `json:"ends_at,omitempty" url:"-"` + Code *string `json:"code,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` + AttemptForOfflineDevice *bool `json:"attempt_for_offline_device,omitempty" url:"-"` + PreferNativeScheduling *bool `json:"prefer_native_scheduling,omitempty" url:"-"` + UseBackupAccessCodePool *bool `json:"use_backup_access_code_pool,omitempty" url:"-"` + AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"-"` + IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"-"` + UseOfflineAccessCode *bool `json:"use_offline_access_code,omitempty" url:"-"` + IsOfflineAccessCode *bool `json:"is_offline_access_code,omitempty" url:"-"` + IsOneTimeUse *bool `json:"is_one_time_use,omitempty" url:"-"` + MaxTimeRounding *MaxTimeRounding `json:"max_time_rounding,omitempty" url:"-"` + AccessCodeId string `json:"access_code_id" url:"-"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + Type *AccessCodesUpdateRequestType `json:"type,omitempty" url:"-"` + IsManaged *bool `json:"is_managed,omitempty" url:"-"` } diff --git a/accesscodes/client/client.go b/accesscodes/client/client.go index a4b9ec6..dd995e4 100644 --- a/accesscodes/client/client.go +++ b/accesscodes/client/client.go @@ -3,22 +3,19 @@ package client import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" simulate "github.com/seamapi/go/accesscodes/simulate" unmanaged "github.com/seamapi/go/accesscodes/unmanaged" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header Simulate *simulate.Client @@ -29,8 +26,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -47,56 +44,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.AccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -110,56 +95,44 @@ func (c *Client) CreateMultiple( opts ...option.RequestOption, ) ([]*seamapigo.AccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/create_multiple" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/create_multiple" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesCreateMultipleResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -173,56 +146,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.AccessCodesDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -236,56 +197,44 @@ func (c *Client) GenerateCode( opts ...option.RequestOption, ) (*seamapigo.AccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/generate_code" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/generate_code" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesGenerateCodeResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -299,56 +248,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.AccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -362,56 +299,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -425,56 +350,44 @@ func (c *Client) PullBackupAccessCode( opts ...option.RequestOption, ) (*seamapigo.AccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/pull_backup_access_code" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/pull_backup_access_code" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesPullBackupAccessCodeResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -488,56 +401,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*seamapigo.AccessCodesUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.AccessCodesUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/accesscodes/simulate.go b/accesscodes/simulate.go index 36cfdb8..b28e2ab 100644 --- a/accesscodes/simulate.go +++ b/accesscodes/simulate.go @@ -6,20 +6,39 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type SimulateCreateUnmanagedAccessCodeRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Name string `json:"name" url:"name"` - Code string `json:"code" url:"code"` + DeviceId string `json:"device_id" url:"-"` + Name string `json:"name" url:"-"` + Code string `json:"code" url:"-"` } type SimulateCreateUnmanagedAccessCodeResponse struct { AccessCode *seamapigo.UnmanagedAccessCode `json:"access_code,omitempty" url:"access_code,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateCreateUnmanagedAccessCodeResponse) GetAccessCode() *seamapigo.UnmanagedAccessCode { + if s == nil { + return nil + } + return s.AccessCode +} + +func (s *SimulateCreateUnmanagedAccessCodeResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SimulateCreateUnmanagedAccessCodeResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SimulateCreateUnmanagedAccessCodeResponse) UnmarshalJSON(data []byte) error { @@ -29,17 +48,22 @@ func (s *SimulateCreateUnmanagedAccessCodeResponse) UnmarshalJSON(data []byte) e return err } *s = SimulateCreateUnmanagedAccessCodeResponse(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SimulateCreateUnmanagedAccessCodeResponse) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) diff --git a/accesscodes/simulate/client.go b/accesscodes/simulate/client.go index 1f63afc..af1e839 100644 --- a/accesscodes/simulate/client.go +++ b/accesscodes/simulate/client.go @@ -3,21 +3,18 @@ package simulate import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" accesscodes "github.com/seamapi/go/accesscodes" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) CreateUnmanagedAccessCode( opts ...option.RequestOption, ) (*seamapigo.UnmanagedAccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/simulate/create_unmanaged_access_code" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/simulate/create_unmanaged_access_code" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *accesscodes.SimulateCreateUnmanagedAccessCodeResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/accesscodes/unmanaged.go b/accesscodes/unmanaged.go index d77e623..597cc44 100644 --- a/accesscodes/unmanaged.go +++ b/accesscodes/unmanaged.go @@ -6,37 +6,49 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type UnmanagedConvertToManagedRequest struct { - AccessCodeId string `json:"access_code_id" url:"access_code_id"` - IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"is_external_modification_allowed,omitempty"` - AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"allow_external_modification,omitempty"` - Force *bool `json:"force,omitempty" url:"force,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + AccessCodeId string `json:"access_code_id" url:"-"` + IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"-"` + AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"-"` + Force *bool `json:"force,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type UnmanagedDeleteRequest struct { - AccessCodeId string `json:"access_code_id" url:"access_code_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + AccessCodeId string `json:"access_code_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type UnmanagedGetRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - AccessCodeId *string `json:"access_code_id,omitempty" url:"access_code_id,omitempty"` - Code *string `json:"code,omitempty" url:"code,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + AccessCodeId *string `json:"access_code_id,omitempty" url:"-"` + Code *string `json:"code,omitempty" url:"-"` } type UnmanagedListRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` + DeviceId string `json:"device_id" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` } type UnmanagedConvertToManagedResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedConvertToManagedResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedConvertToManagedResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedConvertToManagedResponse) UnmarshalJSON(data []byte) error { @@ -46,17 +58,22 @@ func (u *UnmanagedConvertToManagedResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedConvertToManagedResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedConvertToManagedResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -66,7 +83,26 @@ type UnmanagedDeleteResponse struct { ActionAttempt *seamapigo.ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDeleteResponse) GetActionAttempt() *seamapigo.ActionAttempt { + if u == nil { + return nil + } + return u.ActionAttempt +} + +func (u *UnmanagedDeleteResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedDeleteResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDeleteResponse) UnmarshalJSON(data []byte) error { @@ -76,17 +112,22 @@ func (u *UnmanagedDeleteResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedDeleteResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDeleteResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -96,7 +137,26 @@ type UnmanagedGetResponse struct { AccessCode *seamapigo.UnmanagedAccessCode `json:"access_code,omitempty" url:"access_code,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedGetResponse) GetAccessCode() *seamapigo.UnmanagedAccessCode { + if u == nil { + return nil + } + return u.AccessCode +} + +func (u *UnmanagedGetResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedGetResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedGetResponse) UnmarshalJSON(data []byte) error { @@ -106,17 +166,22 @@ func (u *UnmanagedGetResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedGetResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedGetResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -126,7 +191,26 @@ type UnmanagedListResponse struct { AccessCodes []*seamapigo.UnmanagedAccessCode `json:"access_codes,omitempty" url:"access_codes,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedListResponse) GetAccessCodes() []*seamapigo.UnmanagedAccessCode { + if u == nil { + return nil + } + return u.AccessCodes +} + +func (u *UnmanagedListResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedListResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedListResponse) UnmarshalJSON(data []byte) error { @@ -136,17 +220,22 @@ func (u *UnmanagedListResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedListResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedListResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -155,7 +244,19 @@ func (u *UnmanagedListResponse) String() string { type UnmanagedUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedUpdateResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedUpdateResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedUpdateResponse) UnmarshalJSON(data []byte) error { @@ -165,26 +266,31 @@ func (u *UnmanagedUpdateResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedUpdateResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedUpdateResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UnmanagedUpdateRequest struct { - AccessCodeId string `json:"access_code_id" url:"access_code_id"` - IsManaged bool `json:"is_managed" url:"is_managed"` - AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"allow_external_modification,omitempty"` - IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"is_external_modification_allowed,omitempty"` - Force *bool `json:"force,omitempty" url:"force,omitempty"` + AccessCodeId string `json:"access_code_id" url:"-"` + IsManaged bool `json:"is_managed" url:"-"` + AllowExternalModification *bool `json:"allow_external_modification,omitempty" url:"-"` + IsExternalModificationAllowed *bool `json:"is_external_modification_allowed,omitempty" url:"-"` + Force *bool `json:"force,omitempty" url:"-"` } diff --git a/accesscodes/unmanaged/client.go b/accesscodes/unmanaged/client.go index cde230b..250e2f1 100644 --- a/accesscodes/unmanaged/client.go +++ b/accesscodes/unmanaged/client.go @@ -3,21 +3,18 @@ package unmanaged import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" accesscodes "github.com/seamapi/go/accesscodes" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) ConvertToManaged( opts ...option.RequestOption, ) (*accesscodes.UnmanagedConvertToManagedResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/unmanaged/convert_to_managed" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/unmanaged/convert_to_managed" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *accesscodes.UnmanagedConvertToManagedResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*accesscodes.UnmanagedDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/unmanaged/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/unmanaged/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *accesscodes.UnmanagedDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.UnmanagedAccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/unmanaged/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/unmanaged/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *accesscodes.UnmanagedGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.UnmanagedAccessCode, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/unmanaged/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/unmanaged/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *accesscodes.UnmanagedListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -293,56 +242,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*accesscodes.UnmanagedUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "access_codes/unmanaged/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/access_codes/unmanaged/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *accesscodes.UnmanagedUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/access_groups.go b/acs/access_groups.go index 41d920c..2a75de9 100644 --- a/acs/access_groups.go +++ b/acs/access_groups.go @@ -6,36 +6,48 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type AccessGroupsAddUserRequest struct { - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsAccessGroupId string `json:"acs_access_group_id" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` } type AccessGroupsGetRequest struct { - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` + AcsAccessGroupId string `json:"acs_access_group_id" url:"-"` } type AccessGroupsListRequest struct { - AcsSystemId *string `json:"acs_system_id,omitempty" url:"acs_system_id,omitempty"` - AcsUserId *string `json:"acs_user_id,omitempty" url:"acs_user_id,omitempty"` + AcsSystemId *string `json:"acs_system_id,omitempty" url:"-"` + AcsUserId *string `json:"acs_user_id,omitempty" url:"-"` } type AccessGroupsListUsersRequest struct { - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` + AcsAccessGroupId string `json:"acs_access_group_id" url:"-"` } type AccessGroupsRemoveUserRequest struct { - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsAccessGroupId string `json:"acs_access_group_id" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` } type AccessGroupsAddUserResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessGroupsAddUserResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessGroupsAddUserResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessGroupsAddUserResponse) UnmarshalJSON(data []byte) error { @@ -45,17 +57,22 @@ func (a *AccessGroupsAddUserResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessGroupsAddUserResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessGroupsAddUserResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -65,7 +82,26 @@ type AccessGroupsGetResponse struct { AcsAccessGroup *seamapigo.AcsAccessGroup `json:"acs_access_group,omitempty" url:"acs_access_group,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessGroupsGetResponse) GetAcsAccessGroup() *seamapigo.AcsAccessGroup { + if a == nil { + return nil + } + return a.AcsAccessGroup +} + +func (a *AccessGroupsGetResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessGroupsGetResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessGroupsGetResponse) UnmarshalJSON(data []byte) error { @@ -75,17 +111,22 @@ func (a *AccessGroupsGetResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessGroupsGetResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessGroupsGetResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -95,7 +136,26 @@ type AccessGroupsListResponse struct { AcsAccessGroups []*seamapigo.AcsAccessGroup `json:"acs_access_groups,omitempty" url:"acs_access_groups,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessGroupsListResponse) GetAcsAccessGroups() []*seamapigo.AcsAccessGroup { + if a == nil { + return nil + } + return a.AcsAccessGroups +} + +func (a *AccessGroupsListResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessGroupsListResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessGroupsListResponse) UnmarshalJSON(data []byte) error { @@ -105,17 +165,22 @@ func (a *AccessGroupsListResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessGroupsListResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessGroupsListResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -125,7 +190,26 @@ type AccessGroupsListUsersResponse struct { AcsUsers []*seamapigo.AcsUser `json:"acs_users,omitempty" url:"acs_users,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessGroupsListUsersResponse) GetAcsUsers() []*seamapigo.AcsUser { + if a == nil { + return nil + } + return a.AcsUsers +} + +func (a *AccessGroupsListUsersResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessGroupsListUsersResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessGroupsListUsersResponse) UnmarshalJSON(data []byte) error { @@ -135,17 +219,22 @@ func (a *AccessGroupsListUsersResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessGroupsListUsersResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessGroupsListUsersResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -154,7 +243,19 @@ func (a *AccessGroupsListUsersResponse) String() string { type AccessGroupsRemoveUserResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AccessGroupsRemoveUserResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *AccessGroupsRemoveUserResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AccessGroupsRemoveUserResponse) UnmarshalJSON(data []byte) error { @@ -164,17 +265,22 @@ func (a *AccessGroupsRemoveUserResponse) UnmarshalJSON(data []byte) error { return err } *a = AccessGroupsRemoveUserResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AccessGroupsRemoveUserResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) diff --git a/acs/accessgroups/client.go b/acs/accessgroups/client.go index 23ea9bc..b89ef06 100644 --- a/acs/accessgroups/client.go +++ b/acs/accessgroups/client.go @@ -3,21 +3,18 @@ package accessgroups import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) AddUser( opts ...option.RequestOption, ) (*acs.AccessGroupsAddUserResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/access_groups/add_user" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/access_groups/add_user" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.AccessGroupsAddUserResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.AcsAccessGroup, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/access_groups/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/access_groups/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.AccessGroupsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AcsAccessGroup, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/access_groups/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/access_groups/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.AccessGroupsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) ListUsers( opts ...option.RequestOption, ) ([]*seamapigo.AcsUser, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/access_groups/list_users" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/access_groups/list_users" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.AccessGroupsListUsersResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -293,56 +242,44 @@ func (c *Client) RemoveUser( opts ...option.RequestOption, ) (*acs.AccessGroupsRemoveUserResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/access_groups/remove_user" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/access_groups/remove_user" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.AccessGroupsRemoveUserResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/client/client.go b/acs/client/client.go index 688be3b..5e1978c 100644 --- a/acs/client/client.go +++ b/acs/client/client.go @@ -11,13 +11,14 @@ import ( systems "github.com/seamapi/go/acs/systems" users "github.com/seamapi/go/acs/users" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header AccessGroups *accessgroups.Client @@ -33,8 +34,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, diff --git a/acs/credential_pools.go b/acs/credential_pools.go index f6619f2..7cb0311 100644 --- a/acs/credential_pools.go +++ b/acs/credential_pools.go @@ -6,18 +6,37 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type CredentialPoolsListRequest struct { - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + AcsSystemId string `json:"acs_system_id" url:"-"` } type CredentialPoolsListResponse struct { AcsCredentialPools []*seamapigo.AcsCredentialPool `json:"acs_credential_pools,omitempty" url:"acs_credential_pools,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialPoolsListResponse) GetAcsCredentialPools() []*seamapigo.AcsCredentialPool { + if c == nil { + return nil + } + return c.AcsCredentialPools +} + +func (c *CredentialPoolsListResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialPoolsListResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialPoolsListResponse) UnmarshalJSON(data []byte) error { @@ -27,17 +46,22 @@ func (c *CredentialPoolsListResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialPoolsListResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialPoolsListResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) diff --git a/acs/credential_provisioning_automations.go b/acs/credential_provisioning_automations.go index bf99bbf..eabcbce 100644 --- a/acs/credential_provisioning_automations.go +++ b/acs/credential_provisioning_automations.go @@ -6,22 +6,41 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type CredentialProvisioningAutomationsLaunchRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - CredentialManagerAcsSystemId string `json:"credential_manager_acs_system_id" url:"credential_manager_acs_system_id"` - AcsCredentialPoolId *string `json:"acs_credential_pool_id,omitempty" url:"acs_credential_pool_id,omitempty"` - CreateCredentialManagerUser *bool `json:"create_credential_manager_user,omitempty" url:"create_credential_manager_user,omitempty"` - CredentialManagerAcsUserId *string `json:"credential_manager_acs_user_id,omitempty" url:"credential_manager_acs_user_id,omitempty"` + UserIdentityId string `json:"user_identity_id" url:"-"` + CredentialManagerAcsSystemId string `json:"credential_manager_acs_system_id" url:"-"` + AcsCredentialPoolId *string `json:"acs_credential_pool_id,omitempty" url:"-"` + CreateCredentialManagerUser *bool `json:"create_credential_manager_user,omitempty" url:"-"` + CredentialManagerAcsUserId *string `json:"credential_manager_acs_user_id,omitempty" url:"-"` } type CredentialProvisioningAutomationsLaunchResponse struct { AcsCredentialProvisioningAutomation *seamapigo.AcsCredentialProvisioningAutomation `json:"acs_credential_provisioning_automation,omitempty" url:"acs_credential_provisioning_automation,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialProvisioningAutomationsLaunchResponse) GetAcsCredentialProvisioningAutomation() *seamapigo.AcsCredentialProvisioningAutomation { + if c == nil { + return nil + } + return c.AcsCredentialProvisioningAutomation +} + +func (c *CredentialProvisioningAutomationsLaunchResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialProvisioningAutomationsLaunchResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialProvisioningAutomationsLaunchResponse) UnmarshalJSON(data []byte) error { @@ -31,17 +50,22 @@ func (c *CredentialProvisioningAutomationsLaunchResponse) UnmarshalJSON(data []b return err } *c = CredentialProvisioningAutomationsLaunchResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialProvisioningAutomationsLaunchResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) diff --git a/acs/credentialpools/client.go b/acs/credentialpools/client.go index 0cf6735..596886f 100644 --- a/acs/credentialpools/client.go +++ b/acs/credentialpools/client.go @@ -3,21 +3,18 @@ package credentialpools import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AcsCredentialPool, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credential_pools/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credential_pools/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialPoolsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/credentialprovisioningautomations/client.go b/acs/credentialprovisioningautomations/client.go index 2fda474..90bc9d8 100644 --- a/acs/credentialprovisioningautomations/client.go +++ b/acs/credentialprovisioningautomations/client.go @@ -3,21 +3,18 @@ package credentialprovisioningautomations import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Launch( opts ...option.RequestOption, ) (*seamapigo.AcsCredentialProvisioningAutomation, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credential_provisioning_automations/launch" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credential_provisioning_automations/launch" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialProvisioningAutomationsLaunchResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/credentials.go b/acs/credentials.go index d19c6aa..2cbf454 100644 --- a/acs/credentials.go +++ b/acs/credentials.go @@ -6,25 +6,25 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type CredentialsAssignRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` + AcsUserId string `json:"acs_user_id" url:"-"` + AcsCredentialId string `json:"acs_credential_id" url:"-"` } type CredentialsCreateRequest struct { - CredentialManagerAcsSystemId *string `json:"credential_manager_acs_system_id,omitempty" url:"credential_manager_acs_system_id,omitempty"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - AccessMethod CredentialsCreateRequestAccessMethod `json:"access_method,omitempty" url:"access_method,omitempty"` - Code *string `json:"code,omitempty" url:"code,omitempty"` - IsMultiPhoneSyncCredential *bool `json:"is_multi_phone_sync_credential,omitempty" url:"is_multi_phone_sync_credential,omitempty"` - AllowedAcsEntranceIds []string `json:"allowed_acs_entrance_ids,omitempty" url:"allowed_acs_entrance_ids,omitempty"` - VisionlineMetadata *CredentialsCreateRequestVisionlineMetadata `json:"visionline_metadata,omitempty" url:"visionline_metadata,omitempty"` - StartsAt *time.Time `json:"starts_at,omitempty" url:"starts_at,omitempty"` - EndsAt *time.Time `json:"ends_at,omitempty" url:"ends_at,omitempty"` + CredentialManagerAcsSystemId *string `json:"credential_manager_acs_system_id,omitempty" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` + AccessMethod CredentialsCreateRequestAccessMethod `json:"access_method" url:"-"` + Code *string `json:"code,omitempty" url:"-"` + IsMultiPhoneSyncCredential *bool `json:"is_multi_phone_sync_credential,omitempty" url:"-"` + AllowedAcsEntranceIds []string `json:"allowed_acs_entrance_ids,omitempty" url:"-"` + VisionlineMetadata *CredentialsCreateRequestVisionlineMetadata `json:"visionline_metadata,omitempty" url:"-"` + StartsAt *time.Time `json:"starts_at,omitempty" url:"-"` + EndsAt *time.Time `json:"ends_at,omitempty" url:"-"` } func (c *CredentialsCreateRequest) UnmarshalJSON(data []byte) error { @@ -41,36 +41,59 @@ func (c *CredentialsCreateRequest) MarshalJSON() ([]byte, error) { type embed CredentialsCreateRequest var marshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at,omitempty"` - EndsAt *core.DateTime `json:"ends_at,omitempty"` + StartsAt *internal.DateTime `json:"starts_at,omitempty"` + EndsAt *internal.DateTime `json:"ends_at,omitempty"` }{ embed: embed(*c), - StartsAt: core.NewOptionalDateTime(c.StartsAt), - EndsAt: core.NewOptionalDateTime(c.EndsAt), + StartsAt: internal.NewOptionalDateTime(c.StartsAt), + EndsAt: internal.NewOptionalDateTime(c.EndsAt), } return json.Marshal(marshaler) } type CredentialsDeleteRequest struct { - AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` + AcsCredentialId string `json:"acs_credential_id" url:"-"` } type CredentialsGetRequest struct { - AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` + AcsCredentialId string `json:"acs_credential_id" url:"-"` } type CredentialsListRequest struct { - AcsUserId *string `json:"acs_user_id,omitempty" url:"acs_user_id,omitempty"` - AcsSystemId *string `json:"acs_system_id,omitempty" url:"acs_system_id,omitempty"` - UserIdentityId *string `json:"user_identity_id,omitempty" url:"user_identity_id,omitempty"` - IsMultiPhoneSyncCredential *bool `json:"is_multi_phone_sync_credential,omitempty" url:"is_multi_phone_sync_credential,omitempty"` + AcsUserId *string `json:"acs_user_id,omitempty" url:"-"` + AcsSystemId *string `json:"acs_system_id,omitempty" url:"-"` + UserIdentityId *string `json:"user_identity_id,omitempty" url:"-"` + CredentialsListRequestIsMultiPhoneSyncCredential *bool `json:"is_multi_phone_sync_credential,omitempty" url:"-"` +} + +type CredentialsListAccessibleEntrancesRequest struct { + AcsCredentialId string `json:"acs_credential_id" url:"-"` } type CredentialsAssignResponse struct { AcsCredential *seamapigo.AcsCredential `json:"acs_credential,omitempty" url:"acs_credential,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsAssignResponse) GetAcsCredential() *seamapigo.AcsCredential { + if c == nil { + return nil + } + return c.AcsCredential +} + +func (c *CredentialsAssignResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsAssignResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsAssignResponse) UnmarshalJSON(data []byte) error { @@ -80,17 +103,22 @@ func (c *CredentialsAssignResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsAssignResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsAssignResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -125,14 +153,58 @@ type CredentialsCreateRequestVisionlineMetadata struct { AssaAbloyCredentialServiceMobileEndpointId *string `json:"assa_abloy_credential_service_mobile_endpoint_id,omitempty" url:"assa_abloy_credential_service_mobile_endpoint_id,omitempty"` CardFormat *CredentialsCreateRequestVisionlineMetadataCardFormat `json:"card_format,omitempty" url:"card_format,omitempty"` CardFunctionType *CredentialsCreateRequestVisionlineMetadataCardFunctionType `json:"card_function_type,omitempty" url:"card_function_type,omitempty"` - // --- - // deprecated: use override. - // --- - IsOverrideKey *bool `json:"is_override_key,omitempty" url:"is_override_key,omitempty"` - Override *bool `json:"override,omitempty" url:"override,omitempty"` - JoinerAcsCredentialIds []string `json:"joiner_acs_credential_ids,omitempty" url:"joiner_acs_credential_ids,omitempty"` + IsOverrideKey *bool `json:"is_override_key,omitempty" url:"is_override_key,omitempty"` + Override *bool `json:"override,omitempty" url:"override,omitempty"` + JoinerAcsCredentialIds []string `json:"joiner_acs_credential_ids,omitempty" url:"joiner_acs_credential_ids,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsCreateRequestVisionlineMetadata) GetAssaAbloyCredentialServiceMobileEndpointId() *string { + if c == nil { + return nil + } + return c.AssaAbloyCredentialServiceMobileEndpointId +} + +func (c *CredentialsCreateRequestVisionlineMetadata) GetCardFormat() *CredentialsCreateRequestVisionlineMetadataCardFormat { + if c == nil { + return nil + } + return c.CardFormat +} - _rawJSON json.RawMessage +func (c *CredentialsCreateRequestVisionlineMetadata) GetCardFunctionType() *CredentialsCreateRequestVisionlineMetadataCardFunctionType { + if c == nil { + return nil + } + return c.CardFunctionType +} + +func (c *CredentialsCreateRequestVisionlineMetadata) GetIsOverrideKey() *bool { + if c == nil { + return nil + } + return c.IsOverrideKey +} + +func (c *CredentialsCreateRequestVisionlineMetadata) GetOverride() *bool { + if c == nil { + return nil + } + return c.Override +} + +func (c *CredentialsCreateRequestVisionlineMetadata) GetJoinerAcsCredentialIds() []string { + if c == nil { + return nil + } + return c.JoinerAcsCredentialIds +} + +func (c *CredentialsCreateRequestVisionlineMetadata) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsCreateRequestVisionlineMetadata) UnmarshalJSON(data []byte) error { @@ -142,27 +214,95 @@ func (c *CredentialsCreateRequestVisionlineMetadata) UnmarshalJSON(data []byte) return err } *c = CredentialsCreateRequestVisionlineMetadata(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsCreateRequestVisionlineMetadata) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } +type CredentialsCreateRequestVisionlineMetadataCardFormat string + +const ( + CredentialsCreateRequestVisionlineMetadataCardFormatTlCode CredentialsCreateRequestVisionlineMetadataCardFormat = "TLCode" + CredentialsCreateRequestVisionlineMetadataCardFormatRfid48 CredentialsCreateRequestVisionlineMetadataCardFormat = "rfid48" +) + +func NewCredentialsCreateRequestVisionlineMetadataCardFormatFromString(s string) (CredentialsCreateRequestVisionlineMetadataCardFormat, error) { + switch s { + case "TLCode": + return CredentialsCreateRequestVisionlineMetadataCardFormatTlCode, nil + case "rfid48": + return CredentialsCreateRequestVisionlineMetadataCardFormatRfid48, nil + } + var t CredentialsCreateRequestVisionlineMetadataCardFormat + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (c CredentialsCreateRequestVisionlineMetadataCardFormat) Ptr() *CredentialsCreateRequestVisionlineMetadataCardFormat { + return &c +} + +type CredentialsCreateRequestVisionlineMetadataCardFunctionType string + +const ( + CredentialsCreateRequestVisionlineMetadataCardFunctionTypeGuest CredentialsCreateRequestVisionlineMetadataCardFunctionType = "guest" + CredentialsCreateRequestVisionlineMetadataCardFunctionTypeStaff CredentialsCreateRequestVisionlineMetadataCardFunctionType = "staff" +) + +func NewCredentialsCreateRequestVisionlineMetadataCardFunctionTypeFromString(s string) (CredentialsCreateRequestVisionlineMetadataCardFunctionType, error) { + switch s { + case "guest": + return CredentialsCreateRequestVisionlineMetadataCardFunctionTypeGuest, nil + case "staff": + return CredentialsCreateRequestVisionlineMetadataCardFunctionTypeStaff, nil + } + var t CredentialsCreateRequestVisionlineMetadataCardFunctionType + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (c CredentialsCreateRequestVisionlineMetadataCardFunctionType) Ptr() *CredentialsCreateRequestVisionlineMetadataCardFunctionType { + return &c +} + type CredentialsCreateResponse struct { AcsCredential *seamapigo.AcsCredential `json:"acs_credential,omitempty" url:"acs_credential,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsCreateResponse) GetAcsCredential() *seamapigo.AcsCredential { + if c == nil { + return nil + } + return c.AcsCredential +} + +func (c *CredentialsCreateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsCreateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsCreateResponse) UnmarshalJSON(data []byte) error { @@ -172,17 +312,22 @@ func (c *CredentialsCreateResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsCreateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsCreateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -191,7 +336,19 @@ func (c *CredentialsCreateResponse) String() string { type CredentialsDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsDeleteResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsDeleteResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsDeleteResponse) UnmarshalJSON(data []byte) error { @@ -201,17 +358,22 @@ func (c *CredentialsDeleteResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsDeleteResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsDeleteResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -221,7 +383,26 @@ type CredentialsGetResponse struct { AcsCredential *seamapigo.AcsCredential `json:"acs_credential,omitempty" url:"acs_credential,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsGetResponse) GetAcsCredential() *seamapigo.AcsCredential { + if c == nil { + return nil + } + return c.AcsCredential +} + +func (c *CredentialsGetResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsGetResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsGetResponse) UnmarshalJSON(data []byte) error { @@ -231,17 +412,76 @@ func (c *CredentialsGetResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsGetResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsGetResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type CredentialsListAccessibleEntrancesResponse struct { + AcsEntrances []*seamapigo.AcsEntrance `json:"acs_entrances,omitempty" url:"acs_entrances,omitempty"` + Ok bool `json:"ok" url:"ok"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsListAccessibleEntrancesResponse) GetAcsEntrances() []*seamapigo.AcsEntrance { + if c == nil { + return nil + } + return c.AcsEntrances +} + +func (c *CredentialsListAccessibleEntrancesResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsListAccessibleEntrancesResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *CredentialsListAccessibleEntrancesResponse) UnmarshalJSON(data []byte) error { + type unmarshaler CredentialsListAccessibleEntrancesResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = CredentialsListAccessibleEntrancesResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *CredentialsListAccessibleEntrancesResponse) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -251,7 +491,26 @@ type CredentialsListResponse struct { AcsCredentials []*seamapigo.AcsCredential `json:"acs_credentials,omitempty" url:"acs_credentials,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsListResponse) GetAcsCredentials() []*seamapigo.AcsCredential { + if c == nil { + return nil + } + return c.AcsCredentials +} + +func (c *CredentialsListResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsListResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsListResponse) UnmarshalJSON(data []byte) error { @@ -261,17 +520,22 @@ func (c *CredentialsListResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsListResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsListResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -281,7 +545,26 @@ type CredentialsUnassignResponse struct { AcsCredential *seamapigo.AcsCredential `json:"acs_credential,omitempty" url:"acs_credential,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsUnassignResponse) GetAcsCredential() *seamapigo.AcsCredential { + if c == nil { + return nil + } + return c.AcsCredential +} + +func (c *CredentialsUnassignResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsUnassignResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsUnassignResponse) UnmarshalJSON(data []byte) error { @@ -291,17 +574,22 @@ func (c *CredentialsUnassignResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsUnassignResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsUnassignResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -311,7 +599,26 @@ type CredentialsUpdateResponse struct { AcsCredential *seamapigo.AcsCredential `json:"acs_credential,omitempty" url:"acs_credential,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *CredentialsUpdateResponse) GetAcsCredential() *seamapigo.AcsCredential { + if c == nil { + return nil + } + return c.AcsCredential +} + +func (c *CredentialsUpdateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *CredentialsUpdateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *CredentialsUpdateResponse) UnmarshalJSON(data []byte) error { @@ -321,28 +628,56 @@ func (c *CredentialsUpdateResponse) UnmarshalJSON(data []byte) error { return err } *c = CredentialsUpdateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *CredentialsUpdateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type CredentialsUnassignRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` + AcsUserId string `json:"acs_user_id" url:"-"` + AcsCredentialId string `json:"acs_credential_id" url:"-"` } type CredentialsUpdateRequest struct { - AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` - Code string `json:"code" url:"code"` + AcsCredentialId string `json:"acs_credential_id" url:"-"` + Code *string `json:"code,omitempty" url:"-"` + EndsAt *time.Time `json:"ends_at,omitempty" url:"-"` +} + +func (c *CredentialsUpdateRequest) UnmarshalJSON(data []byte) error { + type unmarshaler CredentialsUpdateRequest + var body unmarshaler + if err := json.Unmarshal(data, &body); err != nil { + return err + } + *c = CredentialsUpdateRequest(body) + return nil +} + +func (c *CredentialsUpdateRequest) MarshalJSON() ([]byte, error) { + type embed CredentialsUpdateRequest + var marshaler = struct { + embed + EndsAt *internal.DateTime `json:"ends_at,omitempty"` + }{ + embed: embed(*c), + EndsAt: internal.NewOptionalDateTime(c.EndsAt), + } + return json.Marshal(marshaler) } diff --git a/acs/credentials/client.go b/acs/credentials/client.go index ebf05f8..c032361 100644 --- a/acs/credentials/client.go +++ b/acs/credentials/client.go @@ -3,21 +3,18 @@ package credentials import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Assign( opts ...option.RequestOption, ) (*acs.CredentialsAssignResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credentials/assign" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/assign" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialsAssignResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.AcsCredential, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credentials/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialsCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*acs.CredentialsDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credentials/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialsDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.AcsCredential, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credentials/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -293,61 +242,100 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AcsCredential, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, + } + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, + } + }, } - endpointURL := baseURL + "/" + "acs/credentials/list" - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + var response *acs.CredentialsListResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), + }, + ); err != nil { + return nil, err + } + return response.AcsCredentials, nil +} - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError +func (c *Client) ListAccessibleEntrances( + ctx context.Context, + request *acs.CredentialsListAccessibleEntrancesRequest, + opts ...option.RequestOption, +) ([]*seamapigo.AcsEntrance, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/list_accessible_entrances" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } - var response *acs.CredentialsListResponse + var response *acs.CredentialsListAccessibleEntrancesResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err } - return response.AcsCredentials, nil + return response.AcsEntrances, nil } func (c *Client) Unassign( @@ -356,56 +344,44 @@ func (c *Client) Unassign( opts ...option.RequestOption, ) (*acs.CredentialsUnassignResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credentials/unassign" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/unassign" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialsUnassignResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -419,56 +395,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*acs.CredentialsUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/credentials/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/credentials/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.CredentialsUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/entrances.go b/acs/entrances.go index 573475e..0b56873 100644 --- a/acs/entrances.go +++ b/acs/entrances.go @@ -6,33 +6,52 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type EntrancesGetRequest struct { - AcsEntranceId string `json:"acs_entrance_id" url:"acs_entrance_id"` + AcsEntranceId string `json:"acs_entrance_id" url:"-"` } type EntrancesGrantAccessRequest struct { - AcsEntranceId string `json:"acs_entrance_id" url:"acs_entrance_id"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsEntranceId string `json:"acs_entrance_id" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` } type EntrancesListRequest struct { - AcsSystemId *string `json:"acs_system_id,omitempty" url:"acs_system_id,omitempty"` - AcsCredentialId *string `json:"acs_credential_id,omitempty" url:"acs_credential_id,omitempty"` + AcsSystemId *string `json:"acs_system_id,omitempty" url:"-"` + AcsCredentialId *string `json:"acs_credential_id,omitempty" url:"-"` } type EntrancesListCredentialsWithAccessRequest struct { - AcsEntranceId string `json:"acs_entrance_id" url:"acs_entrance_id"` - IncludeIf []string `json:"include_if,omitempty" url:"include_if,omitempty"` + AcsEntranceId string `json:"acs_entrance_id" url:"-"` + IncludeIf []string `json:"include_if,omitempty" url:"-"` } type EntrancesGetResponse struct { AcsEntrance *seamapigo.AcsEntrance `json:"acs_entrance,omitempty" url:"acs_entrance,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EntrancesGetResponse) GetAcsEntrance() *seamapigo.AcsEntrance { + if e == nil { + return nil + } + return e.AcsEntrance +} + +func (e *EntrancesGetResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EntrancesGetResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EntrancesGetResponse) UnmarshalJSON(data []byte) error { @@ -42,17 +61,22 @@ func (e *EntrancesGetResponse) UnmarshalJSON(data []byte) error { return err } *e = EntrancesGetResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EntrancesGetResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) @@ -61,7 +85,19 @@ func (e *EntrancesGetResponse) String() string { type EntrancesGrantAccessResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EntrancesGrantAccessResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EntrancesGrantAccessResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EntrancesGrantAccessResponse) UnmarshalJSON(data []byte) error { @@ -71,17 +107,22 @@ func (e *EntrancesGrantAccessResponse) UnmarshalJSON(data []byte) error { return err } *e = EntrancesGrantAccessResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EntrancesGrantAccessResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) @@ -91,7 +132,26 @@ type EntrancesListCredentialsWithAccessResponse struct { AcsCredentials []*seamapigo.AcsCredential `json:"acs_credentials,omitempty" url:"acs_credentials,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EntrancesListCredentialsWithAccessResponse) GetAcsCredentials() []*seamapigo.AcsCredential { + if e == nil { + return nil + } + return e.AcsCredentials +} + +func (e *EntrancesListCredentialsWithAccessResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EntrancesListCredentialsWithAccessResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EntrancesListCredentialsWithAccessResponse) UnmarshalJSON(data []byte) error { @@ -101,17 +161,22 @@ func (e *EntrancesListCredentialsWithAccessResponse) UnmarshalJSON(data []byte) return err } *e = EntrancesListCredentialsWithAccessResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EntrancesListCredentialsWithAccessResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) @@ -121,7 +186,26 @@ type EntrancesListResponse struct { AcsEntrances []*seamapigo.AcsEntrance `json:"acs_entrances,omitempty" url:"acs_entrances,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EntrancesListResponse) GetAcsEntrances() []*seamapigo.AcsEntrance { + if e == nil { + return nil + } + return e.AcsEntrances +} + +func (e *EntrancesListResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EntrancesListResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EntrancesListResponse) UnmarshalJSON(data []byte) error { @@ -131,17 +215,22 @@ func (e *EntrancesListResponse) UnmarshalJSON(data []byte) error { return err } *e = EntrancesListResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EntrancesListResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) diff --git a/acs/entrances/client.go b/acs/entrances/client.go index e396201..e19df9c 100644 --- a/acs/entrances/client.go +++ b/acs/entrances/client.go @@ -3,21 +3,18 @@ package entrances import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.AcsEntrance, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/entrances/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/entrances/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.EntrancesGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) GrantAccess( opts ...option.RequestOption, ) (*acs.EntrancesGrantAccessResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/entrances/grant_access" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/entrances/grant_access" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.EntrancesGrantAccessResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AcsEntrance, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/entrances/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/entrances/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.EntrancesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) ListCredentialsWithAccess( opts ...option.RequestOption, ) ([]*seamapigo.AcsCredential, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/entrances/list_credentials_with_access" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/entrances/list_credentials_with_access" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.EntrancesListCredentialsWithAccessResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/systems.go b/acs/systems.go index 6cda956..c52cc1c 100644 --- a/acs/systems.go +++ b/acs/systems.go @@ -6,22 +6,45 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type SystemsGetRequest struct { - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + AcsSystemId string `json:"acs_system_id" url:"-"` } type SystemsListRequest struct { - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"-"` +} + +type SystemsListCompatibleCredentialManagerAcsSystemsRequest struct { + AcsSystemId string `json:"acs_system_id" url:"-"` } type SystemsGetResponse struct { AcsSystem *seamapigo.AcsSystem `json:"acs_system,omitempty" url:"acs_system,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SystemsGetResponse) GetAcsSystem() *seamapigo.AcsSystem { + if s == nil { + return nil + } + return s.AcsSystem +} + +func (s *SystemsGetResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SystemsGetResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SystemsGetResponse) UnmarshalJSON(data []byte) error { @@ -31,17 +54,76 @@ func (s *SystemsGetResponse) UnmarshalJSON(data []byte) error { return err } *s = SystemsGetResponse(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SystemsGetResponse) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(s); err == nil { + return value + } + return fmt.Sprintf("%#v", s) +} + +type SystemsListCompatibleCredentialManagerAcsSystemsResponse struct { + AcsSystems []*seamapigo.AcsSystem `json:"acs_systems,omitempty" url:"acs_systems,omitempty"` + Ok bool `json:"ok" url:"ok"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SystemsListCompatibleCredentialManagerAcsSystemsResponse) GetAcsSystems() []*seamapigo.AcsSystem { + if s == nil { + return nil + } + return s.AcsSystems +} + +func (s *SystemsListCompatibleCredentialManagerAcsSystemsResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SystemsListCompatibleCredentialManagerAcsSystemsResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties +} + +func (s *SystemsListCompatibleCredentialManagerAcsSystemsResponse) UnmarshalJSON(data []byte) error { + type unmarshaler SystemsListCompatibleCredentialManagerAcsSystemsResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *s = SystemsListCompatibleCredentialManagerAcsSystemsResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) + return nil +} + +func (s *SystemsListCompatibleCredentialManagerAcsSystemsResponse) String() string { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) @@ -51,7 +133,26 @@ type SystemsListResponse struct { AcsSystems []*seamapigo.AcsSystem `json:"acs_systems,omitempty" url:"acs_systems,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SystemsListResponse) GetAcsSystems() []*seamapigo.AcsSystem { + if s == nil { + return nil + } + return s.AcsSystems +} + +func (s *SystemsListResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SystemsListResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SystemsListResponse) UnmarshalJSON(data []byte) error { @@ -61,17 +162,22 @@ func (s *SystemsListResponse) UnmarshalJSON(data []byte) error { return err } *s = SystemsListResponse(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SystemsListResponse) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) diff --git a/acs/systems/client.go b/acs/systems/client.go index 27aa397..1305467 100644 --- a/acs/systems/client.go +++ b/acs/systems/client.go @@ -3,21 +3,18 @@ package systems import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.AcsSystem, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/systems/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/systems/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.SystemsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,95 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AcsSystem, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/systems/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, + } + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, + } + }, } - endpointURL := baseURL + "/" + "acs/systems/list" - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + var response *acs.SystemsListResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), + }, + ); err != nil { + return nil, err + } + return response.AcsSystems, nil +} - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError +func (c *Client) ListCompatibleCredentialManagerAcsSystems( + ctx context.Context, + request *acs.SystemsListCompatibleCredentialManagerAcsSystemsRequest, + opts ...option.RequestOption, +) ([]*seamapigo.AcsSystem, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/systems/list_compatible_credential_manager_acs_systems" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } - var response *acs.SystemsListResponse + var response *acs.SystemsListCompatibleCredentialManagerAcsSystemsResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/acs/types.go b/acs/types.go deleted file mode 100644 index 3be346e..0000000 --- a/acs/types.go +++ /dev/null @@ -1,51 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -package acs - -import ( - fmt "fmt" -) - -type CredentialsCreateRequestVisionlineMetadataCardFormat string - -const ( - CredentialsCreateRequestVisionlineMetadataCardFormatTlCode CredentialsCreateRequestVisionlineMetadataCardFormat = "TLCode" - CredentialsCreateRequestVisionlineMetadataCardFormatRfid48 CredentialsCreateRequestVisionlineMetadataCardFormat = "rfid48" -) - -func NewCredentialsCreateRequestVisionlineMetadataCardFormatFromString(s string) (CredentialsCreateRequestVisionlineMetadataCardFormat, error) { - switch s { - case "TLCode": - return CredentialsCreateRequestVisionlineMetadataCardFormatTlCode, nil - case "rfid48": - return CredentialsCreateRequestVisionlineMetadataCardFormatRfid48, nil - } - var t CredentialsCreateRequestVisionlineMetadataCardFormat - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (c CredentialsCreateRequestVisionlineMetadataCardFormat) Ptr() *CredentialsCreateRequestVisionlineMetadataCardFormat { - return &c -} - -type CredentialsCreateRequestVisionlineMetadataCardFunctionType string - -const ( - CredentialsCreateRequestVisionlineMetadataCardFunctionTypeGuest CredentialsCreateRequestVisionlineMetadataCardFunctionType = "guest" - CredentialsCreateRequestVisionlineMetadataCardFunctionTypeStaff CredentialsCreateRequestVisionlineMetadataCardFunctionType = "staff" -) - -func NewCredentialsCreateRequestVisionlineMetadataCardFunctionTypeFromString(s string) (CredentialsCreateRequestVisionlineMetadataCardFunctionType, error) { - switch s { - case "guest": - return CredentialsCreateRequestVisionlineMetadataCardFunctionTypeGuest, nil - case "staff": - return CredentialsCreateRequestVisionlineMetadataCardFunctionTypeStaff, nil - } - var t CredentialsCreateRequestVisionlineMetadataCardFunctionType - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (c CredentialsCreateRequestVisionlineMetadataCardFunctionType) Ptr() *CredentialsCreateRequestVisionlineMetadataCardFunctionType { - return &c -} diff --git a/acs/users.go b/acs/users.go index fef6779..7c77d0d 100644 --- a/acs/users.go +++ b/acs/users.go @@ -6,65 +6,74 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type UsersAddToAccessGroupRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` + AcsUserId string `json:"acs_user_id" url:"-"` + AcsAccessGroupId string `json:"acs_access_group_id" url:"-"` } type UsersCreateRequest struct { - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` - AcsAccessGroupIds []string `json:"acs_access_group_ids,omitempty" url:"acs_access_group_ids,omitempty"` - UserIdentityId *string `json:"user_identity_id,omitempty" url:"user_identity_id,omitempty"` - AccessSchedule *UsersCreateRequestAccessSchedule `json:"access_schedule,omitempty" url:"access_schedule,omitempty"` - FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` - // --- - // deprecated: use email_address. - // --- - Email *string `json:"email,omitempty" url:"email,omitempty"` - PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` - EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` + AcsSystemId string `json:"acs_system_id" url:"-"` + AcsAccessGroupIds []string `json:"acs_access_group_ids,omitempty" url:"-"` + UserIdentityId *string `json:"user_identity_id,omitempty" url:"-"` + AccessSchedule *UsersCreateRequestAccessSchedule `json:"access_schedule,omitempty" url:"-"` + FullName *string `json:"full_name,omitempty" url:"-"` + Email *string `json:"email,omitempty" url:"-"` + PhoneNumber *string `json:"phone_number,omitempty" url:"-"` + EmailAddress *string `json:"email_address,omitempty" url:"-"` } type UsersDeleteRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UsersGetRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UsersListRequest struct { - UserIdentityId *string `json:"user_identity_id,omitempty" url:"user_identity_id,omitempty"` - UserIdentityPhoneNumber *string `json:"user_identity_phone_number,omitempty" url:"user_identity_phone_number,omitempty"` - UserIdentityEmailAddress *string `json:"user_identity_email_address,omitempty" url:"user_identity_email_address,omitempty"` - AcsSystemId *string `json:"acs_system_id,omitempty" url:"acs_system_id,omitempty"` + UserIdentityId *string `json:"user_identity_id,omitempty" url:"-"` + UserIdentityPhoneNumber *string `json:"user_identity_phone_number,omitempty" url:"-"` + UserIdentityEmailAddress *string `json:"user_identity_email_address,omitempty" url:"-"` + AcsSystemId *string `json:"acs_system_id,omitempty" url:"-"` } type UsersListAccessibleEntrancesRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UsersRemoveFromAccessGroupRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` + AcsUserId string `json:"acs_user_id" url:"-"` + AcsAccessGroupId string `json:"acs_access_group_id" url:"-"` } type UsersRevokeAccessToAllEntrancesRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UsersSuspendRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UsersAddToAccessGroupResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersAddToAccessGroupResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersAddToAccessGroupResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersAddToAccessGroupResponse) UnmarshalJSON(data []byte) error { @@ -74,17 +83,22 @@ func (u *UsersAddToAccessGroupResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersAddToAccessGroupResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersAddToAccessGroupResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -94,15 +108,34 @@ type UsersCreateRequestAccessSchedule struct { StartsAt time.Time `json:"starts_at" url:"starts_at"` EndsAt time.Time `json:"ends_at" url:"ends_at"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersCreateRequestAccessSchedule) GetStartsAt() time.Time { + if u == nil { + return time.Time{} + } + return u.StartsAt +} + +func (u *UsersCreateRequestAccessSchedule) GetEndsAt() time.Time { + if u == nil { + return time.Time{} + } + return u.EndsAt +} + +func (u *UsersCreateRequestAccessSchedule) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersCreateRequestAccessSchedule) UnmarshalJSON(data []byte) error { type embed UsersCreateRequestAccessSchedule var unmarshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at"` - EndsAt *core.DateTime `json:"ends_at"` + StartsAt *internal.DateTime `json:"starts_at"` + EndsAt *internal.DateTime `json:"ends_at"` }{ embed: embed(*u), } @@ -112,7 +145,12 @@ func (u *UsersCreateRequestAccessSchedule) UnmarshalJSON(data []byte) error { *u = UsersCreateRequestAccessSchedule(unmarshaler.embed) u.StartsAt = unmarshaler.StartsAt.Time() u.EndsAt = unmarshaler.EndsAt.Time() - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } @@ -120,23 +158,23 @@ func (u *UsersCreateRequestAccessSchedule) MarshalJSON() ([]byte, error) { type embed UsersCreateRequestAccessSchedule var marshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at"` - EndsAt *core.DateTime `json:"ends_at"` + StartsAt *internal.DateTime `json:"starts_at"` + EndsAt *internal.DateTime `json:"ends_at"` }{ embed: embed(*u), - StartsAt: core.NewDateTime(u.StartsAt), - EndsAt: core.NewDateTime(u.EndsAt), + StartsAt: internal.NewDateTime(u.StartsAt), + EndsAt: internal.NewDateTime(u.EndsAt), } return json.Marshal(marshaler) } func (u *UsersCreateRequestAccessSchedule) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -146,7 +184,26 @@ type UsersCreateResponse struct { AcsUser *seamapigo.AcsUser `json:"acs_user,omitempty" url:"acs_user,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersCreateResponse) GetAcsUser() *seamapigo.AcsUser { + if u == nil { + return nil + } + return u.AcsUser +} + +func (u *UsersCreateResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersCreateResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersCreateResponse) UnmarshalJSON(data []byte) error { @@ -156,17 +213,22 @@ func (u *UsersCreateResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersCreateResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersCreateResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -175,7 +237,19 @@ func (u *UsersCreateResponse) String() string { type UsersDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersDeleteResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersDeleteResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersDeleteResponse) UnmarshalJSON(data []byte) error { @@ -185,17 +259,22 @@ func (u *UsersDeleteResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersDeleteResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersDeleteResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -205,7 +284,26 @@ type UsersGetResponse struct { AcsUser *seamapigo.AcsUser `json:"acs_user,omitempty" url:"acs_user,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersGetResponse) GetAcsUser() *seamapigo.AcsUser { + if u == nil { + return nil + } + return u.AcsUser +} + +func (u *UsersGetResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersGetResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersGetResponse) UnmarshalJSON(data []byte) error { @@ -215,17 +313,22 @@ func (u *UsersGetResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersGetResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersGetResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -235,7 +338,26 @@ type UsersListAccessibleEntrancesResponse struct { AcsEntrances []*seamapigo.AcsEntrance `json:"acs_entrances,omitempty" url:"acs_entrances,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersListAccessibleEntrancesResponse) GetAcsEntrances() []*seamapigo.AcsEntrance { + if u == nil { + return nil + } + return u.AcsEntrances +} + +func (u *UsersListAccessibleEntrancesResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersListAccessibleEntrancesResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersListAccessibleEntrancesResponse) UnmarshalJSON(data []byte) error { @@ -245,17 +367,22 @@ func (u *UsersListAccessibleEntrancesResponse) UnmarshalJSON(data []byte) error return err } *u = UsersListAccessibleEntrancesResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersListAccessibleEntrancesResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -265,7 +392,26 @@ type UsersListResponse struct { AcsUsers []*seamapigo.AcsUser `json:"acs_users,omitempty" url:"acs_users,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersListResponse) GetAcsUsers() []*seamapigo.AcsUser { + if u == nil { + return nil + } + return u.AcsUsers +} + +func (u *UsersListResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersListResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersListResponse) UnmarshalJSON(data []byte) error { @@ -275,17 +421,22 @@ func (u *UsersListResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersListResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersListResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -294,7 +445,19 @@ func (u *UsersListResponse) String() string { type UsersRemoveFromAccessGroupResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersRemoveFromAccessGroupResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersRemoveFromAccessGroupResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersRemoveFromAccessGroupResponse) UnmarshalJSON(data []byte) error { @@ -304,17 +467,22 @@ func (u *UsersRemoveFromAccessGroupResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersRemoveFromAccessGroupResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersRemoveFromAccessGroupResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -323,7 +491,19 @@ func (u *UsersRemoveFromAccessGroupResponse) String() string { type UsersRevokeAccessToAllEntrancesResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersRevokeAccessToAllEntrancesResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersRevokeAccessToAllEntrancesResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersRevokeAccessToAllEntrancesResponse) UnmarshalJSON(data []byte) error { @@ -333,17 +513,22 @@ func (u *UsersRevokeAccessToAllEntrancesResponse) UnmarshalJSON(data []byte) err return err } *u = UsersRevokeAccessToAllEntrancesResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersRevokeAccessToAllEntrancesResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -352,7 +537,19 @@ func (u *UsersRevokeAccessToAllEntrancesResponse) String() string { type UsersSuspendResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersSuspendResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersSuspendResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersSuspendResponse) UnmarshalJSON(data []byte) error { @@ -362,17 +559,22 @@ func (u *UsersSuspendResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersSuspendResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersSuspendResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -381,7 +583,19 @@ func (u *UsersSuspendResponse) String() string { type UsersUnsuspendResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersUnsuspendResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersUnsuspendResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersUnsuspendResponse) UnmarshalJSON(data []byte) error { @@ -391,17 +605,22 @@ func (u *UsersUnsuspendResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersUnsuspendResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersUnsuspendResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -411,15 +630,34 @@ type UsersUpdateRequestAccessSchedule struct { StartsAt time.Time `json:"starts_at" url:"starts_at"` EndsAt time.Time `json:"ends_at" url:"ends_at"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersUpdateRequestAccessSchedule) GetStartsAt() time.Time { + if u == nil { + return time.Time{} + } + return u.StartsAt +} + +func (u *UsersUpdateRequestAccessSchedule) GetEndsAt() time.Time { + if u == nil { + return time.Time{} + } + return u.EndsAt +} + +func (u *UsersUpdateRequestAccessSchedule) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersUpdateRequestAccessSchedule) UnmarshalJSON(data []byte) error { type embed UsersUpdateRequestAccessSchedule var unmarshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at"` - EndsAt *core.DateTime `json:"ends_at"` + StartsAt *internal.DateTime `json:"starts_at"` + EndsAt *internal.DateTime `json:"ends_at"` }{ embed: embed(*u), } @@ -429,7 +667,12 @@ func (u *UsersUpdateRequestAccessSchedule) UnmarshalJSON(data []byte) error { *u = UsersUpdateRequestAccessSchedule(unmarshaler.embed) u.StartsAt = unmarshaler.StartsAt.Time() u.EndsAt = unmarshaler.EndsAt.Time() - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } @@ -437,23 +680,23 @@ func (u *UsersUpdateRequestAccessSchedule) MarshalJSON() ([]byte, error) { type embed UsersUpdateRequestAccessSchedule var marshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at"` - EndsAt *core.DateTime `json:"ends_at"` + StartsAt *internal.DateTime `json:"starts_at"` + EndsAt *internal.DateTime `json:"ends_at"` }{ embed: embed(*u), - StartsAt: core.NewDateTime(u.StartsAt), - EndsAt: core.NewDateTime(u.EndsAt), + StartsAt: internal.NewDateTime(u.StartsAt), + EndsAt: internal.NewDateTime(u.EndsAt), } return json.Marshal(marshaler) } func (u *UsersUpdateRequestAccessSchedule) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -462,7 +705,19 @@ func (u *UsersUpdateRequestAccessSchedule) String() string { type UsersUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UsersUpdateResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UsersUpdateResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UsersUpdateResponse) UnmarshalJSON(data []byte) error { @@ -472,35 +727,37 @@ func (u *UsersUpdateResponse) UnmarshalJSON(data []byte) error { return err } *u = UsersUpdateResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UsersUpdateResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UsersUnsuspendRequest struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UsersUpdateRequest struct { - AccessSchedule *UsersUpdateRequestAccessSchedule `json:"access_schedule,omitempty" url:"access_schedule,omitempty"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` - // --- - // deprecated: use email_address. - // --- - Email *string `json:"email,omitempty" url:"email,omitempty"` - PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` - EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` - HidAcsSystemId *string `json:"hid_acs_system_id,omitempty" url:"hid_acs_system_id,omitempty"` + AccessSchedule *UsersUpdateRequestAccessSchedule `json:"access_schedule,omitempty" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` + FullName *string `json:"full_name,omitempty" url:"-"` + Email *string `json:"email,omitempty" url:"-"` + PhoneNumber *string `json:"phone_number,omitempty" url:"-"` + EmailAddress *string `json:"email_address,omitempty" url:"-"` + HidAcsSystemId *string `json:"hid_acs_system_id,omitempty" url:"-"` } diff --git a/acs/users/client.go b/acs/users/client.go index 96364a9..5cab34c 100644 --- a/acs/users/client.go +++ b/acs/users/client.go @@ -3,21 +3,18 @@ package users import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" acs "github.com/seamapi/go/acs" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) AddToAccessGroup( opts ...option.RequestOption, ) (*acs.UsersAddToAccessGroupResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/add_to_access_group" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/add_to_access_group" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersAddToAccessGroupResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.AcsUser, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*acs.UsersDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.AcsUser, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -293,56 +242,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.AcsUser, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -356,56 +293,44 @@ func (c *Client) ListAccessibleEntrances( opts ...option.RequestOption, ) ([]*seamapigo.AcsEntrance, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/list_accessible_entrances" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/list_accessible_entrances" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersListAccessibleEntrancesResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -419,56 +344,44 @@ func (c *Client) RemoveFromAccessGroup( opts ...option.RequestOption, ) (*acs.UsersRemoveFromAccessGroupResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/remove_from_access_group" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/remove_from_access_group" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersRemoveFromAccessGroupResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -482,56 +395,44 @@ func (c *Client) RevokeAccessToAllEntrances( opts ...option.RequestOption, ) (*acs.UsersRevokeAccessToAllEntrancesResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/revoke_access_to_all_entrances" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/revoke_access_to_all_entrances" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersRevokeAccessToAllEntrancesResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -545,56 +446,44 @@ func (c *Client) Suspend( opts ...option.RequestOption, ) (*acs.UsersSuspendResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/suspend" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/suspend" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersSuspendResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -608,56 +497,44 @@ func (c *Client) Unsuspend( opts ...option.RequestOption, ) (*acs.UsersUnsuspendResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/unsuspend" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/unsuspend" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersUnsuspendResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -671,56 +548,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*acs.UsersUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "acs/users/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/acs/users/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *acs.UsersUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/action_attempts.go b/action_attempts.go index 6ddf25c..b0cb187 100644 --- a/action_attempts.go +++ b/action_attempts.go @@ -5,22 +5,41 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type ActionAttemptsGetRequest struct { - ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + ActionAttemptId string `json:"action_attempt_id" url:"-"` } type ActionAttemptsListRequest struct { - ActionAttemptIds []string `json:"action_attempt_ids,omitempty" url:"action_attempt_ids,omitempty"` + ActionAttemptIds []string `json:"action_attempt_ids,omitempty" url:"-"` } type ActionAttemptsGetResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptsGetResponse) GetActionAttempt() *ActionAttempt { + if a == nil { + return nil + } + return a.ActionAttempt +} + +func (a *ActionAttemptsGetResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *ActionAttemptsGetResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *ActionAttemptsGetResponse) UnmarshalJSON(data []byte) error { @@ -30,17 +49,22 @@ func (a *ActionAttemptsGetResponse) UnmarshalJSON(data []byte) error { return err } *a = ActionAttemptsGetResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *ActionAttemptsGetResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -50,7 +74,26 @@ type ActionAttemptsListResponse struct { ActionAttempts []*ActionAttempt `json:"action_attempts,omitempty" url:"action_attempts,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptsListResponse) GetActionAttempts() []*ActionAttempt { + if a == nil { + return nil + } + return a.ActionAttempts +} + +func (a *ActionAttemptsListResponse) GetOk() bool { + if a == nil { + return false + } + return a.Ok +} + +func (a *ActionAttemptsListResponse) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *ActionAttemptsListResponse) UnmarshalJSON(data []byte) error { @@ -60,17 +103,22 @@ func (a *ActionAttemptsListResponse) UnmarshalJSON(data []byte) error { return err } *a = ActionAttemptsListResponse(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *ActionAttemptsListResponse) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) diff --git a/actionattempts/client.go b/actionattempts/client.go index e97f94f..5115c2f 100644 --- a/actionattempts/client.go +++ b/actionattempts/client.go @@ -3,20 +3,17 @@ package actionattempts import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "action_attempts/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/action_attempts/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ActionAttemptsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "action_attempts/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/action_attempts/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ActionAttemptsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/client/client.go b/client/client.go index cd1df68..0d3564d 100644 --- a/client/client.go +++ b/client/client.go @@ -12,6 +12,7 @@ import ( core "github.com/seamapi/go/core" devicesclient "github.com/seamapi/go/devices/client" events "github.com/seamapi/go/events" + internal "github.com/seamapi/go/internal" locks "github.com/seamapi/go/locks" networks "github.com/seamapi/go/networks" noisesensorsclient "github.com/seamapi/go/noisesensors/client" @@ -26,7 +27,7 @@ import ( type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header AccessCodes *accesscodesclient.Client @@ -51,8 +52,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, diff --git a/client_sessions.go b/client_sessions.go index 5c7142c..1d6f6c6 100644 --- a/client_sessions.go +++ b/client_sessions.go @@ -5,16 +5,16 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type ClientSessionsCreateRequest struct { - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"connect_webview_ids,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"user_identity_ids,omitempty"` - ExpiresAt *time.Time `json:"expires_at,omitempty" url:"expires_at,omitempty"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"-"` + ExpiresAt *time.Time `json:"expires_at,omitempty" url:"-"` } func (c *ClientSessionsCreateRequest) UnmarshalJSON(data []byte) error { @@ -31,29 +31,29 @@ func (c *ClientSessionsCreateRequest) MarshalJSON() ([]byte, error) { type embed ClientSessionsCreateRequest var marshaler = struct { embed - ExpiresAt *core.DateTime `json:"expires_at,omitempty"` + ExpiresAt *internal.DateTime `json:"expires_at,omitempty"` }{ embed: embed(*c), - ExpiresAt: core.NewOptionalDateTime(c.ExpiresAt), + ExpiresAt: internal.NewOptionalDateTime(c.ExpiresAt), } return json.Marshal(marshaler) } type ClientSessionsDeleteRequest struct { - ClientSessionId string `json:"client_session_id" url:"client_session_id"` + ClientSessionId string `json:"client_session_id" url:"-"` } type ClientSessionsGetRequest struct { - ClientSessionId *string `json:"client_session_id,omitempty" url:"client_session_id,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` + ClientSessionId *string `json:"client_session_id,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` } type ClientSessionsGetOrCreateRequest struct { - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"connect_webview_ids,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"user_identity_ids,omitempty"` - ExpiresAt *time.Time `json:"expires_at,omitempty" url:"expires_at,omitempty"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"-"` + ExpiresAt *time.Time `json:"expires_at,omitempty" url:"-"` } func (c *ClientSessionsGetOrCreateRequest) UnmarshalJSON(data []byte) error { @@ -70,39 +70,186 @@ func (c *ClientSessionsGetOrCreateRequest) MarshalJSON() ([]byte, error) { type embed ClientSessionsGetOrCreateRequest var marshaler = struct { embed - ExpiresAt *core.DateTime `json:"expires_at,omitempty"` + ExpiresAt *internal.DateTime `json:"expires_at,omitempty"` }{ embed: embed(*c), - ExpiresAt: core.NewOptionalDateTime(c.ExpiresAt), + ExpiresAt: internal.NewOptionalDateTime(c.ExpiresAt), } return json.Marshal(marshaler) } type ClientSessionsGrantAccessRequest struct { - ClientSessionId *string `json:"client_session_id,omitempty" url:"client_session_id,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"connect_webview_ids,omitempty"` - UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"user_identity_ids,omitempty"` + ClientSessionId *string `json:"client_session_id,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"-"` + UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"-"` } type ClientSessionsListRequest struct { - ClientSessionId *string `json:"client_session_id,omitempty" url:"client_session_id,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"connect_webview_id,omitempty"` - WithoutUserIdentifierKey *bool `json:"without_user_identifier_key,omitempty" url:"without_user_identifier_key,omitempty"` - UserIdentityId *string `json:"user_identity_id,omitempty" url:"user_identity_id,omitempty"` + ClientSessionId *string `json:"client_session_id,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"-"` + WithoutUserIdentifierKey *bool `json:"without_user_identifier_key,omitempty" url:"-"` + UserIdentityId *string `json:"user_identity_id,omitempty" url:"-"` } type ClientSessionsRevokeRequest struct { - ClientSessionId string `json:"client_session_id" url:"client_session_id"` + ClientSessionId string `json:"client_session_id" url:"-"` +} + +type ClientSession struct { + ClientSessionId string `json:"client_session_id" url:"client_session_id"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + Token string `json:"token" url:"token"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` + DeviceCount float64 `json:"device_count" url:"device_count"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` + ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"connect_webview_ids,omitempty"` + UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"user_identity_ids,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSession) GetClientSessionId() string { + if c == nil { + return "" + } + return c.ClientSessionId +} + +func (c *ClientSession) GetWorkspaceId() string { + if c == nil { + return "" + } + return c.WorkspaceId +} + +func (c *ClientSession) GetCreatedAt() time.Time { + if c == nil { + return time.Time{} + } + return c.CreatedAt +} + +func (c *ClientSession) GetToken() string { + if c == nil { + return "" + } + return c.Token +} + +func (c *ClientSession) GetUserIdentifierKey() *string { + if c == nil { + return nil + } + return c.UserIdentifierKey +} + +func (c *ClientSession) GetDeviceCount() float64 { + if c == nil { + return 0 + } + return c.DeviceCount +} + +func (c *ClientSession) GetConnectedAccountIds() []string { + if c == nil { + return nil + } + return c.ConnectedAccountIds +} + +func (c *ClientSession) GetConnectWebviewIds() []string { + if c == nil { + return nil + } + return c.ConnectWebviewIds +} + +func (c *ClientSession) GetUserIdentityIds() []string { + if c == nil { + return nil + } + return c.UserIdentityIds +} + +func (c *ClientSession) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ClientSession) UnmarshalJSON(data []byte) error { + type embed ClientSession + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*c), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *c = ClientSession(unmarshaler.embed) + c.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *ClientSession) MarshalJSON() ([]byte, error) { + type embed ClientSession + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*c), + CreatedAt: internal.NewDateTime(c.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (c *ClientSession) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) } type ClientSessionsCreateResponse struct { ClientSession *ClientSession `json:"client_session,omitempty" url:"client_session,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsCreateResponse) GetClientSession() *ClientSession { + if c == nil { + return nil + } + return c.ClientSession +} + +func (c *ClientSessionsCreateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsCreateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsCreateResponse) UnmarshalJSON(data []byte) error { @@ -112,17 +259,22 @@ func (c *ClientSessionsCreateResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsCreateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsCreateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -131,7 +283,19 @@ func (c *ClientSessionsCreateResponse) String() string { type ClientSessionsDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsDeleteResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsDeleteResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsDeleteResponse) UnmarshalJSON(data []byte) error { @@ -141,17 +305,22 @@ func (c *ClientSessionsDeleteResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsDeleteResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsDeleteResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -161,7 +330,26 @@ type ClientSessionsGetOrCreateResponse struct { ClientSession *ClientSession `json:"client_session,omitempty" url:"client_session,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsGetOrCreateResponse) GetClientSession() *ClientSession { + if c == nil { + return nil + } + return c.ClientSession +} + +func (c *ClientSessionsGetOrCreateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsGetOrCreateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsGetOrCreateResponse) UnmarshalJSON(data []byte) error { @@ -171,17 +359,22 @@ func (c *ClientSessionsGetOrCreateResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsGetOrCreateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsGetOrCreateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -191,7 +384,26 @@ type ClientSessionsGetResponse struct { ClientSession *ClientSession `json:"client_session,omitempty" url:"client_session,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsGetResponse) GetClientSession() *ClientSession { + if c == nil { + return nil + } + return c.ClientSession +} + +func (c *ClientSessionsGetResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsGetResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsGetResponse) UnmarshalJSON(data []byte) error { @@ -201,17 +413,22 @@ func (c *ClientSessionsGetResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsGetResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsGetResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -221,7 +438,26 @@ type ClientSessionsGrantAccessResponse struct { ClientSession *ClientSession `json:"client_session,omitempty" url:"client_session,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsGrantAccessResponse) GetClientSession() *ClientSession { + if c == nil { + return nil + } + return c.ClientSession +} + +func (c *ClientSessionsGrantAccessResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsGrantAccessResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsGrantAccessResponse) UnmarshalJSON(data []byte) error { @@ -231,17 +467,22 @@ func (c *ClientSessionsGrantAccessResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsGrantAccessResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsGrantAccessResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -251,7 +492,26 @@ type ClientSessionsListResponse struct { ClientSessions []*ClientSession `json:"client_sessions,omitempty" url:"client_sessions,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsListResponse) GetClientSessions() []*ClientSession { + if c == nil { + return nil + } + return c.ClientSessions +} + +func (c *ClientSessionsListResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsListResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsListResponse) UnmarshalJSON(data []byte) error { @@ -261,17 +521,22 @@ func (c *ClientSessionsListResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsListResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsListResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -280,7 +545,19 @@ func (c *ClientSessionsListResponse) String() string { type ClientSessionsRevokeResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClientSessionsRevokeResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClientSessionsRevokeResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClientSessionsRevokeResponse) UnmarshalJSON(data []byte) error { @@ -290,17 +567,22 @@ func (c *ClientSessionsRevokeResponse) UnmarshalJSON(data []byte) error { return err } *c = ClientSessionsRevokeResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClientSessionsRevokeResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) diff --git a/clientsessions/client.go b/clientsessions/client.go index 4f2bd2e..3211c1d 100644 --- a/clientsessions/client.go +++ b/clientsessions/client.go @@ -3,20 +3,17 @@ package clientsessions import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.ClientSession, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.ClientSessionsDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -166,56 +139,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.ClientSession, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -229,56 +190,44 @@ func (c *Client) GetOrCreate( opts ...option.RequestOption, ) (*seamapigo.ClientSession, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/get_or_create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/get_or_create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsGetOrCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -292,56 +241,44 @@ func (c *Client) GrantAccess( opts ...option.RequestOption, ) (*seamapigo.ClientSessionsGrantAccessResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/grant_access" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/grant_access" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsGrantAccessResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -355,56 +292,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.ClientSession, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -418,56 +343,44 @@ func (c *Client) Revoke( opts ...option.RequestOption, ) (*seamapigo.ClientSessionsRevokeResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "client_sessions/revoke" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/client_sessions/revoke" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ClientSessionsRevokeResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/connect_webviews.go b/connect_webviews.go index 8fae3bc..31f27be 100644 --- a/connect_webviews.go +++ b/connect_webviews.go @@ -5,32 +5,366 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" + time "time" ) type ConnectWebviewsCreateRequest struct { - DeviceSelectionMode *SelectionMode `json:"device_selection_mode,omitempty" url:"device_selection_mode,omitempty"` - CustomRedirectUrl *string `json:"custom_redirect_url,omitempty" url:"custom_redirect_url,omitempty"` - CustomRedirectFailureUrl *string `json:"custom_redirect_failure_url,omitempty" url:"custom_redirect_failure_url,omitempty"` - AcceptedProviders []AcceptedProvider `json:"accepted_providers,omitempty" url:"accepted_providers,omitempty"` - ProviderCategory *ProviderCategory `json:"provider_category,omitempty" url:"provider_category,omitempty"` - CustomMetadata map[string]*ConnectWebviewsCreateRequestCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` - AutomaticallyManageNewDevices *bool `json:"automatically_manage_new_devices,omitempty" url:"automatically_manage_new_devices,omitempty"` - WaitForDeviceCreation *bool `json:"wait_for_device_creation,omitempty" url:"wait_for_device_creation,omitempty"` + DeviceSelectionMode *SelectionMode `json:"device_selection_mode,omitempty" url:"-"` + CustomRedirectUrl *string `json:"custom_redirect_url,omitempty" url:"-"` + CustomRedirectFailureUrl *string `json:"custom_redirect_failure_url,omitempty" url:"-"` + AcceptedProviders []AcceptedProvider `json:"accepted_providers,omitempty" url:"-"` + ProviderCategory *ProviderCategory `json:"provider_category,omitempty" url:"-"` + CustomMetadata map[string]*ConnectWebviewsCreateRequestCustomMetadataValue `json:"custom_metadata,omitempty" url:"-"` + AutomaticallyManageNewDevices *bool `json:"automatically_manage_new_devices,omitempty" url:"-"` + WaitForDeviceCreation *bool `json:"wait_for_device_creation,omitempty" url:"-"` } type ConnectWebviewsDeleteRequest struct { - ConnectWebviewId string `json:"connect_webview_id" url:"connect_webview_id"` + ConnectWebviewId string `json:"connect_webview_id" url:"-"` } type ConnectWebviewsGetRequest struct { - ConnectWebviewId string `json:"connect_webview_id" url:"connect_webview_id"` + ConnectWebviewId string `json:"connect_webview_id" url:"-"` } type ConnectWebviewsListRequest struct { - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` // Returns devices where the webview's custom_metadata contains all of the provided key/value pairs. - CustomMetadataHas map[string]*ConnectWebviewsListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"custom_metadata_has,omitempty"` + CustomMetadataHas map[string]*ConnectWebviewsListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"-"` + Limit *float64 `json:"limit,omitempty" url:"-"` +} + +type ConnectWebview struct { + ConnectWebviewId string `json:"connect_webview_id" url:"connect_webview_id"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` + Url string `json:"url" url:"url"` + DeviceSelectionMode SelectionMode `json:"device_selection_mode" url:"device_selection_mode"` + AcceptedProviders []string `json:"accepted_providers,omitempty" url:"accepted_providers,omitempty"` + AcceptedDevices []string `json:"accepted_devices,omitempty" url:"accepted_devices,omitempty"` + AnyDeviceAllowed bool `json:"any_device_allowed" url:"any_device_allowed"` + AnyProviderAllowed bool `json:"any_provider_allowed" url:"any_provider_allowed"` + LoginSuccessful bool `json:"login_successful" url:"login_successful"` + Status ConnectWebviewStatus `json:"status" url:"status"` + CustomRedirectUrl *string `json:"custom_redirect_url,omitempty" url:"custom_redirect_url,omitempty"` + CustomRedirectFailureUrl *string `json:"custom_redirect_failure_url,omitempty" url:"custom_redirect_failure_url,omitempty"` + CustomMetadata map[string]*ConnectWebviewCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` + AutomaticallyManageNewDevices bool `json:"automatically_manage_new_devices" url:"automatically_manage_new_devices"` + WaitForDeviceCreation bool `json:"wait_for_device_creation" url:"wait_for_device_creation"` + AuthorizedAt *time.Time `json:"authorized_at,omitempty" url:"authorized_at,omitempty"` + SelectedProvider *string `json:"selected_provider,omitempty" url:"selected_provider,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectWebview) GetConnectWebviewId() string { + if c == nil { + return "" + } + return c.ConnectWebviewId +} + +func (c *ConnectWebview) GetWorkspaceId() string { + if c == nil { + return "" + } + return c.WorkspaceId +} + +func (c *ConnectWebview) GetCreatedAt() time.Time { + if c == nil { + return time.Time{} + } + return c.CreatedAt +} + +func (c *ConnectWebview) GetConnectedAccountId() *string { + if c == nil { + return nil + } + return c.ConnectedAccountId +} + +func (c *ConnectWebview) GetUrl() string { + if c == nil { + return "" + } + return c.Url +} + +func (c *ConnectWebview) GetDeviceSelectionMode() SelectionMode { + if c == nil { + return "" + } + return c.DeviceSelectionMode +} + +func (c *ConnectWebview) GetAcceptedProviders() []string { + if c == nil { + return nil + } + return c.AcceptedProviders +} + +func (c *ConnectWebview) GetAcceptedDevices() []string { + if c == nil { + return nil + } + return c.AcceptedDevices +} + +func (c *ConnectWebview) GetAnyDeviceAllowed() bool { + if c == nil { + return false + } + return c.AnyDeviceAllowed +} + +func (c *ConnectWebview) GetAnyProviderAllowed() bool { + if c == nil { + return false + } + return c.AnyProviderAllowed +} + +func (c *ConnectWebview) GetLoginSuccessful() bool { + if c == nil { + return false + } + return c.LoginSuccessful +} + +func (c *ConnectWebview) GetStatus() ConnectWebviewStatus { + if c == nil { + return "" + } + return c.Status +} + +func (c *ConnectWebview) GetCustomRedirectUrl() *string { + if c == nil { + return nil + } + return c.CustomRedirectUrl +} + +func (c *ConnectWebview) GetCustomRedirectFailureUrl() *string { + if c == nil { + return nil + } + return c.CustomRedirectFailureUrl +} + +func (c *ConnectWebview) GetCustomMetadata() map[string]*ConnectWebviewCustomMetadataValue { + if c == nil { + return nil + } + return c.CustomMetadata +} + +func (c *ConnectWebview) GetAutomaticallyManageNewDevices() bool { + if c == nil { + return false + } + return c.AutomaticallyManageNewDevices +} + +func (c *ConnectWebview) GetWaitForDeviceCreation() bool { + if c == nil { + return false + } + return c.WaitForDeviceCreation +} + +func (c *ConnectWebview) GetAuthorizedAt() *time.Time { + if c == nil { + return nil + } + return c.AuthorizedAt +} + +func (c *ConnectWebview) GetSelectedProvider() *string { + if c == nil { + return nil + } + return c.SelectedProvider +} + +func (c *ConnectWebview) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ConnectWebview) UnmarshalJSON(data []byte) error { + type embed ConnectWebview + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + AuthorizedAt *internal.DateTime `json:"authorized_at,omitempty"` + }{ + embed: embed(*c), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *c = ConnectWebview(unmarshaler.embed) + c.CreatedAt = unmarshaler.CreatedAt.Time() + c.AuthorizedAt = unmarshaler.AuthorizedAt.TimePtr() + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *ConnectWebview) MarshalJSON() ([]byte, error) { + type embed ConnectWebview + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + AuthorizedAt *internal.DateTime `json:"authorized_at,omitempty"` + }{ + embed: embed(*c), + CreatedAt: internal.NewDateTime(c.CreatedAt), + AuthorizedAt: internal.NewOptionalDateTime(c.AuthorizedAt), + } + return json.Marshal(marshaler) +} + +func (c *ConnectWebview) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type ConnectWebviewCustomMetadataValue struct { + String string + Boolean bool + + typ string +} + +func NewConnectWebviewCustomMetadataValueFromString(value string) *ConnectWebviewCustomMetadataValue { + return &ConnectWebviewCustomMetadataValue{typ: "String", String: value} +} + +func NewConnectWebviewCustomMetadataValueFromBoolean(value bool) *ConnectWebviewCustomMetadataValue { + return &ConnectWebviewCustomMetadataValue{typ: "Boolean", Boolean: value} +} + +func (c *ConnectWebviewCustomMetadataValue) GetString() string { + if c == nil { + return "" + } + return c.String +} + +func (c *ConnectWebviewCustomMetadataValue) GetBoolean() bool { + if c == nil { + return false + } + return c.Boolean +} + +func (c *ConnectWebviewCustomMetadataValue) UnmarshalJSON(data []byte) error { + var valueString string + if err := json.Unmarshal(data, &valueString); err == nil { + c.typ = "String" + c.String = valueString + return nil + } + var valueBoolean bool + if err := json.Unmarshal(data, &valueBoolean); err == nil { + c.typ = "Boolean" + c.Boolean = valueBoolean + return nil + } + return fmt.Errorf("%s cannot be deserialized as a %T", data, c) +} + +func (c ConnectWebviewCustomMetadataValue) MarshalJSON() ([]byte, error) { + if c.typ == "String" || c.String != "" { + return json.Marshal(c.String) + } + if c.typ == "Boolean" || c.Boolean != false { + return json.Marshal(c.Boolean) + } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) +} + +type ConnectWebviewCustomMetadataValueVisitor interface { + VisitString(string) error + VisitBoolean(bool) error +} + +func (c *ConnectWebviewCustomMetadataValue) Accept(visitor ConnectWebviewCustomMetadataValueVisitor) error { + if c.typ == "String" || c.String != "" { + return visitor.VisitString(c.String) + } + if c.typ == "Boolean" || c.Boolean != false { + return visitor.VisitBoolean(c.Boolean) + } + return fmt.Errorf("type %T does not include a non-empty union type", c) +} + +type ConnectWebviewStatus string + +const ( + ConnectWebviewStatusPending ConnectWebviewStatus = "pending" + ConnectWebviewStatusFailed ConnectWebviewStatus = "failed" + ConnectWebviewStatusAuthorized ConnectWebviewStatus = "authorized" +) + +func NewConnectWebviewStatusFromString(s string) (ConnectWebviewStatus, error) { + switch s { + case "pending": + return ConnectWebviewStatusPending, nil + case "failed": + return ConnectWebviewStatusFailed, nil + case "authorized": + return ConnectWebviewStatusAuthorized, nil + } + var t ConnectWebviewStatus + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (c ConnectWebviewStatus) Ptr() *ConnectWebviewStatus { + return &c +} + +type SelectionMode string + +const ( + SelectionModeNone SelectionMode = "none" + SelectionModeSingle SelectionMode = "single" + SelectionModeMultiple SelectionMode = "multiple" +) + +func NewSelectionModeFromString(s string) (SelectionMode, error) { + switch s { + case "none": + return SelectionModeNone, nil + case "single": + return SelectionModeSingle, nil + case "multiple": + return SelectionModeMultiple, nil + } + var t SelectionMode + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (s SelectionMode) Ptr() *SelectionMode { + return &s } type AcceptedProvider string @@ -170,83 +504,99 @@ func (a AcceptedProvider) Ptr() *AcceptedProvider { } type ConnectWebviewsCreateRequestCustomMetadataValue struct { - typeName string - String string - Boolean bool - StringOptional *string + String string + Boolean bool + + typ string } func NewConnectWebviewsCreateRequestCustomMetadataValueFromString(value string) *ConnectWebviewsCreateRequestCustomMetadataValue { - return &ConnectWebviewsCreateRequestCustomMetadataValue{typeName: "string", String: value} + return &ConnectWebviewsCreateRequestCustomMetadataValue{typ: "String", String: value} } func NewConnectWebviewsCreateRequestCustomMetadataValueFromBoolean(value bool) *ConnectWebviewsCreateRequestCustomMetadataValue { - return &ConnectWebviewsCreateRequestCustomMetadataValue{typeName: "boolean", Boolean: value} + return &ConnectWebviewsCreateRequestCustomMetadataValue{typ: "Boolean", Boolean: value} } -func NewConnectWebviewsCreateRequestCustomMetadataValueFromStringOptional(value *string) *ConnectWebviewsCreateRequestCustomMetadataValue { - return &ConnectWebviewsCreateRequestCustomMetadataValue{typeName: "stringOptional", StringOptional: value} +func (c *ConnectWebviewsCreateRequestCustomMetadataValue) GetString() string { + if c == nil { + return "" + } + return c.String +} + +func (c *ConnectWebviewsCreateRequestCustomMetadataValue) GetBoolean() bool { + if c == nil { + return false + } + return c.Boolean } func (c *ConnectWebviewsCreateRequestCustomMetadataValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - c.typeName = "string" + c.typ = "String" c.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - c.typeName = "boolean" + c.typ = "Boolean" c.Boolean = valueBoolean return nil } - var valueStringOptional *string - if err := json.Unmarshal(data, &valueStringOptional); err == nil { - c.typeName = "stringOptional" - c.StringOptional = valueStringOptional - return nil - } return fmt.Errorf("%s cannot be deserialized as a %T", data, c) } func (c ConnectWebviewsCreateRequestCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return json.Marshal(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return json.Marshal(c.Boolean) - case "stringOptional": - return json.Marshal(c.StringOptional) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectWebviewsCreateRequestCustomMetadataValueVisitor interface { VisitString(string) error VisitBoolean(bool) error - VisitStringOptional(*string) error } func (c *ConnectWebviewsCreateRequestCustomMetadataValue) Accept(visitor ConnectWebviewsCreateRequestCustomMetadataValueVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return visitor.VisitString(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return visitor.VisitBoolean(c.Boolean) - case "stringOptional": - return visitor.VisitStringOptional(c.StringOptional) } + return fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectWebviewsCreateResponse struct { ConnectWebview *ConnectWebview `json:"connect_webview,omitempty" url:"connect_webview,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectWebviewsCreateResponse) GetConnectWebview() *ConnectWebview { + if c == nil { + return nil + } + return c.ConnectWebview +} + +func (c *ConnectWebviewsCreateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectWebviewsCreateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectWebviewsCreateResponse) UnmarshalJSON(data []byte) error { @@ -256,17 +606,22 @@ func (c *ConnectWebviewsCreateResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectWebviewsCreateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectWebviewsCreateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -275,7 +630,19 @@ func (c *ConnectWebviewsCreateResponse) String() string { type ConnectWebviewsDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectWebviewsDeleteResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectWebviewsDeleteResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectWebviewsDeleteResponse) UnmarshalJSON(data []byte) error { @@ -285,17 +652,22 @@ func (c *ConnectWebviewsDeleteResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectWebviewsDeleteResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectWebviewsDeleteResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -305,7 +677,26 @@ type ConnectWebviewsGetResponse struct { ConnectWebview *ConnectWebview `json:"connect_webview,omitempty" url:"connect_webview,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectWebviewsGetResponse) GetConnectWebview() *ConnectWebview { + if c == nil { + return nil + } + return c.ConnectWebview +} + +func (c *ConnectWebviewsGetResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectWebviewsGetResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectWebviewsGetResponse) UnmarshalJSON(data []byte) error { @@ -315,46 +706,66 @@ func (c *ConnectWebviewsGetResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectWebviewsGetResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectWebviewsGetResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type ConnectWebviewsListRequestCustomMetadataHasValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewConnectWebviewsListRequestCustomMetadataHasValueFromString(value string) *ConnectWebviewsListRequestCustomMetadataHasValue { - return &ConnectWebviewsListRequestCustomMetadataHasValue{typeName: "string", String: value} + return &ConnectWebviewsListRequestCustomMetadataHasValue{typ: "String", String: value} } func NewConnectWebviewsListRequestCustomMetadataHasValueFromBoolean(value bool) *ConnectWebviewsListRequestCustomMetadataHasValue { - return &ConnectWebviewsListRequestCustomMetadataHasValue{typeName: "boolean", Boolean: value} + return &ConnectWebviewsListRequestCustomMetadataHasValue{typ: "Boolean", Boolean: value} +} + +func (c *ConnectWebviewsListRequestCustomMetadataHasValue) GetString() string { + if c == nil { + return "" + } + return c.String +} + +func (c *ConnectWebviewsListRequestCustomMetadataHasValue) GetBoolean() bool { + if c == nil { + return false + } + return c.Boolean } func (c *ConnectWebviewsListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - c.typeName = "string" + c.typ = "String" c.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - c.typeName = "boolean" + c.typ = "Boolean" c.Boolean = valueBoolean return nil } @@ -362,14 +773,13 @@ func (c *ConnectWebviewsListRequestCustomMetadataHasValue) UnmarshalJSON(data [] } func (c ConnectWebviewsListRequestCustomMetadataHasValue) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return json.Marshal(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return json.Marshal(c.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectWebviewsListRequestCustomMetadataHasValueVisitor interface { @@ -378,21 +788,39 @@ type ConnectWebviewsListRequestCustomMetadataHasValueVisitor interface { } func (c *ConnectWebviewsListRequestCustomMetadataHasValue) Accept(visitor ConnectWebviewsListRequestCustomMetadataHasValueVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return visitor.VisitString(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return visitor.VisitBoolean(c.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectWebviewsListResponse struct { ConnectWebviews []*ConnectWebview `json:"connect_webviews,omitempty" url:"connect_webviews,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectWebviewsListResponse) GetConnectWebviews() []*ConnectWebview { + if c == nil { + return nil + } + return c.ConnectWebviews +} + +func (c *ConnectWebviewsListResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectWebviewsListResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectWebviewsListResponse) UnmarshalJSON(data []byte) error { @@ -402,17 +830,22 @@ func (c *ConnectWebviewsListResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectWebviewsListResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectWebviewsListResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) diff --git a/connected_accounts.go b/connected_accounts.go index c80456a..1f330d5 100644 --- a/connected_accounts.go +++ b/connected_accounts.go @@ -5,23 +5,312 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" + time "time" ) type ConnectedAccountsDeleteRequest struct { - ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + ConnectedAccountId string `json:"connected_account_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type ConnectedAccountsListRequest struct { // Returns devices where the account's custom_metadata contains all of the provided key/value pairs. - CustomMetadataHas map[string]*ConnectedAccountsListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"custom_metadata_has,omitempty"` + CustomMetadataHas map[string]*ConnectedAccountsListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"-"` +} + +type ConnectedAccount struct { + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty" url:"created_at,omitempty"` + UserIdentifier *ConnectedAccountUserIdentifier `json:"user_identifier,omitempty" url:"user_identifier,omitempty"` + AccountType *string `json:"account_type,omitempty" url:"account_type,omitempty"` + AccountTypeDisplayName string `json:"account_type_display_name" url:"account_type_display_name"` + Errors interface{} `json:"errors,omitempty" url:"errors,omitempty"` + Warnings interface{} `json:"warnings,omitempty" url:"warnings,omitempty"` + CustomMetadata map[string]*ConnectedAccountCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` + AutomaticallyManageNewDevices bool `json:"automatically_manage_new_devices" url:"automatically_manage_new_devices"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccount) GetConnectedAccountId() *string { + if c == nil { + return nil + } + return c.ConnectedAccountId +} + +func (c *ConnectedAccount) GetCreatedAt() *time.Time { + if c == nil { + return nil + } + return c.CreatedAt +} + +func (c *ConnectedAccount) GetUserIdentifier() *ConnectedAccountUserIdentifier { + if c == nil { + return nil + } + return c.UserIdentifier +} + +func (c *ConnectedAccount) GetAccountType() *string { + if c == nil { + return nil + } + return c.AccountType +} + +func (c *ConnectedAccount) GetAccountTypeDisplayName() string { + if c == nil { + return "" + } + return c.AccountTypeDisplayName +} + +func (c *ConnectedAccount) GetErrors() interface{} { + if c == nil { + return nil + } + return c.Errors +} + +func (c *ConnectedAccount) GetWarnings() interface{} { + if c == nil { + return nil + } + return c.Warnings +} + +func (c *ConnectedAccount) GetCustomMetadata() map[string]*ConnectedAccountCustomMetadataValue { + if c == nil { + return nil + } + return c.CustomMetadata +} + +func (c *ConnectedAccount) GetAutomaticallyManageNewDevices() bool { + if c == nil { + return false + } + return c.AutomaticallyManageNewDevices +} + +func (c *ConnectedAccount) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ConnectedAccount) UnmarshalJSON(data []byte) error { + type embed ConnectedAccount + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at,omitempty"` + }{ + embed: embed(*c), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *c = ConnectedAccount(unmarshaler.embed) + c.CreatedAt = unmarshaler.CreatedAt.TimePtr() + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *ConnectedAccount) MarshalJSON() ([]byte, error) { + type embed ConnectedAccount + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at,omitempty"` + }{ + embed: embed(*c), + CreatedAt: internal.NewOptionalDateTime(c.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (c *ConnectedAccount) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type ConnectedAccountCustomMetadataValue struct { + String string + Boolean bool + + typ string +} + +func NewConnectedAccountCustomMetadataValueFromString(value string) *ConnectedAccountCustomMetadataValue { + return &ConnectedAccountCustomMetadataValue{typ: "String", String: value} +} + +func NewConnectedAccountCustomMetadataValueFromBoolean(value bool) *ConnectedAccountCustomMetadataValue { + return &ConnectedAccountCustomMetadataValue{typ: "Boolean", Boolean: value} +} + +func (c *ConnectedAccountCustomMetadataValue) GetString() string { + if c == nil { + return "" + } + return c.String +} + +func (c *ConnectedAccountCustomMetadataValue) GetBoolean() bool { + if c == nil { + return false + } + return c.Boolean +} + +func (c *ConnectedAccountCustomMetadataValue) UnmarshalJSON(data []byte) error { + var valueString string + if err := json.Unmarshal(data, &valueString); err == nil { + c.typ = "String" + c.String = valueString + return nil + } + var valueBoolean bool + if err := json.Unmarshal(data, &valueBoolean); err == nil { + c.typ = "Boolean" + c.Boolean = valueBoolean + return nil + } + return fmt.Errorf("%s cannot be deserialized as a %T", data, c) +} + +func (c ConnectedAccountCustomMetadataValue) MarshalJSON() ([]byte, error) { + if c.typ == "String" || c.String != "" { + return json.Marshal(c.String) + } + if c.typ == "Boolean" || c.Boolean != false { + return json.Marshal(c.Boolean) + } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) +} + +type ConnectedAccountCustomMetadataValueVisitor interface { + VisitString(string) error + VisitBoolean(bool) error +} + +func (c *ConnectedAccountCustomMetadataValue) Accept(visitor ConnectedAccountCustomMetadataValueVisitor) error { + if c.typ == "String" || c.String != "" { + return visitor.VisitString(c.String) + } + if c.typ == "Boolean" || c.Boolean != false { + return visitor.VisitBoolean(c.Boolean) + } + return fmt.Errorf("type %T does not include a non-empty union type", c) +} + +type ConnectedAccountUserIdentifier struct { + Username *string `json:"username,omitempty" url:"username,omitempty"` + ApiUrl *string `json:"api_url,omitempty" url:"api_url,omitempty"` + Email *string `json:"email,omitempty" url:"email,omitempty"` + Phone *string `json:"phone,omitempty" url:"phone,omitempty"` + Exclusive *bool `json:"exclusive,omitempty" url:"exclusive,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountUserIdentifier) GetUsername() *string { + if c == nil { + return nil + } + return c.Username +} + +func (c *ConnectedAccountUserIdentifier) GetApiUrl() *string { + if c == nil { + return nil + } + return c.ApiUrl +} + +func (c *ConnectedAccountUserIdentifier) GetEmail() *string { + if c == nil { + return nil + } + return c.Email +} + +func (c *ConnectedAccountUserIdentifier) GetPhone() *string { + if c == nil { + return nil + } + return c.Phone +} + +func (c *ConnectedAccountUserIdentifier) GetExclusive() *bool { + if c == nil { + return nil + } + return c.Exclusive +} + +func (c *ConnectedAccountUserIdentifier) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ConnectedAccountUserIdentifier) UnmarshalJSON(data []byte) error { + type unmarshaler ConnectedAccountUserIdentifier + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ConnectedAccountUserIdentifier(value) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *ConnectedAccountUserIdentifier) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) } type ConnectedAccountsDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountsDeleteResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectedAccountsDeleteResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectedAccountsDeleteResponse) UnmarshalJSON(data []byte) error { @@ -31,46 +320,66 @@ func (c *ConnectedAccountsDeleteResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectedAccountsDeleteResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectedAccountsDeleteResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type ConnectedAccountsGetRequest struct { - typeName string ConnectedAccountsGetRequestConnectedAccountId *ConnectedAccountsGetRequestConnectedAccountId ConnectedAccountsGetRequestEmail *ConnectedAccountsGetRequestEmail + + typ string } func NewConnectedAccountsGetRequestFromConnectedAccountsGetRequestConnectedAccountId(value *ConnectedAccountsGetRequestConnectedAccountId) *ConnectedAccountsGetRequest { - return &ConnectedAccountsGetRequest{typeName: "connectedAccountsGetRequestConnectedAccountId", ConnectedAccountsGetRequestConnectedAccountId: value} + return &ConnectedAccountsGetRequest{typ: "ConnectedAccountsGetRequestConnectedAccountId", ConnectedAccountsGetRequestConnectedAccountId: value} } func NewConnectedAccountsGetRequestFromConnectedAccountsGetRequestEmail(value *ConnectedAccountsGetRequestEmail) *ConnectedAccountsGetRequest { - return &ConnectedAccountsGetRequest{typeName: "connectedAccountsGetRequestEmail", ConnectedAccountsGetRequestEmail: value} + return &ConnectedAccountsGetRequest{typ: "ConnectedAccountsGetRequestEmail", ConnectedAccountsGetRequestEmail: value} +} + +func (c *ConnectedAccountsGetRequest) GetConnectedAccountsGetRequestConnectedAccountId() *ConnectedAccountsGetRequestConnectedAccountId { + if c == nil { + return nil + } + return c.ConnectedAccountsGetRequestConnectedAccountId +} + +func (c *ConnectedAccountsGetRequest) GetConnectedAccountsGetRequestEmail() *ConnectedAccountsGetRequestEmail { + if c == nil { + return nil + } + return c.ConnectedAccountsGetRequestEmail } func (c *ConnectedAccountsGetRequest) UnmarshalJSON(data []byte) error { valueConnectedAccountsGetRequestConnectedAccountId := new(ConnectedAccountsGetRequestConnectedAccountId) if err := json.Unmarshal(data, &valueConnectedAccountsGetRequestConnectedAccountId); err == nil { - c.typeName = "connectedAccountsGetRequestConnectedAccountId" + c.typ = "ConnectedAccountsGetRequestConnectedAccountId" c.ConnectedAccountsGetRequestConnectedAccountId = valueConnectedAccountsGetRequestConnectedAccountId return nil } valueConnectedAccountsGetRequestEmail := new(ConnectedAccountsGetRequestEmail) if err := json.Unmarshal(data, &valueConnectedAccountsGetRequestEmail); err == nil { - c.typeName = "connectedAccountsGetRequestEmail" + c.typ = "ConnectedAccountsGetRequestEmail" c.ConnectedAccountsGetRequestEmail = valueConnectedAccountsGetRequestEmail return nil } @@ -78,14 +387,13 @@ func (c *ConnectedAccountsGetRequest) UnmarshalJSON(data []byte) error { } func (c ConnectedAccountsGetRequest) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "connectedAccountsGetRequestConnectedAccountId": + if c.typ == "ConnectedAccountsGetRequestConnectedAccountId" || c.ConnectedAccountsGetRequestConnectedAccountId != nil { return json.Marshal(c.ConnectedAccountsGetRequestConnectedAccountId) - case "connectedAccountsGetRequestEmail": + } + if c.typ == "ConnectedAccountsGetRequestEmail" || c.ConnectedAccountsGetRequestEmail != nil { return json.Marshal(c.ConnectedAccountsGetRequestEmail) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectedAccountsGetRequestVisitor interface { @@ -94,21 +402,131 @@ type ConnectedAccountsGetRequestVisitor interface { } func (c *ConnectedAccountsGetRequest) Accept(visitor ConnectedAccountsGetRequestVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "connectedAccountsGetRequestConnectedAccountId": + if c.typ == "ConnectedAccountsGetRequestConnectedAccountId" || c.ConnectedAccountsGetRequestConnectedAccountId != nil { return visitor.VisitConnectedAccountsGetRequestConnectedAccountId(c.ConnectedAccountsGetRequestConnectedAccountId) - case "connectedAccountsGetRequestEmail": + } + if c.typ == "ConnectedAccountsGetRequestEmail" || c.ConnectedAccountsGetRequestEmail != nil { return visitor.VisitConnectedAccountsGetRequestEmail(c.ConnectedAccountsGetRequestEmail) } + return fmt.Errorf("type %T does not include a non-empty union type", c) +} + +type ConnectedAccountsGetRequestConnectedAccountId struct { + ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountsGetRequestConnectedAccountId) GetConnectedAccountId() string { + if c == nil { + return "" + } + return c.ConnectedAccountId +} + +func (c *ConnectedAccountsGetRequestConnectedAccountId) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ConnectedAccountsGetRequestConnectedAccountId) UnmarshalJSON(data []byte) error { + type unmarshaler ConnectedAccountsGetRequestConnectedAccountId + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ConnectedAccountsGetRequestConnectedAccountId(value) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *ConnectedAccountsGetRequestConnectedAccountId) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) +} + +type ConnectedAccountsGetRequestEmail struct { + Email string `json:"email" url:"email"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountsGetRequestEmail) GetEmail() string { + if c == nil { + return "" + } + return c.Email +} + +func (c *ConnectedAccountsGetRequestEmail) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + +func (c *ConnectedAccountsGetRequestEmail) UnmarshalJSON(data []byte) error { + type unmarshaler ConnectedAccountsGetRequestEmail + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *c = ConnectedAccountsGetRequestEmail(value) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) + return nil +} + +func (c *ConnectedAccountsGetRequestEmail) String() string { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(c); err == nil { + return value + } + return fmt.Sprintf("%#v", c) } type ConnectedAccountsGetResponse struct { ConnectedAccount *ConnectedAccount `json:"connected_account,omitempty" url:"connected_account,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountsGetResponse) GetConnectedAccount() *ConnectedAccount { + if c == nil { + return nil + } + return c.ConnectedAccount +} + +func (c *ConnectedAccountsGetResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectedAccountsGetResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectedAccountsGetResponse) UnmarshalJSON(data []byte) error { @@ -118,46 +536,66 @@ func (c *ConnectedAccountsGetResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectedAccountsGetResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectedAccountsGetResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type ConnectedAccountsListRequestCustomMetadataHasValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewConnectedAccountsListRequestCustomMetadataHasValueFromString(value string) *ConnectedAccountsListRequestCustomMetadataHasValue { - return &ConnectedAccountsListRequestCustomMetadataHasValue{typeName: "string", String: value} + return &ConnectedAccountsListRequestCustomMetadataHasValue{typ: "String", String: value} } func NewConnectedAccountsListRequestCustomMetadataHasValueFromBoolean(value bool) *ConnectedAccountsListRequestCustomMetadataHasValue { - return &ConnectedAccountsListRequestCustomMetadataHasValue{typeName: "boolean", Boolean: value} + return &ConnectedAccountsListRequestCustomMetadataHasValue{typ: "Boolean", Boolean: value} +} + +func (c *ConnectedAccountsListRequestCustomMetadataHasValue) GetString() string { + if c == nil { + return "" + } + return c.String +} + +func (c *ConnectedAccountsListRequestCustomMetadataHasValue) GetBoolean() bool { + if c == nil { + return false + } + return c.Boolean } func (c *ConnectedAccountsListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - c.typeName = "string" + c.typ = "String" c.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - c.typeName = "boolean" + c.typ = "Boolean" c.Boolean = valueBoolean return nil } @@ -165,14 +603,13 @@ func (c *ConnectedAccountsListRequestCustomMetadataHasValue) UnmarshalJSON(data } func (c ConnectedAccountsListRequestCustomMetadataHasValue) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return json.Marshal(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return json.Marshal(c.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectedAccountsListRequestCustomMetadataHasValueVisitor interface { @@ -181,21 +618,39 @@ type ConnectedAccountsListRequestCustomMetadataHasValueVisitor interface { } func (c *ConnectedAccountsListRequestCustomMetadataHasValue) Accept(visitor ConnectedAccountsListRequestCustomMetadataHasValueVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return visitor.VisitString(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return visitor.VisitBoolean(c.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectedAccountsListResponse struct { ConnectedAccounts []*ConnectedAccount `json:"connected_accounts,omitempty" url:"connected_accounts,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountsListResponse) GetConnectedAccounts() []*ConnectedAccount { + if c == nil { + return nil + } + return c.ConnectedAccounts +} + +func (c *ConnectedAccountsListResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectedAccountsListResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectedAccountsListResponse) UnmarshalJSON(data []byte) error { @@ -205,100 +660,121 @@ func (c *ConnectedAccountsListResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectedAccountsListResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectedAccountsListResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type ConnectedAccountsUpdateRequestCustomMetadataValue struct { - typeName string - String string - Boolean bool - StringOptional *string + String string + Boolean bool + + typ string } func NewConnectedAccountsUpdateRequestCustomMetadataValueFromString(value string) *ConnectedAccountsUpdateRequestCustomMetadataValue { - return &ConnectedAccountsUpdateRequestCustomMetadataValue{typeName: "string", String: value} + return &ConnectedAccountsUpdateRequestCustomMetadataValue{typ: "String", String: value} } func NewConnectedAccountsUpdateRequestCustomMetadataValueFromBoolean(value bool) *ConnectedAccountsUpdateRequestCustomMetadataValue { - return &ConnectedAccountsUpdateRequestCustomMetadataValue{typeName: "boolean", Boolean: value} + return &ConnectedAccountsUpdateRequestCustomMetadataValue{typ: "Boolean", Boolean: value} +} + +func (c *ConnectedAccountsUpdateRequestCustomMetadataValue) GetString() string { + if c == nil { + return "" + } + return c.String } -func NewConnectedAccountsUpdateRequestCustomMetadataValueFromStringOptional(value *string) *ConnectedAccountsUpdateRequestCustomMetadataValue { - return &ConnectedAccountsUpdateRequestCustomMetadataValue{typeName: "stringOptional", StringOptional: value} +func (c *ConnectedAccountsUpdateRequestCustomMetadataValue) GetBoolean() bool { + if c == nil { + return false + } + return c.Boolean } func (c *ConnectedAccountsUpdateRequestCustomMetadataValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - c.typeName = "string" + c.typ = "String" c.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - c.typeName = "boolean" + c.typ = "Boolean" c.Boolean = valueBoolean return nil } - var valueStringOptional *string - if err := json.Unmarshal(data, &valueStringOptional); err == nil { - c.typeName = "stringOptional" - c.StringOptional = valueStringOptional - return nil - } return fmt.Errorf("%s cannot be deserialized as a %T", data, c) } func (c ConnectedAccountsUpdateRequestCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return json.Marshal(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return json.Marshal(c.Boolean) - case "stringOptional": - return json.Marshal(c.StringOptional) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectedAccountsUpdateRequestCustomMetadataValueVisitor interface { VisitString(string) error VisitBoolean(bool) error - VisitStringOptional(*string) error } func (c *ConnectedAccountsUpdateRequestCustomMetadataValue) Accept(visitor ConnectedAccountsUpdateRequestCustomMetadataValueVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": + if c.typ == "String" || c.String != "" { return visitor.VisitString(c.String) - case "boolean": + } + if c.typ == "Boolean" || c.Boolean != false { return visitor.VisitBoolean(c.Boolean) - case "stringOptional": - return visitor.VisitStringOptional(c.StringOptional) } + return fmt.Errorf("type %T does not include a non-empty union type", c) } type ConnectedAccountsUpdateResponse struct { ConnectedAccount *ConnectedAccount `json:"connected_account,omitempty" url:"connected_account,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ConnectedAccountsUpdateResponse) GetConnectedAccount() *ConnectedAccount { + if c == nil { + return nil + } + return c.ConnectedAccount +} + +func (c *ConnectedAccountsUpdateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ConnectedAccountsUpdateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ConnectedAccountsUpdateResponse) UnmarshalJSON(data []byte) error { @@ -308,24 +784,29 @@ func (c *ConnectedAccountsUpdateResponse) UnmarshalJSON(data []byte) error { return err } *c = ConnectedAccountsUpdateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ConnectedAccountsUpdateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type ConnectedAccountsUpdateRequest struct { - ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` - AutomaticallyManageNewDevices *bool `json:"automatically_manage_new_devices,omitempty" url:"automatically_manage_new_devices,omitempty"` - CustomMetadata map[string]*ConnectedAccountsUpdateRequestCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` + ConnectedAccountId string `json:"connected_account_id" url:"-"` + AutomaticallyManageNewDevices *bool `json:"automatically_manage_new_devices,omitempty" url:"-"` + CustomMetadata map[string]*ConnectedAccountsUpdateRequestCustomMetadataValue `json:"custom_metadata,omitempty" url:"-"` } diff --git a/connectedaccounts/client.go b/connectedaccounts/client.go index edf4be7..b72ca62 100644 --- a/connectedaccounts/client.go +++ b/connectedaccounts/client.go @@ -3,20 +3,17 @@ package connectedaccounts import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.ConnectedAccountsDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connected_accounts/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connected_accounts/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectedAccountsDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.ConnectedAccount, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connected_accounts/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connected_accounts/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectedAccountsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -166,56 +139,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.ConnectedAccount, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connected_accounts/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connected_accounts/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectedAccountsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -229,56 +190,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*seamapigo.ConnectedAccount, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connected_accounts/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connected_accounts/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectedAccountsUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/connectwebviews/client.go b/connectwebviews/client.go index 5e7e658..fee50e3 100644 --- a/connectwebviews/client.go +++ b/connectwebviews/client.go @@ -3,20 +3,17 @@ package connectwebviews import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.ConnectWebview, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connect_webviews/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connect_webviews/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectWebviewsCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.ConnectWebviewsDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connect_webviews/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connect_webviews/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectWebviewsDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -166,56 +139,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.ConnectWebview, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connect_webviews/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connect_webviews/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectWebviewsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -229,56 +190,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.ConnectWebview, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "connect_webviews/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/connect_webviews/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ConnectWebviewsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/core/api_error.go b/core/api_error.go new file mode 100644 index 0000000..dc4190c --- /dev/null +++ b/core/api_error.go @@ -0,0 +1,42 @@ +package core + +import "fmt" + +// APIError is a lightweight wrapper around the standard error +// interface that preserves the status code from the RPC, if any. +type APIError struct { + err error + + StatusCode int `json:"-"` +} + +// NewAPIError constructs a new API error. +func NewAPIError(statusCode int, err error) *APIError { + return &APIError{ + err: err, + StatusCode: statusCode, + } +} + +// Unwrap returns the underlying error. This also makes the error compatible +// with errors.As and errors.Is. +func (a *APIError) Unwrap() error { + if a == nil { + return nil + } + return a.err +} + +// Error returns the API error's message. +func (a *APIError) Error() string { + if a == nil || (a.err == nil && a.StatusCode == 0) { + return "" + } + if a.err == nil { + return fmt.Sprintf("%d", a.StatusCode) + } + if a.StatusCode == 0 { + return a.err.Error() + } + return fmt.Sprintf("%d: %s", a.StatusCode, a.err.Error()) +} diff --git a/core/http.go b/core/http.go new file mode 100644 index 0000000..b553350 --- /dev/null +++ b/core/http.go @@ -0,0 +1,8 @@ +package core + +import "net/http" + +// HTTPClient is an interface for a subset of the *http.Client. +type HTTPClient interface { + Do(*http.Request) (*http.Response, error) +} diff --git a/core/request_option.go b/core/request_option.go index 0bffde7..cbf4c0c 100644 --- a/core/request_option.go +++ b/core/request_option.go @@ -5,6 +5,7 @@ package core import ( fmt "fmt" http "net/http" + url "net/url" ) // RequestOption adapts the behavior of the client or an individual request. @@ -20,6 +21,8 @@ type RequestOptions struct { BaseURL string HTTPClient HTTPClient HTTPHeader http.Header + BodyProperties map[string]interface{} + QueryParameters url.Values MaxAttempts uint ApiKey string SeamWorkspace string @@ -33,7 +36,9 @@ type RequestOptions struct { // to be used directly; use RequestOption instead. func NewRequestOptions(opts ...RequestOption) *RequestOptions { options := &RequestOptions{ - HTTPHeader: make(http.Header), + HTTPHeader: make(http.Header), + BodyProperties: make(map[string]interface{}), + QueryParameters: make(url.Values), } for _, opt := range opts { opt.applyRequestOptions(options) @@ -58,7 +63,7 @@ func (r *RequestOptions) cloneHeader() http.Header { headers := r.HTTPHeader.Clone() headers.Set("X-Fern-Language", "Go") headers.Set("X-Fern-SDK-Name", "github.com/seamapi/go") - headers.Set("X-Fern-SDK-Version", "v0.3.4") + headers.Set("X-Fern-SDK-Version", "v0.0.18") return headers } @@ -89,6 +94,24 @@ func (h *HTTPHeaderOption) applyRequestOptions(opts *RequestOptions) { opts.HTTPHeader = h.HTTPHeader } +// BodyPropertiesOption implements the RequestOption interface. +type BodyPropertiesOption struct { + BodyProperties map[string]interface{} +} + +func (b *BodyPropertiesOption) applyRequestOptions(opts *RequestOptions) { + opts.BodyProperties = b.BodyProperties +} + +// QueryParametersOption implements the RequestOption interface. +type QueryParametersOption struct { + QueryParameters url.Values +} + +func (q *QueryParametersOption) applyRequestOptions(opts *RequestOptions) { + opts.QueryParameters = q.QueryParameters +} + // MaxAttemptsOption implements the RequestOption interface. type MaxAttemptsOption struct { MaxAttempts uint diff --git a/devices.go b/devices.go index be5016d..07794e4 100644 --- a/devices.go +++ b/devices.go @@ -5,34 +5,34 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type DevicesDeleteRequest struct { - DeviceId string `json:"device_id" url:"device_id"` + DeviceId string `json:"device_id" url:"-"` } type DevicesGetRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` } type DevicesListRequest struct { // List all devices owned by this connected account - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"connect_webview_id,omitempty"` - DeviceType *DeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` - DeviceTypes []DeviceType `json:"device_types,omitempty" url:"device_types,omitempty"` - Manufacturer *Manufacturer `json:"manufacturer,omitempty" url:"manufacturer,omitempty"` - DeviceIds []string `json:"device_ids,omitempty" url:"device_ids,omitempty"` - Limit *float64 `json:"limit,omitempty" url:"limit,omitempty"` - CreatedBefore *time.Time `json:"created_before,omitempty" url:"created_before,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - CustomMetadataHas map[string]*DevicesListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"custom_metadata_has,omitempty"` - IncludeIf []DevicesListRequestIncludeIfItem `json:"include_if,omitempty" url:"include_if,omitempty"` - ExcludeIf []DevicesListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"exclude_if,omitempty"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"-"` + DeviceType *DeviceType `json:"device_type,omitempty" url:"-"` + DeviceTypes []DeviceType `json:"device_types,omitempty" url:"-"` + Manufacturer *Manufacturer `json:"manufacturer,omitempty" url:"-"` + DeviceIds []string `json:"device_ids,omitempty" url:"-"` + Limit *float64 `json:"limit,omitempty" url:"-"` + CreatedBefore *time.Time `json:"created_before,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + CustomMetadataHas map[string]*DevicesListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"-"` + IncludeIf []DevicesListRequestIncludeIfItem `json:"include_if,omitempty" url:"-"` + ExcludeIf []DevicesListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"-"` } func (d *DevicesListRequest) UnmarshalJSON(data []byte) error { @@ -49,22 +49,262 @@ func (d *DevicesListRequest) MarshalJSON() ([]byte, error) { type embed DevicesListRequest var marshaler = struct { embed - CreatedBefore *core.DateTime `json:"created_before,omitempty"` + CreatedBefore *internal.DateTime `json:"created_before,omitempty"` }{ embed: embed(*d), - CreatedBefore: core.NewOptionalDateTime(d.CreatedBefore), + CreatedBefore: internal.NewOptionalDateTime(d.CreatedBefore), } return json.Marshal(marshaler) } type DevicesListDeviceProvidersRequest struct { - ProviderCategory *ProviderCategory `json:"provider_category,omitempty" url:"provider_category,omitempty"` + ProviderCategory *ProviderCategory `json:"provider_category,omitempty" url:"-"` +} + +type DeviceProvider struct { + DeviceProviderName DeviceProviderDeviceProviderName `json:"device_provider_name" url:"device_provider_name"` + DisplayName string `json:"display_name" url:"display_name"` + ImageUrl string `json:"image_url" url:"image_url"` + ProviderCategories []DeviceProviderProviderCategoriesItem `json:"provider_categories,omitempty" url:"provider_categories,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DeviceProvider) GetDeviceProviderName() DeviceProviderDeviceProviderName { + if d == nil { + return "" + } + return d.DeviceProviderName +} + +func (d *DeviceProvider) GetDisplayName() string { + if d == nil { + return "" + } + return d.DisplayName +} + +func (d *DeviceProvider) GetImageUrl() string { + if d == nil { + return "" + } + return d.ImageUrl +} + +func (d *DeviceProvider) GetProviderCategories() []DeviceProviderProviderCategoriesItem { + if d == nil { + return nil + } + return d.ProviderCategories +} + +func (d *DeviceProvider) GetExtraProperties() map[string]interface{} { + return d.extraProperties +} + +func (d *DeviceProvider) UnmarshalJSON(data []byte) error { + type unmarshaler DeviceProvider + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *d = DeviceProvider(value) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) + return nil +} + +func (d *DeviceProvider) String() string { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(d); err == nil { + return value + } + return fmt.Sprintf("%#v", d) +} + +type DeviceProviderDeviceProviderName string + +const ( + DeviceProviderDeviceProviderNameAkuvox DeviceProviderDeviceProviderName = "akuvox" + DeviceProviderDeviceProviderNameAugust DeviceProviderDeviceProviderName = "august" + DeviceProviderDeviceProviderNameAvigilonAlta DeviceProviderDeviceProviderName = "avigilon_alta" + DeviceProviderDeviceProviderNameBrivo DeviceProviderDeviceProviderName = "brivo" + DeviceProviderDeviceProviderNameButterflymx DeviceProviderDeviceProviderName = "butterflymx" + DeviceProviderDeviceProviderNameSchlage DeviceProviderDeviceProviderName = "schlage" + DeviceProviderDeviceProviderNameSmartthings DeviceProviderDeviceProviderName = "smartthings" + DeviceProviderDeviceProviderNameYale DeviceProviderDeviceProviderName = "yale" + DeviceProviderDeviceProviderNameGenie DeviceProviderDeviceProviderName = "genie" + DeviceProviderDeviceProviderNameDoorking DeviceProviderDeviceProviderName = "doorking" + DeviceProviderDeviceProviderNameSalto DeviceProviderDeviceProviderName = "salto" + DeviceProviderDeviceProviderNameLockly DeviceProviderDeviceProviderName = "lockly" + DeviceProviderDeviceProviderNameTtlock DeviceProviderDeviceProviderName = "ttlock" + DeviceProviderDeviceProviderNameLinear DeviceProviderDeviceProviderName = "linear" + DeviceProviderDeviceProviderNameNoiseaware DeviceProviderDeviceProviderName = "noiseaware" + DeviceProviderDeviceProviderNameNuki DeviceProviderDeviceProviderName = "nuki" + DeviceProviderDeviceProviderNameSeamRelayAdmin DeviceProviderDeviceProviderName = "seam_relay_admin" + DeviceProviderDeviceProviderNameIgloo DeviceProviderDeviceProviderName = "igloo" + DeviceProviderDeviceProviderNameKwikset DeviceProviderDeviceProviderName = "kwikset" + DeviceProviderDeviceProviderNameMinut DeviceProviderDeviceProviderName = "minut" + DeviceProviderDeviceProviderNameMy2N DeviceProviderDeviceProviderName = "my_2n" + DeviceProviderDeviceProviderNameControlbyweb DeviceProviderDeviceProviderName = "controlbyweb" + DeviceProviderDeviceProviderNameNest DeviceProviderDeviceProviderName = "nest" + DeviceProviderDeviceProviderNameIgloohome DeviceProviderDeviceProviderName = "igloohome" + DeviceProviderDeviceProviderNameEcobee DeviceProviderDeviceProviderName = "ecobee" + DeviceProviderDeviceProviderNameHubitat DeviceProviderDeviceProviderName = "hubitat" + DeviceProviderDeviceProviderNameFourSuites DeviceProviderDeviceProviderName = "four_suites" + DeviceProviderDeviceProviderNameDormakabaOracode DeviceProviderDeviceProviderName = "dormakaba_oracode" + DeviceProviderDeviceProviderNamePti DeviceProviderDeviceProviderName = "pti" + DeviceProviderDeviceProviderNameWyze DeviceProviderDeviceProviderName = "wyze" + DeviceProviderDeviceProviderNameSeamPassport DeviceProviderDeviceProviderName = "seam_passport" + DeviceProviderDeviceProviderNameVisionline DeviceProviderDeviceProviderName = "visionline" + DeviceProviderDeviceProviderNameAssaAbloyCredentialService DeviceProviderDeviceProviderName = "assa_abloy_credential_service" + DeviceProviderDeviceProviderNameSeamBridge DeviceProviderDeviceProviderName = "seam_bridge" + DeviceProviderDeviceProviderNameTedee DeviceProviderDeviceProviderName = "tedee" + DeviceProviderDeviceProviderNameHoneywellResideo DeviceProviderDeviceProviderName = "honeywell_resideo" + DeviceProviderDeviceProviderNameLatch DeviceProviderDeviceProviderName = "latch" +) + +func NewDeviceProviderDeviceProviderNameFromString(s string) (DeviceProviderDeviceProviderName, error) { + switch s { + case "akuvox": + return DeviceProviderDeviceProviderNameAkuvox, nil + case "august": + return DeviceProviderDeviceProviderNameAugust, nil + case "avigilon_alta": + return DeviceProviderDeviceProviderNameAvigilonAlta, nil + case "brivo": + return DeviceProviderDeviceProviderNameBrivo, nil + case "butterflymx": + return DeviceProviderDeviceProviderNameButterflymx, nil + case "schlage": + return DeviceProviderDeviceProviderNameSchlage, nil + case "smartthings": + return DeviceProviderDeviceProviderNameSmartthings, nil + case "yale": + return DeviceProviderDeviceProviderNameYale, nil + case "genie": + return DeviceProviderDeviceProviderNameGenie, nil + case "doorking": + return DeviceProviderDeviceProviderNameDoorking, nil + case "salto": + return DeviceProviderDeviceProviderNameSalto, nil + case "lockly": + return DeviceProviderDeviceProviderNameLockly, nil + case "ttlock": + return DeviceProviderDeviceProviderNameTtlock, nil + case "linear": + return DeviceProviderDeviceProviderNameLinear, nil + case "noiseaware": + return DeviceProviderDeviceProviderNameNoiseaware, nil + case "nuki": + return DeviceProviderDeviceProviderNameNuki, nil + case "seam_relay_admin": + return DeviceProviderDeviceProviderNameSeamRelayAdmin, nil + case "igloo": + return DeviceProviderDeviceProviderNameIgloo, nil + case "kwikset": + return DeviceProviderDeviceProviderNameKwikset, nil + case "minut": + return DeviceProviderDeviceProviderNameMinut, nil + case "my_2n": + return DeviceProviderDeviceProviderNameMy2N, nil + case "controlbyweb": + return DeviceProviderDeviceProviderNameControlbyweb, nil + case "nest": + return DeviceProviderDeviceProviderNameNest, nil + case "igloohome": + return DeviceProviderDeviceProviderNameIgloohome, nil + case "ecobee": + return DeviceProviderDeviceProviderNameEcobee, nil + case "hubitat": + return DeviceProviderDeviceProviderNameHubitat, nil + case "four_suites": + return DeviceProviderDeviceProviderNameFourSuites, nil + case "dormakaba_oracode": + return DeviceProviderDeviceProviderNameDormakabaOracode, nil + case "pti": + return DeviceProviderDeviceProviderNamePti, nil + case "wyze": + return DeviceProviderDeviceProviderNameWyze, nil + case "seam_passport": + return DeviceProviderDeviceProviderNameSeamPassport, nil + case "visionline": + return DeviceProviderDeviceProviderNameVisionline, nil + case "assa_abloy_credential_service": + return DeviceProviderDeviceProviderNameAssaAbloyCredentialService, nil + case "seam_bridge": + return DeviceProviderDeviceProviderNameSeamBridge, nil + case "tedee": + return DeviceProviderDeviceProviderNameTedee, nil + case "honeywell_resideo": + return DeviceProviderDeviceProviderNameHoneywellResideo, nil + case "latch": + return DeviceProviderDeviceProviderNameLatch, nil + } + var t DeviceProviderDeviceProviderName + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (d DeviceProviderDeviceProviderName) Ptr() *DeviceProviderDeviceProviderName { + return &d +} + +type DeviceProviderProviderCategoriesItem string + +const ( + DeviceProviderProviderCategoriesItemStable DeviceProviderProviderCategoriesItem = "stable" + DeviceProviderProviderCategoriesItemConsumerSmartlocks DeviceProviderProviderCategoriesItem = "consumer_smartlocks" + DeviceProviderProviderCategoriesItemThermostats DeviceProviderProviderCategoriesItem = "thermostats" + DeviceProviderProviderCategoriesItemNoiseSensors DeviceProviderProviderCategoriesItem = "noise_sensors" + DeviceProviderProviderCategoriesItemAccessControlSystems DeviceProviderProviderCategoriesItem = "access_control_systems" +) + +func NewDeviceProviderProviderCategoriesItemFromString(s string) (DeviceProviderProviderCategoriesItem, error) { + switch s { + case "stable": + return DeviceProviderProviderCategoriesItemStable, nil + case "consumer_smartlocks": + return DeviceProviderProviderCategoriesItemConsumerSmartlocks, nil + case "thermostats": + return DeviceProviderProviderCategoriesItemThermostats, nil + case "noise_sensors": + return DeviceProviderProviderCategoriesItemNoiseSensors, nil + case "access_control_systems": + return DeviceProviderProviderCategoriesItemAccessControlSystems, nil + } + var t DeviceProviderProviderCategoriesItem + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (d DeviceProviderProviderCategoriesItem) Ptr() *DeviceProviderProviderCategoriesItem { + return &d } type DevicesDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicesDeleteResponse) GetOk() bool { + if d == nil { + return false + } + return d.Ok +} + +func (d *DevicesDeleteResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicesDeleteResponse) UnmarshalJSON(data []byte) error { @@ -74,17 +314,22 @@ func (d *DevicesDeleteResponse) UnmarshalJSON(data []byte) error { return err } *d = DevicesDeleteResponse(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicesDeleteResponse) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -94,7 +339,26 @@ type DevicesGetResponse struct { Device *Device `json:"device,omitempty" url:"device,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicesGetResponse) GetDevice() *Device { + if d == nil { + return nil + } + return d.Device +} + +func (d *DevicesGetResponse) GetOk() bool { + if d == nil { + return false + } + return d.Ok +} + +func (d *DevicesGetResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicesGetResponse) UnmarshalJSON(data []byte) error { @@ -104,17 +368,22 @@ func (d *DevicesGetResponse) UnmarshalJSON(data []byte) error { return err } *d = DevicesGetResponse(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicesGetResponse) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -124,7 +393,26 @@ type DevicesListDeviceProvidersResponse struct { DeviceProviders []*DeviceProvider `json:"device_providers,omitempty" url:"device_providers,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicesListDeviceProvidersResponse) GetDeviceProviders() []*DeviceProvider { + if d == nil { + return nil + } + return d.DeviceProviders +} + +func (d *DevicesListDeviceProvidersResponse) GetOk() bool { + if d == nil { + return false + } + return d.Ok +} + +func (d *DevicesListDeviceProvidersResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicesListDeviceProvidersResponse) UnmarshalJSON(data []byte) error { @@ -134,46 +422,66 @@ func (d *DevicesListDeviceProvidersResponse) UnmarshalJSON(data []byte) error { return err } *d = DevicesListDeviceProvidersResponse(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicesListDeviceProvidersResponse) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) } type DevicesListRequestCustomMetadataHasValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewDevicesListRequestCustomMetadataHasValueFromString(value string) *DevicesListRequestCustomMetadataHasValue { - return &DevicesListRequestCustomMetadataHasValue{typeName: "string", String: value} + return &DevicesListRequestCustomMetadataHasValue{typ: "String", String: value} } func NewDevicesListRequestCustomMetadataHasValueFromBoolean(value bool) *DevicesListRequestCustomMetadataHasValue { - return &DevicesListRequestCustomMetadataHasValue{typeName: "boolean", Boolean: value} + return &DevicesListRequestCustomMetadataHasValue{typ: "Boolean", Boolean: value} +} + +func (d *DevicesListRequestCustomMetadataHasValue) GetString() string { + if d == nil { + return "" + } + return d.String +} + +func (d *DevicesListRequestCustomMetadataHasValue) GetBoolean() bool { + if d == nil { + return false + } + return d.Boolean } func (d *DevicesListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - d.typeName = "string" + d.typ = "String" d.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - d.typeName = "boolean" + d.typ = "Boolean" d.Boolean = valueBoolean return nil } @@ -181,14 +489,13 @@ func (d *DevicesListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) er } func (d DevicesListRequestCustomMetadataHasValue) MarshalJSON() ([]byte, error) { - switch d.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "string": + if d.typ == "String" || d.String != "" { return json.Marshal(d.String) - case "boolean": + } + if d.typ == "Boolean" || d.Boolean != false { return json.Marshal(d.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", d) } type DevicesListRequestCustomMetadataHasValueVisitor interface { @@ -197,14 +504,13 @@ type DevicesListRequestCustomMetadataHasValueVisitor interface { } func (d *DevicesListRequestCustomMetadataHasValue) Accept(visitor DevicesListRequestCustomMetadataHasValueVisitor) error { - switch d.typeName { - default: - return fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "string": + if d.typ == "String" || d.String != "" { return visitor.VisitString(d.String) - case "boolean": + } + if d.typ == "Boolean" || d.Boolean != false { return visitor.VisitBoolean(d.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", d) } type DevicesListRequestExcludeIfItem string @@ -215,6 +521,8 @@ const ( DevicesListRequestExcludeIfItemCanProgramOfflineAccessCodes DevicesListRequestExcludeIfItem = "can_program_offline_access_codes" DevicesListRequestExcludeIfItemCanProgramOnlineAccessCodes DevicesListRequestExcludeIfItem = "can_program_online_access_codes" DevicesListRequestExcludeIfItemCanSimulateRemoval DevicesListRequestExcludeIfItem = "can_simulate_removal" + DevicesListRequestExcludeIfItemCanSimulateConnection DevicesListRequestExcludeIfItem = "can_simulate_connection" + DevicesListRequestExcludeIfItemCanSimulateDisconnection DevicesListRequestExcludeIfItem = "can_simulate_disconnection" ) func NewDevicesListRequestExcludeIfItemFromString(s string) (DevicesListRequestExcludeIfItem, error) { @@ -229,6 +537,10 @@ func NewDevicesListRequestExcludeIfItemFromString(s string) (DevicesListRequestE return DevicesListRequestExcludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return DevicesListRequestExcludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return DevicesListRequestExcludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return DevicesListRequestExcludeIfItemCanSimulateDisconnection, nil } var t DevicesListRequestExcludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -246,6 +558,8 @@ const ( DevicesListRequestIncludeIfItemCanProgramOfflineAccessCodes DevicesListRequestIncludeIfItem = "can_program_offline_access_codes" DevicesListRequestIncludeIfItemCanProgramOnlineAccessCodes DevicesListRequestIncludeIfItem = "can_program_online_access_codes" DevicesListRequestIncludeIfItemCanSimulateRemoval DevicesListRequestIncludeIfItem = "can_simulate_removal" + DevicesListRequestIncludeIfItemCanSimulateConnection DevicesListRequestIncludeIfItem = "can_simulate_connection" + DevicesListRequestIncludeIfItemCanSimulateDisconnection DevicesListRequestIncludeIfItem = "can_simulate_disconnection" ) func NewDevicesListRequestIncludeIfItemFromString(s string) (DevicesListRequestIncludeIfItem, error) { @@ -260,6 +574,10 @@ func NewDevicesListRequestIncludeIfItemFromString(s string) (DevicesListRequestI return DevicesListRequestIncludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return DevicesListRequestIncludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return DevicesListRequestIncludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return DevicesListRequestIncludeIfItemCanSimulateDisconnection, nil } var t DevicesListRequestIncludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -273,7 +591,26 @@ type DevicesListResponse struct { Devices []*Device `json:"devices,omitempty" url:"devices,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicesListResponse) GetDevices() []*Device { + if d == nil { + return nil + } + return d.Devices +} + +func (d *DevicesListResponse) GetOk() bool { + if d == nil { + return false + } + return d.Ok +} + +func (d *DevicesListResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicesListResponse) UnmarshalJSON(data []byte) error { @@ -283,99 +620,113 @@ func (d *DevicesListResponse) UnmarshalJSON(data []byte) error { return err } *d = DevicesListResponse(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicesListResponse) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) } type DevicesUpdateRequestCustomMetadataValue struct { - typeName string - String string - Boolean bool - StringOptional *string + String string + Boolean bool + + typ string } func NewDevicesUpdateRequestCustomMetadataValueFromString(value string) *DevicesUpdateRequestCustomMetadataValue { - return &DevicesUpdateRequestCustomMetadataValue{typeName: "string", String: value} + return &DevicesUpdateRequestCustomMetadataValue{typ: "String", String: value} } func NewDevicesUpdateRequestCustomMetadataValueFromBoolean(value bool) *DevicesUpdateRequestCustomMetadataValue { - return &DevicesUpdateRequestCustomMetadataValue{typeName: "boolean", Boolean: value} + return &DevicesUpdateRequestCustomMetadataValue{typ: "Boolean", Boolean: value} +} + +func (d *DevicesUpdateRequestCustomMetadataValue) GetString() string { + if d == nil { + return "" + } + return d.String } -func NewDevicesUpdateRequestCustomMetadataValueFromStringOptional(value *string) *DevicesUpdateRequestCustomMetadataValue { - return &DevicesUpdateRequestCustomMetadataValue{typeName: "stringOptional", StringOptional: value} +func (d *DevicesUpdateRequestCustomMetadataValue) GetBoolean() bool { + if d == nil { + return false + } + return d.Boolean } func (d *DevicesUpdateRequestCustomMetadataValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - d.typeName = "string" + d.typ = "String" d.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - d.typeName = "boolean" + d.typ = "Boolean" d.Boolean = valueBoolean return nil } - var valueStringOptional *string - if err := json.Unmarshal(data, &valueStringOptional); err == nil { - d.typeName = "stringOptional" - d.StringOptional = valueStringOptional - return nil - } return fmt.Errorf("%s cannot be deserialized as a %T", data, d) } func (d DevicesUpdateRequestCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch d.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "string": + if d.typ == "String" || d.String != "" { return json.Marshal(d.String) - case "boolean": + } + if d.typ == "Boolean" || d.Boolean != false { return json.Marshal(d.Boolean) - case "stringOptional": - return json.Marshal(d.StringOptional) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", d) } type DevicesUpdateRequestCustomMetadataValueVisitor interface { VisitString(string) error VisitBoolean(bool) error - VisitStringOptional(*string) error } func (d *DevicesUpdateRequestCustomMetadataValue) Accept(visitor DevicesUpdateRequestCustomMetadataValueVisitor) error { - switch d.typeName { - default: - return fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "string": + if d.typ == "String" || d.String != "" { return visitor.VisitString(d.String) - case "boolean": + } + if d.typ == "Boolean" || d.Boolean != false { return visitor.VisitBoolean(d.Boolean) - case "stringOptional": - return visitor.VisitStringOptional(d.StringOptional) } + return fmt.Errorf("type %T does not include a non-empty union type", d) } type DevicesUpdateRequestProperties struct { Name *string `json:"name,omitempty" url:"name,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicesUpdateRequestProperties) GetName() *string { + if d == nil { + return nil + } + return d.Name +} + +func (d *DevicesUpdateRequestProperties) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicesUpdateRequestProperties) UnmarshalJSON(data []byte) error { @@ -385,17 +736,22 @@ func (d *DevicesUpdateRequestProperties) UnmarshalJSON(data []byte) error { return err } *d = DevicesUpdateRequestProperties(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicesUpdateRequestProperties) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -404,7 +760,19 @@ func (d *DevicesUpdateRequestProperties) String() string { type DevicesUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicesUpdateResponse) GetOk() bool { + if d == nil { + return false + } + return d.Ok +} + +func (d *DevicesUpdateResponse) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicesUpdateResponse) UnmarshalJSON(data []byte) error { @@ -414,26 +782,31 @@ func (d *DevicesUpdateResponse) UnmarshalJSON(data []byte) error { return err } *d = DevicesUpdateResponse(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicesUpdateResponse) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) } type DevicesUpdateRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Properties *DevicesUpdateRequestProperties `json:"properties,omitempty" url:"properties,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - IsManaged *bool `json:"is_managed,omitempty" url:"is_managed,omitempty"` - CustomMetadata map[string]*DevicesUpdateRequestCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` + DeviceId string `json:"device_id" url:"-"` + Properties *DevicesUpdateRequestProperties `json:"properties,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + IsManaged *bool `json:"is_managed,omitempty" url:"-"` + CustomMetadata map[string]*DevicesUpdateRequestCustomMetadataValue `json:"custom_metadata,omitempty" url:"-"` } diff --git a/devices/client/client.go b/devices/client/client.go index c244c91..9e1bdd0 100644 --- a/devices/client/client.go +++ b/devices/client/client.go @@ -3,22 +3,19 @@ package client import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" simulate "github.com/seamapi/go/devices/simulate" unmanaged "github.com/seamapi/go/devices/unmanaged" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header Simulate *simulate.Client @@ -29,8 +26,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -47,56 +44,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.DevicesDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.DevicesDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -110,56 +95,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.DevicesGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -173,56 +146,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.DevicesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -236,56 +197,44 @@ func (c *Client) ListDeviceProviders( opts ...option.RequestOption, ) ([]*seamapigo.DeviceProvider, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/list_device_providers" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/list_device_providers" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.DevicesListDeviceProvidersResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -299,56 +248,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*seamapigo.DevicesUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.DevicesUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/devices/simulate.go b/devices/simulate.go index 85461b6..7257ad6 100644 --- a/devices/simulate.go +++ b/devices/simulate.go @@ -5,17 +5,129 @@ package devices import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) +type SimulateConnectRequest struct { + DeviceId string `json:"device_id" url:"-"` +} + +type SimulateDisconnectRequest struct { + DeviceId string `json:"device_id" url:"-"` +} + type SimulateRemoveRequest struct { - DeviceId string `json:"device_id" url:"device_id"` + DeviceId string `json:"device_id" url:"-"` +} + +type SimulateConnectResponse struct { + Ok bool `json:"ok" url:"ok"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateConnectResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SimulateConnectResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties +} + +func (s *SimulateConnectResponse) UnmarshalJSON(data []byte) error { + type unmarshaler SimulateConnectResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *s = SimulateConnectResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) + return nil +} + +func (s *SimulateConnectResponse) String() string { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(s); err == nil { + return value + } + return fmt.Sprintf("%#v", s) +} + +type SimulateDisconnectResponse struct { + Ok bool `json:"ok" url:"ok"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateDisconnectResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SimulateDisconnectResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties +} + +func (s *SimulateDisconnectResponse) UnmarshalJSON(data []byte) error { + type unmarshaler SimulateDisconnectResponse + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *s = SimulateDisconnectResponse(value) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) + return nil +} + +func (s *SimulateDisconnectResponse) String() string { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(s); err == nil { + return value + } + return fmt.Sprintf("%#v", s) } type SimulateRemoveResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateRemoveResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SimulateRemoveResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SimulateRemoveResponse) UnmarshalJSON(data []byte) error { @@ -25,17 +137,22 @@ func (s *SimulateRemoveResponse) UnmarshalJSON(data []byte) error { return err } *s = SimulateRemoveResponse(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SimulateRemoveResponse) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) diff --git a/devices/simulate/client.go b/devices/simulate/client.go index 59d0edd..3b796a1 100644 --- a/devices/simulate/client.go +++ b/devices/simulate/client.go @@ -3,21 +3,18 @@ package simulate import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" devices "github.com/seamapi/go/devices" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -35,62 +32,152 @@ func NewClient(opts ...option.RequestOption) *Client { } } -func (c *Client) Remove( +func (c *Client) Connect( ctx context.Context, - request *devices.SimulateRemoveRequest, + request *devices.SimulateConnectRequest, opts ...option.RequestOption, -) (*devices.SimulateRemoveResponse, error) { +) (*devices.SimulateConnectResponse, error) { options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/simulate/connect" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, + } + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, + } + }, + } - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL + var response *devices.SimulateConnectResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), + }, + ); err != nil { + return nil, err } - if options.BaseURL != "" { - baseURL = options.BaseURL + return response, nil +} + +func (c *Client) Disconnect( + ctx context.Context, + request *devices.SimulateDisconnectRequest, + opts ...option.RequestOption, +) (*devices.SimulateDisconnectResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/simulate/disconnect" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, + } + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, + } + }, } - endpointURL := baseURL + "/" + "devices/simulate/remove" - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) + var response *devices.SimulateDisconnectResponse + if err := c.caller.Call( + ctx, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), + }, + ); err != nil { + return nil, err + } + return response, nil +} - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError +func (c *Client) Remove( + ctx context.Context, + request *devices.SimulateRemoveRequest, + opts ...option.RequestOption, +) (*devices.SimulateRemoveResponse, error) { + options := core.NewRequestOptions(opts...) + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/simulate/remove" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *devices.SimulateRemoveResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/devices/unmanaged.go b/devices/unmanaged.go index 67b8e46..c74e209 100644 --- a/devices/unmanaged.go +++ b/devices/unmanaged.go @@ -6,30 +6,30 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type UnmanagedGetRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` } type UnmanagedListRequest struct { // List all devices owned by this connected account - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"connect_webview_id,omitempty"` - DeviceType *seamapigo.DeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` - DeviceTypes []seamapigo.DeviceType `json:"device_types,omitempty" url:"device_types,omitempty"` - Manufacturer *seamapigo.Manufacturer `json:"manufacturer,omitempty" url:"manufacturer,omitempty"` - DeviceIds []string `json:"device_ids,omitempty" url:"device_ids,omitempty"` - Limit *float64 `json:"limit,omitempty" url:"limit,omitempty"` - CreatedBefore *time.Time `json:"created_before,omitempty" url:"created_before,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - CustomMetadataHas map[string]*UnmanagedListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"custom_metadata_has,omitempty"` - IncludeIf []UnmanagedListRequestIncludeIfItem `json:"include_if,omitempty" url:"include_if,omitempty"` - ExcludeIf []UnmanagedListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"exclude_if,omitempty"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"-"` + DeviceType *seamapigo.DeviceType `json:"device_type,omitempty" url:"-"` + DeviceTypes []seamapigo.DeviceType `json:"device_types,omitempty" url:"-"` + Manufacturer *seamapigo.Manufacturer `json:"manufacturer,omitempty" url:"-"` + DeviceIds []string `json:"device_ids,omitempty" url:"-"` + Limit *float64 `json:"limit,omitempty" url:"-"` + CreatedBefore *time.Time `json:"created_before,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + CustomMetadataHas map[string]*UnmanagedListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"-"` + IncludeIf []UnmanagedListRequestIncludeIfItem `json:"include_if,omitempty" url:"-"` + ExcludeIf []UnmanagedListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"-"` } func (u *UnmanagedListRequest) UnmarshalJSON(data []byte) error { @@ -46,10 +46,10 @@ func (u *UnmanagedListRequest) MarshalJSON() ([]byte, error) { type embed UnmanagedListRequest var marshaler = struct { embed - CreatedBefore *core.DateTime `json:"created_before,omitempty"` + CreatedBefore *internal.DateTime `json:"created_before,omitempty"` }{ embed: embed(*u), - CreatedBefore: core.NewOptionalDateTime(u.CreatedBefore), + CreatedBefore: internal.NewOptionalDateTime(u.CreatedBefore), } return json.Marshal(marshaler) } @@ -58,7 +58,26 @@ type UnmanagedGetResponse struct { Device *seamapigo.UnmanagedDevice `json:"device,omitempty" url:"device,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedGetResponse) GetDevice() *seamapigo.UnmanagedDevice { + if u == nil { + return nil + } + return u.Device +} + +func (u *UnmanagedGetResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedGetResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedGetResponse) UnmarshalJSON(data []byte) error { @@ -68,46 +87,66 @@ func (u *UnmanagedGetResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedGetResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedGetResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UnmanagedListRequestCustomMetadataHasValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewUnmanagedListRequestCustomMetadataHasValueFromString(value string) *UnmanagedListRequestCustomMetadataHasValue { - return &UnmanagedListRequestCustomMetadataHasValue{typeName: "string", String: value} + return &UnmanagedListRequestCustomMetadataHasValue{typ: "String", String: value} } func NewUnmanagedListRequestCustomMetadataHasValueFromBoolean(value bool) *UnmanagedListRequestCustomMetadataHasValue { - return &UnmanagedListRequestCustomMetadataHasValue{typeName: "boolean", Boolean: value} + return &UnmanagedListRequestCustomMetadataHasValue{typ: "Boolean", Boolean: value} +} + +func (u *UnmanagedListRequestCustomMetadataHasValue) GetString() string { + if u == nil { + return "" + } + return u.String +} + +func (u *UnmanagedListRequestCustomMetadataHasValue) GetBoolean() bool { + if u == nil { + return false + } + return u.Boolean } func (u *UnmanagedListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - u.typeName = "string" + u.typ = "String" u.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - u.typeName = "boolean" + u.typ = "Boolean" u.Boolean = valueBoolean return nil } @@ -115,14 +154,13 @@ func (u *UnmanagedListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) } func (u UnmanagedListRequestCustomMetadataHasValue) MarshalJSON() ([]byte, error) { - switch u.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", u.typeName, u) - case "string": + if u.typ == "String" || u.String != "" { return json.Marshal(u.String) - case "boolean": + } + if u.typ == "Boolean" || u.Boolean != false { return json.Marshal(u.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", u) } type UnmanagedListRequestCustomMetadataHasValueVisitor interface { @@ -131,14 +169,13 @@ type UnmanagedListRequestCustomMetadataHasValueVisitor interface { } func (u *UnmanagedListRequestCustomMetadataHasValue) Accept(visitor UnmanagedListRequestCustomMetadataHasValueVisitor) error { - switch u.typeName { - default: - return fmt.Errorf("invalid type %s in %T", u.typeName, u) - case "string": + if u.typ == "String" || u.String != "" { return visitor.VisitString(u.String) - case "boolean": + } + if u.typ == "Boolean" || u.Boolean != false { return visitor.VisitBoolean(u.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", u) } type UnmanagedListRequestExcludeIfItem string @@ -149,6 +186,8 @@ const ( UnmanagedListRequestExcludeIfItemCanProgramOfflineAccessCodes UnmanagedListRequestExcludeIfItem = "can_program_offline_access_codes" UnmanagedListRequestExcludeIfItemCanProgramOnlineAccessCodes UnmanagedListRequestExcludeIfItem = "can_program_online_access_codes" UnmanagedListRequestExcludeIfItemCanSimulateRemoval UnmanagedListRequestExcludeIfItem = "can_simulate_removal" + UnmanagedListRequestExcludeIfItemCanSimulateConnection UnmanagedListRequestExcludeIfItem = "can_simulate_connection" + UnmanagedListRequestExcludeIfItemCanSimulateDisconnection UnmanagedListRequestExcludeIfItem = "can_simulate_disconnection" ) func NewUnmanagedListRequestExcludeIfItemFromString(s string) (UnmanagedListRequestExcludeIfItem, error) { @@ -163,6 +202,10 @@ func NewUnmanagedListRequestExcludeIfItemFromString(s string) (UnmanagedListRequ return UnmanagedListRequestExcludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return UnmanagedListRequestExcludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return UnmanagedListRequestExcludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return UnmanagedListRequestExcludeIfItemCanSimulateDisconnection, nil } var t UnmanagedListRequestExcludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -180,6 +223,8 @@ const ( UnmanagedListRequestIncludeIfItemCanProgramOfflineAccessCodes UnmanagedListRequestIncludeIfItem = "can_program_offline_access_codes" UnmanagedListRequestIncludeIfItemCanProgramOnlineAccessCodes UnmanagedListRequestIncludeIfItem = "can_program_online_access_codes" UnmanagedListRequestIncludeIfItemCanSimulateRemoval UnmanagedListRequestIncludeIfItem = "can_simulate_removal" + UnmanagedListRequestIncludeIfItemCanSimulateConnection UnmanagedListRequestIncludeIfItem = "can_simulate_connection" + UnmanagedListRequestIncludeIfItemCanSimulateDisconnection UnmanagedListRequestIncludeIfItem = "can_simulate_disconnection" ) func NewUnmanagedListRequestIncludeIfItemFromString(s string) (UnmanagedListRequestIncludeIfItem, error) { @@ -194,6 +239,10 @@ func NewUnmanagedListRequestIncludeIfItemFromString(s string) (UnmanagedListRequ return UnmanagedListRequestIncludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return UnmanagedListRequestIncludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return UnmanagedListRequestIncludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return UnmanagedListRequestIncludeIfItemCanSimulateDisconnection, nil } var t UnmanagedListRequestIncludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -207,7 +256,26 @@ type UnmanagedListResponse struct { Devices []*seamapigo.UnmanagedDevice `json:"devices,omitempty" url:"devices,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedListResponse) GetDevices() []*seamapigo.UnmanagedDevice { + if u == nil { + return nil + } + return u.Devices +} + +func (u *UnmanagedListResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedListResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedListResponse) UnmarshalJSON(data []byte) error { @@ -217,17 +285,22 @@ func (u *UnmanagedListResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedListResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedListResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -236,7 +309,19 @@ func (u *UnmanagedListResponse) String() string { type UnmanagedUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedUpdateResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UnmanagedUpdateResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedUpdateResponse) UnmarshalJSON(data []byte) error { @@ -246,23 +331,28 @@ func (u *UnmanagedUpdateResponse) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedUpdateResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedUpdateResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UnmanagedUpdateRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - IsManaged bool `json:"is_managed" url:"is_managed"` + DeviceId string `json:"device_id" url:"-"` + IsManaged bool `json:"is_managed" url:"-"` } diff --git a/devices/unmanaged/client.go b/devices/unmanaged/client.go index 7bfc671..bb623c2 100644 --- a/devices/unmanaged/client.go +++ b/devices/unmanaged/client.go @@ -3,21 +3,18 @@ package unmanaged import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" devices "github.com/seamapi/go/devices" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.UnmanagedDevice, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/unmanaged/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/unmanaged/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *devices.UnmanagedGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.UnmanagedDevice, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/unmanaged/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/unmanaged/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *devices.UnmanagedListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*devices.UnmanagedUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "devices/unmanaged/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/devices/unmanaged/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *devices.UnmanagedUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/errors.go b/errors.go index 26ee4dd..f08834b 100644 --- a/errors.go +++ b/errors.go @@ -7,6 +7,7 @@ import ( core "github.com/seamapi/go/core" ) +// Bad Request type BadRequestError struct { *core.APIError Body interface{} @@ -30,6 +31,7 @@ func (b *BadRequestError) Unwrap() error { return b.APIError } +// Unauthorized type UnauthorizedError struct { *core.APIError Body interface{} diff --git a/events.go b/events.go index 3a3d378..7e2a614 100644 --- a/events.go +++ b/events.go @@ -5,27 +5,346 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type EventsGetRequest struct { - EventId *string `json:"event_id,omitempty" url:"event_id,omitempty"` - EventType *string `json:"event_type,omitempty" url:"event_type,omitempty"` - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` + EventId *string `json:"event_id,omitempty" url:"-"` + EventType *string `json:"event_type,omitempty" url:"-"` + DeviceId *string `json:"device_id,omitempty" url:"-"` } type EventsListRequest struct { - Since *string `json:"since,omitempty" url:"since,omitempty"` - Between []*EventsListRequestBetweenItem `json:"between,omitempty" url:"between,omitempty"` - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - DeviceIds []string `json:"device_ids,omitempty" url:"device_ids,omitempty"` - AccessCodeId *string `json:"access_code_id,omitempty" url:"access_code_id,omitempty"` - AccessCodeIds []string `json:"access_code_ids,omitempty" url:"access_code_ids,omitempty"` - EventType *EventType `json:"event_type,omitempty" url:"event_type,omitempty"` - EventTypes []EventType `json:"event_types,omitempty" url:"event_types,omitempty"` - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - Limit *float64 `json:"limit,omitempty" url:"limit,omitempty"` + Since *string `json:"since,omitempty" url:"-"` + Between []*EventsListRequestBetweenItem `json:"between,omitempty" url:"-"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + DeviceIds []string `json:"device_ids,omitempty" url:"-"` + AccessCodeId *string `json:"access_code_id,omitempty" url:"-"` + AccessCodeIds []string `json:"access_code_ids,omitempty" url:"-"` + EventType *EventType `json:"event_type,omitempty" url:"-"` + EventTypes []EventType `json:"event_types,omitempty" url:"-"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"-"` + Limit *float64 `json:"limit,omitempty" url:"-"` +} + +type Event struct { + EventId string `json:"event_id" url:"event_id"` + DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` + ActionAttemptId *string `json:"action_attempt_id,omitempty" url:"action_attempt_id,omitempty"` + AcsCredentialId *string `json:"acs_credential_id,omitempty" url:"acs_credential_id,omitempty"` + AcsUserId *string `json:"acs_user_id,omitempty" url:"acs_user_id,omitempty"` + AcsSystemId *string `json:"acs_system_id,omitempty" url:"acs_system_id,omitempty"` + ClientSessionId *string `json:"client_session_id,omitempty" url:"client_session_id,omitempty"` + EnrollmentAutomationId *string `json:"enrollment_automation_id,omitempty" url:"enrollment_automation_id,omitempty"` + EventType string `json:"event_type" url:"event_type"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + OccurredAt time.Time `json:"occurred_at" url:"occurred_at"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *Event) GetEventId() string { + if e == nil { + return "" + } + return e.EventId +} + +func (e *Event) GetDeviceId() *string { + if e == nil { + return nil + } + return e.DeviceId +} + +func (e *Event) GetActionAttemptId() *string { + if e == nil { + return nil + } + return e.ActionAttemptId +} + +func (e *Event) GetAcsCredentialId() *string { + if e == nil { + return nil + } + return e.AcsCredentialId +} + +func (e *Event) GetAcsUserId() *string { + if e == nil { + return nil + } + return e.AcsUserId +} + +func (e *Event) GetAcsSystemId() *string { + if e == nil { + return nil + } + return e.AcsSystemId +} + +func (e *Event) GetClientSessionId() *string { + if e == nil { + return nil + } + return e.ClientSessionId +} + +func (e *Event) GetEnrollmentAutomationId() *string { + if e == nil { + return nil + } + return e.EnrollmentAutomationId +} + +func (e *Event) GetEventType() string { + if e == nil { + return "" + } + return e.EventType +} + +func (e *Event) GetWorkspaceId() string { + if e == nil { + return "" + } + return e.WorkspaceId +} + +func (e *Event) GetCreatedAt() time.Time { + if e == nil { + return time.Time{} + } + return e.CreatedAt +} + +func (e *Event) GetOccurredAt() time.Time { + if e == nil { + return time.Time{} + } + return e.OccurredAt +} + +func (e *Event) GetExtraProperties() map[string]interface{} { + return e.extraProperties +} + +func (e *Event) UnmarshalJSON(data []byte) error { + type embed Event + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + OccurredAt *internal.DateTime `json:"occurred_at"` + }{ + embed: embed(*e), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *e = Event(unmarshaler.embed) + e.CreatedAt = unmarshaler.CreatedAt.Time() + e.OccurredAt = unmarshaler.OccurredAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) + return nil +} + +func (e *Event) MarshalJSON() ([]byte, error) { + type embed Event + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + OccurredAt *internal.DateTime `json:"occurred_at"` + }{ + embed: embed(*e), + CreatedAt: internal.NewDateTime(e.CreatedAt), + OccurredAt: internal.NewDateTime(e.OccurredAt), + } + return json.Marshal(marshaler) +} + +func (e *Event) String() string { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(e); err == nil { + return value + } + return fmt.Sprintf("%#v", e) +} + +type EventType string + +const ( + EventTypeDeviceConnected EventType = "device.connected" + EventTypeDeviceUnmanagedConnected EventType = "device.unmanaged.connected" + EventTypeDeviceDisconnected EventType = "device.disconnected" + EventTypeDeviceUnmanagedDisconnected EventType = "device.unmanaged.disconnected" + EventTypeDeviceConvertedToUnmanaged EventType = "device.converted_to_unmanaged" + EventTypeDeviceUnmanagedConvertedToManaged EventType = "device.unmanaged.converted_to_managed" + EventTypeDeviceRemoved EventType = "device.removed" + EventTypeDeviceTampered EventType = "device.tampered" + EventTypeDeviceLowBattery EventType = "device.low_battery" + EventTypeDeviceBatteryStatusChanged EventType = "device.battery_status_changed" + EventTypeDeviceThirdPartyIntegrationDetected EventType = "device.third_party_integration_detected" + EventTypeDeviceThirdPartyIntegrationNoLongerDetected EventType = "device.third_party_integration_no_longer_detected" + EventTypeDeviceSaltoPrivacyModeActivated EventType = "device.salto.privacy_mode_activated" + EventTypeDeviceSaltoPrivacyModeDeactivated EventType = "device.salto.privacy_mode_deactivated" + EventTypeDeviceConnectionBecameFlaky EventType = "device.connection_became_flaky" + EventTypeDeviceConnectionStabilized EventType = "device.connection_stabilized" + EventTypeDeviceErrorSubscriptionRequired EventType = "device.error.subscription_required" + EventTypeDeviceErrorSubscriptionRequiredResolved EventType = "device.error.subscription_required.resolved" + EventTypeAccessCodeCreated EventType = "access_code.created" + EventTypeAccessCodeChanged EventType = "access_code.changed" + EventTypeAccessCodeScheduledOnDevice EventType = "access_code.scheduled_on_device" + EventTypeAccessCodeSetOnDevice EventType = "access_code.set_on_device" + EventTypeAccessCodeDeleted EventType = "access_code.deleted" + EventTypeAccessCodeRemovedFromDevice EventType = "access_code.removed_from_device" + EventTypeAccessCodeFailedToSetOnDevice EventType = "access_code.failed_to_set_on_device" + EventTypeAccessCodeDelayInSettingOnDevice EventType = "access_code.delay_in_setting_on_device" + EventTypeAccessCodeFailedToRemoveFromDevice EventType = "access_code.failed_to_remove_from_device" + EventTypeAccessCodeDelayInRemovingFromDevice EventType = "access_code.delay_in_removing_from_device" + EventTypeAccessCodeDeletedExternalToSeam EventType = "access_code.deleted_external_to_seam" + EventTypeAccessCodeModifiedExternalToSeam EventType = "access_code.modified_external_to_seam" + EventTypeAccessCodeUnmanagedConvertedToManaged EventType = "access_code.unmanaged.converted_to_managed" + EventTypeAccessCodeUnmanagedFailedToConvertToManaged EventType = "access_code.unmanaged.failed_to_convert_to_managed" + EventTypeAccessCodeUnmanagedCreated EventType = "access_code.unmanaged.created" + EventTypeAccessCodeUnmanagedRemoved EventType = "access_code.unmanaged.removed" + EventTypeLockLocked EventType = "lock.locked" + EventTypeLockUnlocked EventType = "lock.unlocked" + EventTypeConnectedAccountConnected EventType = "connected_account.connected" + EventTypeConnectedAccountSuccessfulLogin EventType = "connected_account.successful_login" + EventTypeConnectedAccountCreated EventType = "connected_account.created" + EventTypeConnectedAccountDeleted EventType = "connected_account.deleted" + EventTypeConnectedAccountDisconnected EventType = "connected_account.disconnected" + EventTypeConnectedAccountCompletedFirstSync EventType = "connected_account.completed_first_sync" + EventTypeNoiseSensorNoiseThresholdTriggered EventType = "noise_sensor.noise_threshold_triggered" + EventTypeAccessCodeBackupAccessCodePulled EventType = "access_code.backup_access_code_pulled" + EventTypeEnrollmentAutomationDeleted EventType = "enrollment_automation.deleted" + EventTypeAcsUserDeleted EventType = "acs_user.deleted" + EventTypeAcsCredentialDeleted EventType = "acs_credential.deleted" + EventTypePhoneDeactivated EventType = "phone.deactivated" + EventTypeClientSessionDeleted EventType = "client_session.deleted" +) + +func NewEventTypeFromString(s string) (EventType, error) { + switch s { + case "device.connected": + return EventTypeDeviceConnected, nil + case "device.unmanaged.connected": + return EventTypeDeviceUnmanagedConnected, nil + case "device.disconnected": + return EventTypeDeviceDisconnected, nil + case "device.unmanaged.disconnected": + return EventTypeDeviceUnmanagedDisconnected, nil + case "device.converted_to_unmanaged": + return EventTypeDeviceConvertedToUnmanaged, nil + case "device.unmanaged.converted_to_managed": + return EventTypeDeviceUnmanagedConvertedToManaged, nil + case "device.removed": + return EventTypeDeviceRemoved, nil + case "device.tampered": + return EventTypeDeviceTampered, nil + case "device.low_battery": + return EventTypeDeviceLowBattery, nil + case "device.battery_status_changed": + return EventTypeDeviceBatteryStatusChanged, nil + case "device.third_party_integration_detected": + return EventTypeDeviceThirdPartyIntegrationDetected, nil + case "device.third_party_integration_no_longer_detected": + return EventTypeDeviceThirdPartyIntegrationNoLongerDetected, nil + case "device.salto.privacy_mode_activated": + return EventTypeDeviceSaltoPrivacyModeActivated, nil + case "device.salto.privacy_mode_deactivated": + return EventTypeDeviceSaltoPrivacyModeDeactivated, nil + case "device.connection_became_flaky": + return EventTypeDeviceConnectionBecameFlaky, nil + case "device.connection_stabilized": + return EventTypeDeviceConnectionStabilized, nil + case "device.error.subscription_required": + return EventTypeDeviceErrorSubscriptionRequired, nil + case "device.error.subscription_required.resolved": + return EventTypeDeviceErrorSubscriptionRequiredResolved, nil + case "access_code.created": + return EventTypeAccessCodeCreated, nil + case "access_code.changed": + return EventTypeAccessCodeChanged, nil + case "access_code.scheduled_on_device": + return EventTypeAccessCodeScheduledOnDevice, nil + case "access_code.set_on_device": + return EventTypeAccessCodeSetOnDevice, nil + case "access_code.deleted": + return EventTypeAccessCodeDeleted, nil + case "access_code.removed_from_device": + return EventTypeAccessCodeRemovedFromDevice, nil + case "access_code.failed_to_set_on_device": + return EventTypeAccessCodeFailedToSetOnDevice, nil + case "access_code.delay_in_setting_on_device": + return EventTypeAccessCodeDelayInSettingOnDevice, nil + case "access_code.failed_to_remove_from_device": + return EventTypeAccessCodeFailedToRemoveFromDevice, nil + case "access_code.delay_in_removing_from_device": + return EventTypeAccessCodeDelayInRemovingFromDevice, nil + case "access_code.deleted_external_to_seam": + return EventTypeAccessCodeDeletedExternalToSeam, nil + case "access_code.modified_external_to_seam": + return EventTypeAccessCodeModifiedExternalToSeam, nil + case "access_code.unmanaged.converted_to_managed": + return EventTypeAccessCodeUnmanagedConvertedToManaged, nil + case "access_code.unmanaged.failed_to_convert_to_managed": + return EventTypeAccessCodeUnmanagedFailedToConvertToManaged, nil + case "access_code.unmanaged.created": + return EventTypeAccessCodeUnmanagedCreated, nil + case "access_code.unmanaged.removed": + return EventTypeAccessCodeUnmanagedRemoved, nil + case "lock.locked": + return EventTypeLockLocked, nil + case "lock.unlocked": + return EventTypeLockUnlocked, nil + case "connected_account.connected": + return EventTypeConnectedAccountConnected, nil + case "connected_account.successful_login": + return EventTypeConnectedAccountSuccessfulLogin, nil + case "connected_account.created": + return EventTypeConnectedAccountCreated, nil + case "connected_account.deleted": + return EventTypeConnectedAccountDeleted, nil + case "connected_account.disconnected": + return EventTypeConnectedAccountDisconnected, nil + case "connected_account.completed_first_sync": + return EventTypeConnectedAccountCompletedFirstSync, nil + case "noise_sensor.noise_threshold_triggered": + return EventTypeNoiseSensorNoiseThresholdTriggered, nil + case "access_code.backup_access_code_pulled": + return EventTypeAccessCodeBackupAccessCodePulled, nil + case "enrollment_automation.deleted": + return EventTypeEnrollmentAutomationDeleted, nil + case "acs_user.deleted": + return EventTypeAcsUserDeleted, nil + case "acs_credential.deleted": + return EventTypeAcsCredentialDeleted, nil + case "phone.deactivated": + return EventTypePhoneDeactivated, nil + case "client_session.deleted": + return EventTypeClientSessionDeleted, nil + } + var t EventType + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (e EventType) Ptr() *EventType { + return &e } type EventsGetResponse struct { @@ -33,7 +352,33 @@ type EventsGetResponse struct { Message *string `json:"message,omitempty" url:"message,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EventsGetResponse) GetEvent() *Event { + if e == nil { + return nil + } + return e.Event +} + +func (e *EventsGetResponse) GetMessage() *string { + if e == nil { + return nil + } + return e.Message +} + +func (e *EventsGetResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EventsGetResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EventsGetResponse) UnmarshalJSON(data []byte) error { @@ -43,46 +388,66 @@ func (e *EventsGetResponse) UnmarshalJSON(data []byte) error { return err } *e = EventsGetResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EventsGetResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) } type EventsListRequestBetweenItem struct { - typeName string String string DateTime time.Time + + typ string } func NewEventsListRequestBetweenItemFromString(value string) *EventsListRequestBetweenItem { - return &EventsListRequestBetweenItem{typeName: "string", String: value} + return &EventsListRequestBetweenItem{typ: "String", String: value} } func NewEventsListRequestBetweenItemFromDateTime(value time.Time) *EventsListRequestBetweenItem { - return &EventsListRequestBetweenItem{typeName: "dateTime", DateTime: value} + return &EventsListRequestBetweenItem{typ: "DateTime", DateTime: value} +} + +func (e *EventsListRequestBetweenItem) GetString() string { + if e == nil { + return "" + } + return e.String +} + +func (e *EventsListRequestBetweenItem) GetDateTime() time.Time { + if e == nil { + return time.Time{} + } + return e.DateTime } func (e *EventsListRequestBetweenItem) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - e.typeName = "string" + e.typ = "String" e.String = valueString return nil } - var valueDateTime *core.DateTime + var valueDateTime *internal.DateTime if err := json.Unmarshal(data, &valueDateTime); err == nil { - e.typeName = "dateTime" + e.typ = "DateTime" e.DateTime = valueDateTime.Time() return nil } @@ -90,14 +455,13 @@ func (e *EventsListRequestBetweenItem) UnmarshalJSON(data []byte) error { } func (e EventsListRequestBetweenItem) MarshalJSON() ([]byte, error) { - switch e.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", e.typeName, e) - case "string": + if e.typ == "String" || e.String != "" { return json.Marshal(e.String) - case "dateTime": - return json.Marshal(core.NewDateTime(e.DateTime)) } + if e.typ == "DateTime" || !e.DateTime.IsZero() { + return json.Marshal(internal.NewDateTime(e.DateTime)) + } + return nil, fmt.Errorf("type %T does not include a non-empty union type", e) } type EventsListRequestBetweenItemVisitor interface { @@ -106,21 +470,39 @@ type EventsListRequestBetweenItemVisitor interface { } func (e *EventsListRequestBetweenItem) Accept(visitor EventsListRequestBetweenItemVisitor) error { - switch e.typeName { - default: - return fmt.Errorf("invalid type %s in %T", e.typeName, e) - case "string": + if e.typ == "String" || e.String != "" { return visitor.VisitString(e.String) - case "dateTime": + } + if e.typ == "DateTime" || !e.DateTime.IsZero() { return visitor.VisitDateTime(e.DateTime) } + return fmt.Errorf("type %T does not include a non-empty union type", e) } type EventsListResponse struct { Events []*Event `json:"events,omitempty" url:"events,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EventsListResponse) GetEvents() []*Event { + if e == nil { + return nil + } + return e.Events +} + +func (e *EventsListResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EventsListResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EventsListResponse) UnmarshalJSON(data []byte) error { @@ -130,17 +512,22 @@ func (e *EventsListResponse) UnmarshalJSON(data []byte) error { return err } *e = EventsListResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EventsListResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) diff --git a/events/client.go b/events/client.go index bd23455..57a534a 100644 --- a/events/client.go +++ b/events/client.go @@ -3,20 +3,17 @@ package events import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Event, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "events/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/events/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.EventsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Event, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "events/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/events/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.EventsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/file_param.go b/file_param.go new file mode 100644 index 0000000..737abb9 --- /dev/null +++ b/file_param.go @@ -0,0 +1,41 @@ +package api + +import ( + "io" +) + +// FileParam is a file type suitable for multipart/form-data uploads. +type FileParam struct { + io.Reader + filename string + contentType string +} + +// FileParamOption adapts the behavior of the FileParam. No options are +// implemented yet, but this interface allows for future extensibility. +type FileParamOption interface { + apply() +} + +// NewFileParam returns a *FileParam type suitable for multipart/form-data uploads. All file +// upload endpoints accept a simple io.Reader, which is usually created by opening a file +// via os.Open. +// +// However, some endpoints require additional metadata about the file such as a specific +// Content-Type or custom filename. FileParam makes it easier to create the correct type +// signature for these endpoints. +func NewFileParam( + reader io.Reader, + filename string, + contentType string, + opts ...FileParamOption, +) *FileParam { + return &FileParam{ + Reader: reader, + filename: filename, + contentType: contentType, + } +} + +func (f *FileParam) Name() string { return f.filename } +func (f *FileParam) ContentType() string { return f.contentType } diff --git a/core/core.go b/internal/caller.go similarity index 62% rename from core/core.go rename to internal/caller.go index 5277d13..baed593 100644 --- a/core/core.go +++ b/internal/caller.go @@ -1,4 +1,4 @@ -package core +package internal import ( "bytes" @@ -7,8 +7,12 @@ import ( "errors" "fmt" "io" - "mime/multipart" "net/http" + "net/url" + "reflect" + "strings" + + "github.com/seamapi/go/core" ) const ( @@ -17,95 +21,21 @@ const ( contentTypeHeader = "Content-Type" ) -// HTTPClient is an interface for a subset of the *http.Client. -type HTTPClient interface { - Do(*http.Request) (*http.Response, error) -} - -// MergeHeaders merges the given headers together, where the right -// takes precedence over the left. -func MergeHeaders(left, right http.Header) http.Header { - for key, values := range right { - if len(values) > 1 { - left[key] = values - continue - } - if value := right.Get(key); value != "" { - left.Set(key, value) - } - } - return left -} - -// WriteMultipartJSON writes the given value as a JSON part. -// This is used to serialize non-primitive multipart properties -// (i.e. lists, objects, etc). -func WriteMultipartJSON(writer *multipart.Writer, field string, value interface{}) error { - bytes, err := json.Marshal(value) - if err != nil { - return err - } - return writer.WriteField(field, string(bytes)) -} - -// APIError is a lightweight wrapper around the standard error -// interface that preserves the status code from the RPC, if any. -type APIError struct { - err error - - StatusCode int `json:"-"` -} - -// NewAPIError constructs a new API error. -func NewAPIError(statusCode int, err error) *APIError { - return &APIError{ - err: err, - StatusCode: statusCode, - } -} - -// Unwrap returns the underlying error. This also makes the error compatible -// with errors.As and errors.Is. -func (a *APIError) Unwrap() error { - if a == nil { - return nil - } - return a.err -} - -// Error returns the API error's message. -func (a *APIError) Error() string { - if a == nil || (a.err == nil && a.StatusCode == 0) { - return "" - } - if a.err == nil { - return fmt.Sprintf("%d", a.StatusCode) - } - if a.StatusCode == 0 { - return a.err.Error() - } - return fmt.Sprintf("%d: %s", a.StatusCode, a.err.Error()) -} - -// ErrorDecoder decodes *http.Response errors and returns a -// typed API error (e.g. *APIError). -type ErrorDecoder func(statusCode int, body io.Reader) error - // Caller calls APIs and deserializes their response, if any. type Caller struct { - client HTTPClient + client core.HTTPClient retrier *Retrier } // CallerParams represents the parameters used to constrcut a new *Caller. type CallerParams struct { - Client HTTPClient + Client core.HTTPClient MaxAttempts uint } // NewCaller returns a new *Caller backed by the given parameters. func NewCaller(params *CallerParams) *Caller { - var httpClient HTTPClient = http.DefaultClient + var httpClient core.HTTPClient = http.DefaultClient if params.Client != nil { httpClient = params.Client } @@ -125,7 +55,9 @@ type CallParams struct { Method string MaxAttempts uint Headers http.Header - Client HTTPClient + BodyProperties map[string]interface{} + QueryParameters url.Values + Client core.HTTPClient Request interface{} Response interface{} ResponseIsOptional bool @@ -134,7 +66,15 @@ type CallParams struct { // Call issues an API call according to the given call parameters. func (c *Caller) Call(ctx context.Context, params *CallParams) error { - req, err := newRequest(ctx, params.URL, params.Method, params.Headers, params.Request) + url := buildURL(params.URL, params.QueryParameters) + req, err := newRequest( + ctx, + url, + params.Method, + params.Headers, + params.Request, + params.BodyProperties, + ) if err != nil { return err } @@ -201,6 +141,23 @@ func (c *Caller) Call(ctx context.Context, params *CallParams) error { return nil } +// buildURL constructs the final URL by appending the given query parameters (if any). +func buildURL( + url string, + queryParameters url.Values, +) string { + if len(queryParameters) == 0 { + return url + } + if strings.ContainsRune(url, '?') { + url += "&" + } else { + url += "?" + } + url += queryParameters.Encode() + return url +} + // newRequest returns a new *http.Request with all of the fields // required to issue the call. func newRequest( @@ -209,8 +166,9 @@ func newRequest( method string, endpointHeaders http.Header, request interface{}, + bodyProperties map[string]interface{}, ) (*http.Request, error) { - requestBody, err := newRequestBody(request) + requestBody, err := newRequestBody(request, bodyProperties) if err != nil { return nil, err } @@ -227,20 +185,25 @@ func newRequest( } // newRequestBody returns a new io.Reader that represents the HTTP request body. -func newRequestBody(request interface{}) (io.Reader, error) { - var requestBody io.Reader - if request != nil { - if body, ok := request.(io.Reader); ok { - requestBody = body - } else { - requestBytes, err := json.Marshal(request) - if err != nil { - return nil, err - } - requestBody = bytes.NewReader(requestBytes) +func newRequestBody(request interface{}, bodyProperties map[string]interface{}) (io.Reader, error) { + if isNil(request) { + if len(bodyProperties) == 0 { + return nil, nil } + requestBytes, err := json.Marshal(bodyProperties) + if err != nil { + return nil, err + } + return bytes.NewReader(requestBytes), nil + } + if body, ok := request.(io.Reader); ok { + return body, nil } - return requestBody, nil + requestBytes, err := MarshalJSONWithExtraProperties(request, bodyProperties) + if err != nil { + return nil, err + } + return bytes.NewReader(requestBytes), nil } // decodeError decodes the error from the given HTTP response. Note that @@ -263,7 +226,13 @@ func decodeError(response *http.Response, errorDecoder ErrorDecoder) error { // The error didn't have a response body, // so all we can do is return an error // with the status code. - return NewAPIError(response.StatusCode, nil) + return core.NewAPIError(response.StatusCode, nil) } - return NewAPIError(response.StatusCode, errors.New(string(bytes))) + return core.NewAPIError(response.StatusCode, errors.New(string(bytes))) +} + +// isNil is used to determine if the request value is equal to nil (i.e. an interface +// value that holds a nil concrete value is itself non-nil). +func isNil(value interface{}) bool { + return value == nil || reflect.ValueOf(value).IsNil() } diff --git a/core/core_test.go b/internal/caller_test.go similarity index 67% rename from core/core_test.go rename to internal/caller_test.go index f476f9e..293d01a 100644 --- a/core/core_test.go +++ b/internal/caller_test.go @@ -1,4 +1,4 @@ -package core +package internal import ( "bytes" @@ -9,9 +9,11 @@ import ( "io" "net/http" "net/http/httptest" + "net/url" "strconv" "testing" + "github.com/seamapi/go/core" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -21,11 +23,14 @@ type TestCase struct { description string // Server-side assertions. + givePathSuffix string giveMethod string giveResponseIsOptional bool giveHeader http.Header giveErrorDecoder ErrorDecoder giveRequest *Request + giveQueryParams url.Values + giveBodyProperties map[string]interface{} // Client-side assertions. wantResponse *Response @@ -39,12 +44,14 @@ type Request struct { // Response a simple response body. type Response struct { - Id string `json:"id"` + Id string `json:"id"` + ExtraBodyProperties map[string]interface{} `json:"extraBodyProperties,omitempty"` + QueryParameters url.Values `json:"queryParameters,omitempty"` } // NotFoundError represents a 404. type NotFoundError struct { - *APIError + *core.APIError Message string `json:"message"` } @@ -64,6 +71,23 @@ func TestCall(t *testing.T) { Id: "123", }, }, + { + description: "GET success with query", + givePathSuffix: "?limit=1", + giveMethod: http.MethodGet, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveRequest: &Request{ + Id: "123", + }, + wantResponse: &Response{ + Id: "123", + QueryParameters: url.Values{ + "limit": []string{"1"}, + }, + }, + }, { description: "GET not found", giveMethod: http.MethodGet, @@ -75,12 +99,24 @@ func TestCall(t *testing.T) { }, giveErrorDecoder: newTestErrorDecoder(t), wantError: &NotFoundError{ - APIError: NewAPIError( + APIError: core.NewAPIError( http.StatusNotFound, errors.New(`{"message":"ID \"404\" not found"}`), ), }, }, + { + description: "POST empty body", + giveMethod: http.MethodPost, + giveHeader: http.Header{ + "X-API-Status": []string{"fail"}, + }, + giveRequest: nil, + wantError: core.NewAPIError( + http.StatusBadRequest, + errors.New("invalid request"), + ), + }, { description: "POST optional response", giveMethod: http.MethodPost, @@ -101,11 +137,67 @@ func TestCall(t *testing.T) { giveRequest: &Request{ Id: strconv.Itoa(http.StatusInternalServerError), }, - wantError: NewAPIError( + wantError: core.NewAPIError( http.StatusInternalServerError, errors.New("failed to process request"), ), }, + { + description: "POST extra properties", + giveMethod: http.MethodPost, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveRequest: new(Request), + giveBodyProperties: map[string]interface{}{ + "key": "value", + }, + wantResponse: &Response{ + ExtraBodyProperties: map[string]interface{}{ + "key": "value", + }, + }, + }, + { + description: "GET extra query parameters", + giveMethod: http.MethodGet, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveQueryParams: url.Values{ + "extra": []string{"true"}, + }, + giveRequest: &Request{ + Id: "123", + }, + wantResponse: &Response{ + Id: "123", + QueryParameters: url.Values{ + "extra": []string{"true"}, + }, + }, + }, + { + description: "GET merge extra query parameters", + givePathSuffix: "?limit=1", + giveMethod: http.MethodGet, + giveHeader: http.Header{ + "X-API-Status": []string{"success"}, + }, + giveRequest: &Request{ + Id: "123", + }, + giveQueryParams: url.Values{ + "extra": []string{"true"}, + }, + wantResponse: &Response{ + Id: "123", + QueryParameters: url.Values{ + "limit": []string{"1"}, + "extra": []string{"true"}, + }, + }, + }, } for _, test := range tests { t.Run(test.description, func(t *testing.T) { @@ -122,9 +214,11 @@ func TestCall(t *testing.T) { err := caller.Call( context.Background(), &CallParams{ - URL: server.URL, + URL: server.URL + test.givePathSuffix, Method: test.giveMethod, Headers: test.giveHeader, + BodyProperties: test.giveBodyProperties, + QueryParameters: test.giveQueryParams, Request: test.giveRequest, Response: &response, ResponseIsOptional: test.giveResponseIsOptional, @@ -215,16 +309,23 @@ func newTestServer(t *testing.T, tc *TestCase) *httptest.Server { assert.Equal(t, value, r.Header.Values(header)) } + request := new(Request) + bytes, err := io.ReadAll(r.Body) + if tc.giveRequest == nil { + require.Empty(t, bytes) + w.WriteHeader(http.StatusBadRequest) + _, err = w.Write([]byte("invalid request")) + require.NoError(t, err) + return + } require.NoError(t, err) - - request := new(Request) require.NoError(t, json.Unmarshal(bytes, request)) switch request.Id { case strconv.Itoa(http.StatusNotFound): notFoundError := &NotFoundError{ - APIError: &APIError{ + APIError: &core.APIError{ StatusCode: http.StatusNotFound, }, Message: fmt.Sprintf("ID %q not found", request.Id), @@ -249,8 +350,14 @@ func newTestServer(t *testing.T, tc *TestCase) *httptest.Server { return } + extraBodyProperties := make(map[string]interface{}) + require.NoError(t, json.Unmarshal(bytes, &extraBodyProperties)) + delete(extraBodyProperties, "id") + response := &Response{ - Id: request.Id, + Id: request.Id, + ExtraBodyProperties: extraBodyProperties, + QueryParameters: r.URL.Query(), } bytes, err = json.Marshal(response) require.NoError(t, err) @@ -269,7 +376,7 @@ func newTestErrorDecoder(t *testing.T) func(int, io.Reader) error { require.NoError(t, err) var ( - apiError = NewAPIError(statusCode, errors.New(string(raw))) + apiError = core.NewAPIError(statusCode, errors.New(string(raw))) decoder = json.NewDecoder(bytes.NewReader(raw)) ) if statusCode == http.StatusNotFound { diff --git a/internal/error_decoder.go b/internal/error_decoder.go new file mode 100644 index 0000000..a442ab3 --- /dev/null +++ b/internal/error_decoder.go @@ -0,0 +1,45 @@ +package internal + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + + "github.com/seamapi/go/core" +) + +// ErrorDecoder decodes *http.Response errors and returns a +// typed API error (e.g. *core.APIError). +type ErrorDecoder func(statusCode int, body io.Reader) error + +// ErrorCodes maps HTTP status codes to error constructors. +type ErrorCodes map[int]func(*core.APIError) error + +// NewErrorDecoder returns a new ErrorDecoder backed by the given error codes. +func NewErrorDecoder(errorCodes ErrorCodes) ErrorDecoder { + return func(statusCode int, body io.Reader) error { + raw, err := io.ReadAll(body) + if err != nil { + return fmt.Errorf("failed to read error from response body: %w", err) + } + apiError := core.NewAPIError( + statusCode, + errors.New(string(raw)), + ) + newErrorFunc, ok := errorCodes[statusCode] + if !ok { + // This status code isn't recognized, so we return + // the API error as-is. + return apiError + } + customError := newErrorFunc(apiError) + if err := json.NewDecoder(bytes.NewReader(raw)).Decode(customError); err != nil { + // If we fail to decode the error, we return the + // API error as-is. + return apiError + } + return customError + } +} diff --git a/internal/error_decoder_test.go b/internal/error_decoder_test.go new file mode 100644 index 0000000..171940b --- /dev/null +++ b/internal/error_decoder_test.go @@ -0,0 +1,55 @@ +package internal + +import ( + "bytes" + "errors" + "net/http" + "testing" + + "github.com/seamapi/go/core" + "github.com/stretchr/testify/assert" +) + +func TestErrorDecoder(t *testing.T) { + decoder := NewErrorDecoder( + ErrorCodes{ + http.StatusNotFound: func(apiError *core.APIError) error { + return &NotFoundError{APIError: apiError} + }, + }) + + tests := []struct { + description string + giveStatusCode int + giveBody string + wantError error + }{ + { + description: "unrecognized status code", + giveStatusCode: http.StatusInternalServerError, + giveBody: "Internal Server Error", + wantError: core.NewAPIError(http.StatusInternalServerError, errors.New("Internal Server Error")), + }, + { + description: "not found with valid JSON", + giveStatusCode: http.StatusNotFound, + giveBody: `{"message": "Resource not found"}`, + wantError: &NotFoundError{ + APIError: core.NewAPIError(http.StatusNotFound, errors.New(`{"message": "Resource not found"}`)), + Message: "Resource not found", + }, + }, + { + description: "not found with invalid JSON", + giveStatusCode: http.StatusNotFound, + giveBody: `Resource not found`, + wantError: core.NewAPIError(http.StatusNotFound, errors.New("Resource not found")), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + assert.Equal(t, tt.wantError, decoder(tt.giveStatusCode, bytes.NewReader([]byte(tt.giveBody)))) + }) + } +} diff --git a/internal/extra_properties.go b/internal/extra_properties.go new file mode 100644 index 0000000..540c3fd --- /dev/null +++ b/internal/extra_properties.go @@ -0,0 +1,141 @@ +package internal + +import ( + "bytes" + "encoding/json" + "fmt" + "reflect" + "strings" +) + +// MarshalJSONWithExtraProperty marshals the given value to JSON, including the extra property. +func MarshalJSONWithExtraProperty(marshaler interface{}, key string, value interface{}) ([]byte, error) { + return MarshalJSONWithExtraProperties(marshaler, map[string]interface{}{key: value}) +} + +// MarshalJSONWithExtraProperties marshals the given value to JSON, including any extra properties. +func MarshalJSONWithExtraProperties(marshaler interface{}, extraProperties map[string]interface{}) ([]byte, error) { + bytes, err := json.Marshal(marshaler) + if err != nil { + return nil, err + } + if len(extraProperties) == 0 { + return bytes, nil + } + keys, err := getKeys(marshaler) + if err != nil { + return nil, err + } + for _, key := range keys { + if _, ok := extraProperties[key]; ok { + return nil, fmt.Errorf("cannot add extra property %q because it is already defined on the type", key) + } + } + extraBytes, err := json.Marshal(extraProperties) + if err != nil { + return nil, err + } + if isEmptyJSON(bytes) { + if isEmptyJSON(extraBytes) { + return bytes, nil + } + return extraBytes, nil + } + result := bytes[:len(bytes)-1] + result = append(result, ',') + result = append(result, extraBytes[1:len(extraBytes)-1]...) + result = append(result, '}') + return result, nil +} + +// ExtractExtraProperties extracts any extra properties from the given value. +func ExtractExtraProperties(bytes []byte, value interface{}, exclude ...string) (map[string]interface{}, error) { + val := reflect.ValueOf(value) + for val.Kind() == reflect.Ptr { + if val.IsNil() { + return nil, fmt.Errorf("value must be non-nil to extract extra properties") + } + val = val.Elem() + } + if err := json.Unmarshal(bytes, &value); err != nil { + return nil, err + } + var extraProperties map[string]interface{} + if err := json.Unmarshal(bytes, &extraProperties); err != nil { + return nil, err + } + for i := 0; i < val.Type().NumField(); i++ { + key := jsonKey(val.Type().Field(i)) + if key == "" || key == "-" { + continue + } + delete(extraProperties, key) + } + for _, key := range exclude { + delete(extraProperties, key) + } + if len(extraProperties) == 0 { + return nil, nil + } + return extraProperties, nil +} + +// getKeys returns the keys associated with the given value. The value must be a +// a struct or a map with string keys. +func getKeys(value interface{}) ([]string, error) { + val := reflect.ValueOf(value) + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + if !val.IsValid() { + return nil, nil + } + switch val.Kind() { + case reflect.Struct: + return getKeysForStructType(val.Type()), nil + case reflect.Map: + var keys []string + if val.Type().Key().Kind() != reflect.String { + return nil, fmt.Errorf("cannot extract keys from %T; only structs and maps with string keys are supported", value) + } + for _, key := range val.MapKeys() { + keys = append(keys, key.String()) + } + return keys, nil + default: + return nil, fmt.Errorf("cannot extract keys from %T; only structs and maps with string keys are supported", value) + } +} + +// getKeysForStructType returns all the keys associated with the given struct type, +// visiting embedded fields recursively. +func getKeysForStructType(structType reflect.Type) []string { + if structType.Kind() == reflect.Pointer { + structType = structType.Elem() + } + if structType.Kind() != reflect.Struct { + return nil + } + var keys []string + for i := 0; i < structType.NumField(); i++ { + field := structType.Field(i) + if field.Anonymous { + keys = append(keys, getKeysForStructType(field.Type)...) + continue + } + keys = append(keys, jsonKey(field)) + } + return keys +} + +// jsonKey returns the JSON key from the struct tag of the given field, +// excluding the omitempty flag (if any). +func jsonKey(field reflect.StructField) string { + return strings.TrimSuffix(field.Tag.Get("json"), ",omitempty") +} + +// isEmptyJSON returns true if the given data is empty, the empty JSON object, or +// an explicit null. +func isEmptyJSON(data []byte) bool { + return len(data) <= 2 || bytes.Equal(data, []byte("null")) +} diff --git a/internal/extra_properties_test.go b/internal/extra_properties_test.go new file mode 100644 index 0000000..aa2510e --- /dev/null +++ b/internal/extra_properties_test.go @@ -0,0 +1,228 @@ +package internal + +import ( + "encoding/json" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type testMarshaler struct { + Name string `json:"name"` + BirthDate time.Time `json:"birthDate"` + CreatedAt time.Time `json:"created_at"` +} + +func (t *testMarshaler) MarshalJSON() ([]byte, error) { + type embed testMarshaler + var marshaler = struct { + embed + BirthDate string `json:"birthDate"` + CreatedAt string `json:"created_at"` + }{ + embed: embed(*t), + BirthDate: t.BirthDate.Format("2006-01-02"), + CreatedAt: t.CreatedAt.Format(time.RFC3339), + } + return MarshalJSONWithExtraProperty(marshaler, "type", "test") +} + +func TestMarshalJSONWithExtraProperties(t *testing.T) { + tests := []struct { + desc string + giveMarshaler interface{} + giveExtraProperties map[string]interface{} + wantBytes []byte + wantError string + }{ + { + desc: "invalid type", + giveMarshaler: []string{"invalid"}, + giveExtraProperties: map[string]interface{}{"key": "overwrite"}, + wantError: `cannot extract keys from []string; only structs and maps with string keys are supported`, + }, + { + desc: "invalid key type", + giveMarshaler: map[int]interface{}{42: "value"}, + giveExtraProperties: map[string]interface{}{"key": "overwrite"}, + wantError: `cannot extract keys from map[int]interface {}; only structs and maps with string keys are supported`, + }, + { + desc: "invalid map overwrite", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{"key": "overwrite"}, + wantError: `cannot add extra property "key" because it is already defined on the type`, + }, + { + desc: "invalid struct overwrite", + giveMarshaler: new(testMarshaler), + giveExtraProperties: map[string]interface{}{"birthDate": "2000-01-01"}, + wantError: `cannot add extra property "birthDate" because it is already defined on the type`, + }, + { + desc: "invalid struct overwrite embedded type", + giveMarshaler: new(testMarshaler), + giveExtraProperties: map[string]interface{}{"name": "bob"}, + wantError: `cannot add extra property "name" because it is already defined on the type`, + }, + { + desc: "nil", + giveMarshaler: nil, + giveExtraProperties: nil, + wantBytes: []byte(`null`), + }, + { + desc: "empty", + giveMarshaler: map[string]interface{}{}, + giveExtraProperties: map[string]interface{}{}, + wantBytes: []byte(`{}`), + }, + { + desc: "no extra properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{}, + wantBytes: []byte(`{"key":"value"}`), + }, + { + desc: "only extra properties", + giveMarshaler: map[string]interface{}{}, + giveExtraProperties: map[string]interface{}{"key": "value"}, + wantBytes: []byte(`{"key":"value"}`), + }, + { + desc: "single extra property", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{"extra": "property"}, + wantBytes: []byte(`{"key":"value","extra":"property"}`), + }, + { + desc: "multiple extra properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{"one": 1, "two": 2}, + wantBytes: []byte(`{"key":"value","one":1,"two":2}`), + }, + { + desc: "nested properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{ + "user": map[string]interface{}{ + "age": 42, + "name": "alice", + }, + }, + wantBytes: []byte(`{"key":"value","user":{"age":42,"name":"alice"}}`), + }, + { + desc: "multiple nested properties", + giveMarshaler: map[string]interface{}{"key": "value"}, + giveExtraProperties: map[string]interface{}{ + "metadata": map[string]interface{}{ + "ip": "127.0.0.1", + }, + "user": map[string]interface{}{ + "age": 42, + "name": "alice", + }, + }, + wantBytes: []byte(`{"key":"value","metadata":{"ip":"127.0.0.1"},"user":{"age":42,"name":"alice"}}`), + }, + { + desc: "custom marshaler", + giveMarshaler: &testMarshaler{ + Name: "alice", + BirthDate: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), + CreatedAt: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), + }, + giveExtraProperties: map[string]interface{}{ + "extra": "property", + }, + wantBytes: []byte(`{"name":"alice","birthDate":"2000-01-01","created_at":"2024-01-01T00:00:00Z","type":"test","extra":"property"}`), + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + bytes, err := MarshalJSONWithExtraProperties(tt.giveMarshaler, tt.giveExtraProperties) + if tt.wantError != "" { + require.EqualError(t, err, tt.wantError) + assert.Nil(t, tt.wantBytes) + return + } + require.NoError(t, err) + assert.Equal(t, tt.wantBytes, bytes) + + value := make(map[string]interface{}) + require.NoError(t, json.Unmarshal(bytes, &value)) + }) + } +} + +func TestExtractExtraProperties(t *testing.T) { + t.Run("none", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := &user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice"}`), value) + require.NoError(t, err) + assert.Nil(t, extraProperties) + }) + + t.Run("non-nil pointer", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := &user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + require.NoError(t, err) + assert.Equal(t, map[string]interface{}{"age": float64(42)}, extraProperties) + }) + + t.Run("nil pointer", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + var value *user + _, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + assert.EqualError(t, err, "value must be non-nil to extract extra properties") + }) + + t.Run("non-zero value", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + require.NoError(t, err) + assert.Equal(t, map[string]interface{}{"age": float64(42)}, extraProperties) + }) + + t.Run("zero value", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + var value user + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value) + require.NoError(t, err) + assert.Equal(t, map[string]interface{}{"age": float64(42)}, extraProperties) + }) + + t.Run("exclude", func(t *testing.T) { + type user struct { + Name string `json:"name"` + } + value := &user{ + Name: "alice", + } + extraProperties, err := ExtractExtraProperties([]byte(`{"name": "alice", "age": 42}`), value, "age") + require.NoError(t, err) + assert.Nil(t, extraProperties) + }) +} diff --git a/internal/http.go b/internal/http.go new file mode 100644 index 0000000..768968b --- /dev/null +++ b/internal/http.go @@ -0,0 +1,48 @@ +package internal + +import ( + "fmt" + "net/http" + "net/url" +) + +// HTTPClient is an interface for a subset of the *http.Client. +type HTTPClient interface { + Do(*http.Request) (*http.Response, error) +} + +// ResolveBaseURL resolves the base URL from the given arguments, +// preferring the first non-empty value. +func ResolveBaseURL(values ...string) string { + for _, value := range values { + if value != "" { + return value + } + } + return "" +} + +// EncodeURL encodes the given arguments into the URL, escaping +// values as needed. +func EncodeURL(urlFormat string, args ...interface{}) string { + escapedArgs := make([]interface{}, 0, len(args)) + for _, arg := range args { + escapedArgs = append(escapedArgs, url.PathEscape(fmt.Sprintf("%v", arg))) + } + return fmt.Sprintf(urlFormat, escapedArgs...) +} + +// MergeHeaders merges the given headers together, where the right +// takes precedence over the left. +func MergeHeaders(left, right http.Header) http.Header { + for key, values := range right { + if len(values) > 1 { + left[key] = values + continue + } + if value := right.Get(key); value != "" { + left.Set(key, value) + } + } + return left +} diff --git a/core/query.go b/internal/query.go similarity index 91% rename from core/query.go rename to internal/query.go index 479cbb2..6129e71 100644 --- a/core/query.go +++ b/internal/query.go @@ -1,4 +1,4 @@ -package core +package internal import ( "encoding/base64" @@ -116,7 +116,14 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error { continue } for i := 0; i < sv.Len(); i++ { - values.Add(name, valueString(sv.Index(i), opts, sf)) + value := sv.Index(i) + if isStructPointer(value) && !value.IsNil() { + if err := reflectValue(values, value.Elem(), name); err != nil { + return err + } + } else { + values.Add(name, valueString(value, opts, sf)) + } } continue } @@ -171,7 +178,7 @@ func isEmptyValue(v reflect.Value) bool { IsZero() bool } - if !v.IsNil() { + if !v.IsZero() { if z, ok := v.Interface().(zeroable); ok { return z.IsZero() } @@ -197,6 +204,11 @@ func isEmptyValue(v reflect.Value) bool { return false } +// isStructPointer returns true if the given reflect.Value is a pointer to a struct. +func isStructPointer(v reflect.Value) bool { + return v.Kind() == reflect.Ptr && v.Elem().Kind() == reflect.Struct +} + // tagOptions is the string following a comma in a struct field's "url" tag, or // the empty string. It does not include the leading comma. type tagOptions []string diff --git a/core/query_test.go b/internal/query_test.go similarity index 78% rename from core/query_test.go rename to internal/query_test.go index 4f0d392..2e58cca 100644 --- a/core/query_test.go +++ b/internal/query_test.go @@ -1,4 +1,4 @@ -package core +package internal import ( "testing" @@ -143,4 +143,45 @@ func TestQueryValues(t *testing.T) { require.NoError(t, err) assert.Empty(t, values.Encode()) }) + + t.Run("omitempty with non-pointer zero value", func(t *testing.T) { + type enum string + + type example struct { + Enum enum `json:"enum,omitempty" url:"enum,omitempty"` + } + + values, err := QueryValues( + &example{}, + ) + require.NoError(t, err) + assert.Empty(t, values.Encode()) + }) + + t.Run("object array", func(t *testing.T) { + type object struct { + Key string `json:"key" url:"key"` + Value string `json:"value" url:"value"` + } + type example struct { + Objects []*object `json:"objects,omitempty" url:"objects,omitempty"` + } + + values, err := QueryValues( + &example{ + Objects: []*object{ + { + Key: "hello", + Value: "world", + }, + { + Key: "foo", + Value: "bar", + }, + }, + }, + ) + require.NoError(t, err) + assert.Equal(t, "objects%5Bkey%5D=hello&objects%5Bkey%5D=foo&objects%5Bvalue%5D=world&objects%5Bvalue%5D=bar", values.Encode()) + }) } diff --git a/core/retrier.go b/internal/retrier.go similarity index 98% rename from core/retrier.go rename to internal/retrier.go index ea24916..6040147 100644 --- a/core/retrier.go +++ b/internal/retrier.go @@ -1,4 +1,4 @@ -package core +package internal import ( "crypto/rand" @@ -130,7 +130,6 @@ func (r *Retrier) run( func (r *Retrier) shouldRetry(response *http.Response) bool { return response.StatusCode == http.StatusTooManyRequests || response.StatusCode == http.StatusRequestTimeout || - response.StatusCode == http.StatusConflict || response.StatusCode >= http.StatusInternalServerError } diff --git a/internal/retrier_test.go b/internal/retrier_test.go new file mode 100644 index 0000000..815a2d8 --- /dev/null +++ b/internal/retrier_test.go @@ -0,0 +1,211 @@ +package internal + +import ( + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/seamapi/go/core" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type RetryTestCase struct { + description string + + giveAttempts uint + giveStatusCodes []int + giveResponse *Response + + wantResponse *Response + wantError *core.APIError +} + +func TestRetrier(t *testing.T) { + tests := []*RetryTestCase{ + { + description: "retry request succeeds after multiple failures", + giveAttempts: 3, + giveStatusCodes: []int{ + http.StatusServiceUnavailable, + http.StatusServiceUnavailable, + http.StatusOK, + }, + giveResponse: &Response{ + Id: "1", + }, + wantResponse: &Response{ + Id: "1", + }, + }, + { + description: "retry request fails if MaxAttempts is exceeded", + giveAttempts: 3, + giveStatusCodes: []int{ + http.StatusRequestTimeout, + http.StatusRequestTimeout, + http.StatusRequestTimeout, + http.StatusOK, + }, + wantError: &core.APIError{ + StatusCode: http.StatusRequestTimeout, + }, + }, + { + description: "retry durations increase exponentially and stay within the min and max delay values", + giveAttempts: 4, + giveStatusCodes: []int{ + http.StatusServiceUnavailable, + http.StatusServiceUnavailable, + http.StatusServiceUnavailable, + http.StatusOK, + }, + }, + { + description: "retry does not occur on status code 404", + giveAttempts: 2, + giveStatusCodes: []int{http.StatusNotFound, http.StatusOK}, + wantError: &core.APIError{ + StatusCode: http.StatusNotFound, + }, + }, + { + description: "retries occur on status code 429", + giveAttempts: 2, + giveStatusCodes: []int{http.StatusTooManyRequests, http.StatusOK}, + }, + { + description: "retries occur on status code 408", + giveAttempts: 2, + giveStatusCodes: []int{http.StatusRequestTimeout, http.StatusOK}, + }, + { + description: "retries occur on status code 500", + giveAttempts: 2, + giveStatusCodes: []int{http.StatusInternalServerError, http.StatusOK}, + }, + } + + for _, tc := range tests { + t.Run(tc.description, func(t *testing.T) { + var ( + test = tc + server = newTestRetryServer(t, test) + client = server.Client() + ) + + t.Parallel() + + caller := NewCaller( + &CallerParams{ + Client: client, + }, + ) + + var response *Response + err := caller.Call( + context.Background(), + &CallParams{ + URL: server.URL, + Method: http.MethodGet, + Request: &Request{}, + Response: &response, + MaxAttempts: test.giveAttempts, + ResponseIsOptional: true, + }, + ) + + if test.wantError != nil { + require.IsType(t, err, &core.APIError{}) + expectedErrorCode := test.wantError.StatusCode + actualErrorCode := err.(*core.APIError).StatusCode + assert.Equal(t, expectedErrorCode, actualErrorCode) + return + } + + require.NoError(t, err) + assert.Equal(t, test.wantResponse, response) + }) + } +} + +// newTestRetryServer returns a new *httptest.Server configured with the +// given test parameters, suitable for testing retries. +func newTestRetryServer(t *testing.T, tc *RetryTestCase) *httptest.Server { + var index int + timestamps := make([]time.Time, 0, len(tc.giveStatusCodes)) + + return httptest.NewServer( + http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + timestamps = append(timestamps, time.Now()) + if index > 0 && index < len(expectedRetryDurations) { + // Ensure that the duration between retries increases exponentially, + // and that it is within the minimum and maximum retry delay values. + actualDuration := timestamps[index].Sub(timestamps[index-1]) + expectedDurationMin := expectedRetryDurations[index-1] * 75 / 100 + expectedDurationMax := expectedRetryDurations[index-1] * 125 / 100 + assert.True( + t, + actualDuration >= expectedDurationMin && actualDuration <= expectedDurationMax, + "expected duration to be in range [%v, %v], got %v", + expectedDurationMin, + expectedDurationMax, + actualDuration, + ) + assert.LessOrEqual( + t, + actualDuration, + maxRetryDelay, + "expected duration to be less than the maxRetryDelay (%v), got %v", + maxRetryDelay, + actualDuration, + ) + assert.GreaterOrEqual( + t, + actualDuration, + minRetryDelay, + "expected duration to be greater than the minRetryDelay (%v), got %v", + minRetryDelay, + actualDuration, + ) + } + + request := new(Request) + bytes, err := io.ReadAll(r.Body) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(bytes, request)) + require.LessOrEqual(t, index, len(tc.giveStatusCodes)) + + statusCode := tc.giveStatusCodes[index] + w.WriteHeader(statusCode) + + if tc.giveResponse != nil && statusCode == http.StatusOK { + bytes, err = json.Marshal(tc.giveResponse) + require.NoError(t, err) + _, err = w.Write(bytes) + require.NoError(t, err) + } + + index++ + }, + ), + ) +} + +// expectedRetryDurations holds an array of calculated retry durations, +// where the index of the array should correspond to the retry attempt. +// +// Values are calculated based off of `minRetryDelay + minRetryDelay*i*i`, with +// a max and min value of 5000ms and 500ms respectively. +var expectedRetryDurations = []time.Duration{ + 500 * time.Millisecond, + 1000 * time.Millisecond, + 2500 * time.Millisecond, + 5000 * time.Millisecond, + 5000 * time.Millisecond, +} diff --git a/core/stringer.go b/internal/stringer.go similarity index 94% rename from core/stringer.go rename to internal/stringer.go index 000cf44..3128018 100644 --- a/core/stringer.go +++ b/internal/stringer.go @@ -1,4 +1,4 @@ -package core +package internal import "encoding/json" diff --git a/core/time.go b/internal/time.go similarity index 99% rename from core/time.go rename to internal/time.go index d009ab3..ab0e269 100644 --- a/core/time.go +++ b/internal/time.go @@ -1,4 +1,4 @@ -package core +package internal import ( "encoding/json" diff --git a/locks.go b/locks.go index e1574b7..3bf5658 100644 --- a/locks.go +++ b/locks.go @@ -5,30 +5,30 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type LocksGetRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` } type LocksListRequest struct { // List all devices owned by this connected account - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"connect_webview_id,omitempty"` - DeviceType *DeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` - DeviceTypes []DeviceType `json:"device_types,omitempty" url:"device_types,omitempty"` - Manufacturer *Manufacturer `json:"manufacturer,omitempty" url:"manufacturer,omitempty"` - DeviceIds []string `json:"device_ids,omitempty" url:"device_ids,omitempty"` - Limit *float64 `json:"limit,omitempty" url:"limit,omitempty"` - CreatedBefore *time.Time `json:"created_before,omitempty" url:"created_before,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - CustomMetadataHas map[string]*LocksListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"custom_metadata_has,omitempty"` - IncludeIf []LocksListRequestIncludeIfItem `json:"include_if,omitempty" url:"include_if,omitempty"` - ExcludeIf []LocksListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"exclude_if,omitempty"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"-"` + DeviceType *DeviceType `json:"device_type,omitempty" url:"-"` + DeviceTypes []DeviceType `json:"device_types,omitempty" url:"-"` + Manufacturer *Manufacturer `json:"manufacturer,omitempty" url:"-"` + DeviceIds []string `json:"device_ids,omitempty" url:"-"` + Limit *float64 `json:"limit,omitempty" url:"-"` + CreatedBefore *time.Time `json:"created_before,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + CustomMetadataHas map[string]*LocksListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"-"` + IncludeIf []LocksListRequestIncludeIfItem `json:"include_if,omitempty" url:"-"` + ExcludeIf []LocksListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"-"` } func (l *LocksListRequest) UnmarshalJSON(data []byte) error { @@ -45,17 +45,17 @@ func (l *LocksListRequest) MarshalJSON() ([]byte, error) { type embed LocksListRequest var marshaler = struct { embed - CreatedBefore *core.DateTime `json:"created_before,omitempty"` + CreatedBefore *internal.DateTime `json:"created_before,omitempty"` }{ embed: embed(*l), - CreatedBefore: core.NewOptionalDateTime(l.CreatedBefore), + CreatedBefore: internal.NewOptionalDateTime(l.CreatedBefore), } return json.Marshal(marshaler) } type LocksLockDoorRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type LocksGetResponse struct { @@ -63,7 +63,33 @@ type LocksGetResponse struct { Device *Device `json:"device,omitempty" url:"device,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (l *LocksGetResponse) GetLock() *Device { + if l == nil { + return nil + } + return l.Lock +} + +func (l *LocksGetResponse) GetDevice() *Device { + if l == nil { + return nil + } + return l.Device +} + +func (l *LocksGetResponse) GetOk() bool { + if l == nil { + return false + } + return l.Ok +} + +func (l *LocksGetResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *LocksGetResponse) UnmarshalJSON(data []byte) error { @@ -73,46 +99,66 @@ func (l *LocksGetResponse) UnmarshalJSON(data []byte) error { return err } *l = LocksGetResponse(value) - l._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l.rawJSON = json.RawMessage(data) return nil } func (l *LocksGetResponse) String() string { - if len(l._rawJSON) > 0 { - if value, err := core.StringifyJSON(l._rawJSON); err == nil { + if len(l.rawJSON) > 0 { + if value, err := internal.StringifyJSON(l.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(l); err == nil { + if value, err := internal.StringifyJSON(l); err == nil { return value } return fmt.Sprintf("%#v", l) } type LocksListRequestCustomMetadataHasValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewLocksListRequestCustomMetadataHasValueFromString(value string) *LocksListRequestCustomMetadataHasValue { - return &LocksListRequestCustomMetadataHasValue{typeName: "string", String: value} + return &LocksListRequestCustomMetadataHasValue{typ: "String", String: value} } func NewLocksListRequestCustomMetadataHasValueFromBoolean(value bool) *LocksListRequestCustomMetadataHasValue { - return &LocksListRequestCustomMetadataHasValue{typeName: "boolean", Boolean: value} + return &LocksListRequestCustomMetadataHasValue{typ: "Boolean", Boolean: value} +} + +func (l *LocksListRequestCustomMetadataHasValue) GetString() string { + if l == nil { + return "" + } + return l.String +} + +func (l *LocksListRequestCustomMetadataHasValue) GetBoolean() bool { + if l == nil { + return false + } + return l.Boolean } func (l *LocksListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - l.typeName = "string" + l.typ = "String" l.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - l.typeName = "boolean" + l.typ = "Boolean" l.Boolean = valueBoolean return nil } @@ -120,14 +166,13 @@ func (l *LocksListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) erro } func (l LocksListRequestCustomMetadataHasValue) MarshalJSON() ([]byte, error) { - switch l.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", l.typeName, l) - case "string": + if l.typ == "String" || l.String != "" { return json.Marshal(l.String) - case "boolean": + } + if l.typ == "Boolean" || l.Boolean != false { return json.Marshal(l.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", l) } type LocksListRequestCustomMetadataHasValueVisitor interface { @@ -136,14 +181,13 @@ type LocksListRequestCustomMetadataHasValueVisitor interface { } func (l *LocksListRequestCustomMetadataHasValue) Accept(visitor LocksListRequestCustomMetadataHasValueVisitor) error { - switch l.typeName { - default: - return fmt.Errorf("invalid type %s in %T", l.typeName, l) - case "string": + if l.typ == "String" || l.String != "" { return visitor.VisitString(l.String) - case "boolean": + } + if l.typ == "Boolean" || l.Boolean != false { return visitor.VisitBoolean(l.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", l) } type LocksListRequestExcludeIfItem string @@ -154,6 +198,8 @@ const ( LocksListRequestExcludeIfItemCanProgramOfflineAccessCodes LocksListRequestExcludeIfItem = "can_program_offline_access_codes" LocksListRequestExcludeIfItemCanProgramOnlineAccessCodes LocksListRequestExcludeIfItem = "can_program_online_access_codes" LocksListRequestExcludeIfItemCanSimulateRemoval LocksListRequestExcludeIfItem = "can_simulate_removal" + LocksListRequestExcludeIfItemCanSimulateConnection LocksListRequestExcludeIfItem = "can_simulate_connection" + LocksListRequestExcludeIfItemCanSimulateDisconnection LocksListRequestExcludeIfItem = "can_simulate_disconnection" ) func NewLocksListRequestExcludeIfItemFromString(s string) (LocksListRequestExcludeIfItem, error) { @@ -168,6 +214,10 @@ func NewLocksListRequestExcludeIfItemFromString(s string) (LocksListRequestExclu return LocksListRequestExcludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return LocksListRequestExcludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return LocksListRequestExcludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return LocksListRequestExcludeIfItemCanSimulateDisconnection, nil } var t LocksListRequestExcludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -185,6 +235,8 @@ const ( LocksListRequestIncludeIfItemCanProgramOfflineAccessCodes LocksListRequestIncludeIfItem = "can_program_offline_access_codes" LocksListRequestIncludeIfItemCanProgramOnlineAccessCodes LocksListRequestIncludeIfItem = "can_program_online_access_codes" LocksListRequestIncludeIfItemCanSimulateRemoval LocksListRequestIncludeIfItem = "can_simulate_removal" + LocksListRequestIncludeIfItemCanSimulateConnection LocksListRequestIncludeIfItem = "can_simulate_connection" + LocksListRequestIncludeIfItemCanSimulateDisconnection LocksListRequestIncludeIfItem = "can_simulate_disconnection" ) func NewLocksListRequestIncludeIfItemFromString(s string) (LocksListRequestIncludeIfItem, error) { @@ -199,6 +251,10 @@ func NewLocksListRequestIncludeIfItemFromString(s string) (LocksListRequestInclu return LocksListRequestIncludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return LocksListRequestIncludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return LocksListRequestIncludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return LocksListRequestIncludeIfItemCanSimulateDisconnection, nil } var t LocksListRequestIncludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -213,7 +269,33 @@ type LocksListResponse struct { Devices []*Device `json:"devices,omitempty" url:"devices,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (l *LocksListResponse) GetLocks() []*Device { + if l == nil { + return nil + } + return l.Locks +} + +func (l *LocksListResponse) GetDevices() []*Device { + if l == nil { + return nil + } + return l.Devices +} + +func (l *LocksListResponse) GetOk() bool { + if l == nil { + return false + } + return l.Ok +} + +func (l *LocksListResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *LocksListResponse) UnmarshalJSON(data []byte) error { @@ -223,17 +305,22 @@ func (l *LocksListResponse) UnmarshalJSON(data []byte) error { return err } *l = LocksListResponse(value) - l._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l.rawJSON = json.RawMessage(data) return nil } func (l *LocksListResponse) String() string { - if len(l._rawJSON) > 0 { - if value, err := core.StringifyJSON(l._rawJSON); err == nil { + if len(l.rawJSON) > 0 { + if value, err := internal.StringifyJSON(l.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(l); err == nil { + if value, err := internal.StringifyJSON(l); err == nil { return value } return fmt.Sprintf("%#v", l) @@ -243,7 +330,26 @@ type LocksLockDoorResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (l *LocksLockDoorResponse) GetActionAttempt() *ActionAttempt { + if l == nil { + return nil + } + return l.ActionAttempt +} + +func (l *LocksLockDoorResponse) GetOk() bool { + if l == nil { + return false + } + return l.Ok +} + +func (l *LocksLockDoorResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *LocksLockDoorResponse) UnmarshalJSON(data []byte) error { @@ -253,17 +359,22 @@ func (l *LocksLockDoorResponse) UnmarshalJSON(data []byte) error { return err } *l = LocksLockDoorResponse(value) - l._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l.rawJSON = json.RawMessage(data) return nil } func (l *LocksLockDoorResponse) String() string { - if len(l._rawJSON) > 0 { - if value, err := core.StringifyJSON(l._rawJSON); err == nil { + if len(l.rawJSON) > 0 { + if value, err := internal.StringifyJSON(l.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(l); err == nil { + if value, err := internal.StringifyJSON(l); err == nil { return value } return fmt.Sprintf("%#v", l) @@ -273,7 +384,26 @@ type LocksUnlockDoorResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (l *LocksUnlockDoorResponse) GetActionAttempt() *ActionAttempt { + if l == nil { + return nil + } + return l.ActionAttempt +} + +func (l *LocksUnlockDoorResponse) GetOk() bool { + if l == nil { + return false + } + return l.Ok +} + +func (l *LocksUnlockDoorResponse) GetExtraProperties() map[string]interface{} { + return l.extraProperties } func (l *LocksUnlockDoorResponse) UnmarshalJSON(data []byte) error { @@ -283,23 +413,28 @@ func (l *LocksUnlockDoorResponse) UnmarshalJSON(data []byte) error { return err } *l = LocksUnlockDoorResponse(value) - l._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *l) + if err != nil { + return err + } + l.extraProperties = extraProperties + l.rawJSON = json.RawMessage(data) return nil } func (l *LocksUnlockDoorResponse) String() string { - if len(l._rawJSON) > 0 { - if value, err := core.StringifyJSON(l._rawJSON); err == nil { + if len(l.rawJSON) > 0 { + if value, err := internal.StringifyJSON(l.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(l); err == nil { + if value, err := internal.StringifyJSON(l); err == nil { return value } return fmt.Sprintf("%#v", l) } type LocksUnlockDoorRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } diff --git a/locks/client.go b/locks/client.go index 1a046c0..9394a22 100644 --- a/locks/client.go +++ b/locks/client.go @@ -3,20 +3,17 @@ package locks import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "locks/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/locks/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.LocksGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "locks/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/locks/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.LocksListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -166,56 +139,44 @@ func (c *Client) LockDoor( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "locks/lock_door" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/locks/lock_door" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.LocksLockDoorResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -229,56 +190,44 @@ func (c *Client) UnlockDoor( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "locks/unlock_door" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/locks/unlock_door" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.LocksUnlockDoorResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/networks.go b/networks.go index a7f4215..f9dfd77 100644 --- a/networks.go +++ b/networks.go @@ -5,21 +5,129 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" + time "time" ) type NetworksGetRequest struct { - NetworkId string `json:"network_id" url:"network_id"` + NetworkId string `json:"network_id" url:"-"` } type NetworksListRequest struct { } +type Network struct { + NetworkId string `json:"network_id" url:"network_id"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + DisplayName string `json:"display_name" url:"display_name"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *Network) GetNetworkId() string { + if n == nil { + return "" + } + return n.NetworkId +} + +func (n *Network) GetWorkspaceId() string { + if n == nil { + return "" + } + return n.WorkspaceId +} + +func (n *Network) GetDisplayName() string { + if n == nil { + return "" + } + return n.DisplayName +} + +func (n *Network) GetCreatedAt() time.Time { + if n == nil { + return time.Time{} + } + return n.CreatedAt +} + +func (n *Network) GetExtraProperties() map[string]interface{} { + return n.extraProperties +} + +func (n *Network) UnmarshalJSON(data []byte) error { + type embed Network + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*n), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *n = Network(unmarshaler.embed) + n.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) + return nil +} + +func (n *Network) MarshalJSON() ([]byte, error) { + type embed Network + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*n), + CreatedAt: internal.NewDateTime(n.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (n *Network) String() string { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(n); err == nil { + return value + } + return fmt.Sprintf("%#v", n) +} + type NetworksGetResponse struct { Network *Network `json:"network,omitempty" url:"network,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NetworksGetResponse) GetNetwork() *Network { + if n == nil { + return nil + } + return n.Network +} + +func (n *NetworksGetResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NetworksGetResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NetworksGetResponse) UnmarshalJSON(data []byte) error { @@ -29,17 +137,22 @@ func (n *NetworksGetResponse) UnmarshalJSON(data []byte) error { return err } *n = NetworksGetResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NetworksGetResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) @@ -49,7 +162,26 @@ type NetworksListResponse struct { Networks []*Network `json:"networks,omitempty" url:"networks,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NetworksListResponse) GetNetworks() []*Network { + if n == nil { + return nil + } + return n.Networks +} + +func (n *NetworksListResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NetworksListResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NetworksListResponse) UnmarshalJSON(data []byte) error { @@ -59,17 +191,22 @@ func (n *NetworksListResponse) UnmarshalJSON(data []byte) error { return err } *n = NetworksListResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NetworksListResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) diff --git a/networks/client.go b/networks/client.go index b8da773..bb20beb 100644 --- a/networks/client.go +++ b/networks/client.go @@ -3,20 +3,17 @@ package networks import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Network, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "networks/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/networks/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.NetworksGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Network, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "networks/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/networks/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.NetworksListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/noisesensors/client/client.go b/noisesensors/client/client.go index de3232a..77d79b2 100644 --- a/noisesensors/client/client.go +++ b/noisesensors/client/client.go @@ -4,6 +4,7 @@ package client import ( core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" noisethresholds "github.com/seamapi/go/noisesensors/noisethresholds" simulate "github.com/seamapi/go/noisesensors/simulate" option "github.com/seamapi/go/option" @@ -12,7 +13,7 @@ import ( type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header NoiseThresholds *noisethresholds.Client @@ -23,8 +24,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, diff --git a/noisesensors/noise_thresholds.go b/noisesensors/noise_thresholds.go index 862cafd..e01551a 100644 --- a/noisesensors/noise_thresholds.go +++ b/noisesensors/noise_thresholds.go @@ -6,32 +6,32 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type NoiseThresholdsCreateRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - StartsDailyAt string `json:"starts_daily_at" url:"starts_daily_at"` - EndsDailyAt string `json:"ends_daily_at" url:"ends_daily_at"` - NoiseThresholdDecibels *float64 `json:"noise_threshold_decibels,omitempty" url:"noise_threshold_decibels,omitempty"` - NoiseThresholdNrs *float64 `json:"noise_threshold_nrs,omitempty" url:"noise_threshold_nrs,omitempty"` + DeviceId string `json:"device_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + StartsDailyAt string `json:"starts_daily_at" url:"-"` + EndsDailyAt string `json:"ends_daily_at" url:"-"` + NoiseThresholdDecibels *float64 `json:"noise_threshold_decibels,omitempty" url:"-"` + NoiseThresholdNrs *float64 `json:"noise_threshold_nrs,omitempty" url:"-"` } type NoiseThresholdsDeleteRequest struct { - NoiseThresholdId string `json:"noise_threshold_id" url:"noise_threshold_id"` - DeviceId string `json:"device_id" url:"device_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + NoiseThresholdId string `json:"noise_threshold_id" url:"-"` + DeviceId string `json:"device_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type NoiseThresholdsGetRequest struct { - NoiseThresholdId string `json:"noise_threshold_id" url:"noise_threshold_id"` + NoiseThresholdId string `json:"noise_threshold_id" url:"-"` } type NoiseThresholdsListRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - IsProgrammed *bool `json:"is_programmed,omitempty" url:"is_programmed,omitempty"` + DeviceId string `json:"device_id" url:"-"` + IsProgrammed *bool `json:"is_programmed,omitempty" url:"-"` } type NoiseThresholdsCreateResponse struct { @@ -39,7 +39,33 @@ type NoiseThresholdsCreateResponse struct { NoiseThreshold *seamapigo.NoiseThreshold `json:"noise_threshold,omitempty" url:"noise_threshold,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NoiseThresholdsCreateResponse) GetActionAttempt() *seamapigo.ActionAttempt { + if n == nil { + return nil + } + return n.ActionAttempt +} + +func (n *NoiseThresholdsCreateResponse) GetNoiseThreshold() *seamapigo.NoiseThreshold { + if n == nil { + return nil + } + return n.NoiseThreshold +} + +func (n *NoiseThresholdsCreateResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NoiseThresholdsCreateResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NoiseThresholdsCreateResponse) UnmarshalJSON(data []byte) error { @@ -49,17 +75,22 @@ func (n *NoiseThresholdsCreateResponse) UnmarshalJSON(data []byte) error { return err } *n = NoiseThresholdsCreateResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NoiseThresholdsCreateResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) @@ -69,7 +100,26 @@ type NoiseThresholdsDeleteResponse struct { ActionAttempt *seamapigo.ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NoiseThresholdsDeleteResponse) GetActionAttempt() *seamapigo.ActionAttempt { + if n == nil { + return nil + } + return n.ActionAttempt +} + +func (n *NoiseThresholdsDeleteResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NoiseThresholdsDeleteResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NoiseThresholdsDeleteResponse) UnmarshalJSON(data []byte) error { @@ -79,17 +129,22 @@ func (n *NoiseThresholdsDeleteResponse) UnmarshalJSON(data []byte) error { return err } *n = NoiseThresholdsDeleteResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NoiseThresholdsDeleteResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) @@ -99,7 +154,26 @@ type NoiseThresholdsGetResponse struct { NoiseThreshold *seamapigo.NoiseThreshold `json:"noise_threshold,omitempty" url:"noise_threshold,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NoiseThresholdsGetResponse) GetNoiseThreshold() *seamapigo.NoiseThreshold { + if n == nil { + return nil + } + return n.NoiseThreshold +} + +func (n *NoiseThresholdsGetResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NoiseThresholdsGetResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NoiseThresholdsGetResponse) UnmarshalJSON(data []byte) error { @@ -109,17 +183,22 @@ func (n *NoiseThresholdsGetResponse) UnmarshalJSON(data []byte) error { return err } *n = NoiseThresholdsGetResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NoiseThresholdsGetResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) @@ -129,7 +208,26 @@ type NoiseThresholdsListResponse struct { NoiseThresholds []*seamapigo.NoiseThreshold `json:"noise_thresholds,omitempty" url:"noise_thresholds,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NoiseThresholdsListResponse) GetNoiseThresholds() []*seamapigo.NoiseThreshold { + if n == nil { + return nil + } + return n.NoiseThresholds +} + +func (n *NoiseThresholdsListResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NoiseThresholdsListResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NoiseThresholdsListResponse) UnmarshalJSON(data []byte) error { @@ -139,17 +237,22 @@ func (n *NoiseThresholdsListResponse) UnmarshalJSON(data []byte) error { return err } *n = NoiseThresholdsListResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NoiseThresholdsListResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) @@ -159,7 +262,26 @@ type NoiseThresholdsUpdateResponse struct { ActionAttempt *seamapigo.ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NoiseThresholdsUpdateResponse) GetActionAttempt() *seamapigo.ActionAttempt { + if n == nil { + return nil + } + return n.ActionAttempt +} + +func (n *NoiseThresholdsUpdateResponse) GetOk() bool { + if n == nil { + return false + } + return n.Ok +} + +func (n *NoiseThresholdsUpdateResponse) GetExtraProperties() map[string]interface{} { + return n.extraProperties } func (n *NoiseThresholdsUpdateResponse) UnmarshalJSON(data []byte) error { @@ -169,29 +291,34 @@ func (n *NoiseThresholdsUpdateResponse) UnmarshalJSON(data []byte) error { return err } *n = NoiseThresholdsUpdateResponse(value) - n._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { + return err + } + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) return nil } func (n *NoiseThresholdsUpdateResponse) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(n); err == nil { + if value, err := internal.StringifyJSON(n); err == nil { return value } return fmt.Sprintf("%#v", n) } type NoiseThresholdsUpdateRequest struct { - NoiseThresholdId string `json:"noise_threshold_id" url:"noise_threshold_id"` - DeviceId string `json:"device_id" url:"device_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - StartsDailyAt *string `json:"starts_daily_at,omitempty" url:"starts_daily_at,omitempty"` - EndsDailyAt *string `json:"ends_daily_at,omitempty" url:"ends_daily_at,omitempty"` - NoiseThresholdDecibels *float64 `json:"noise_threshold_decibels,omitempty" url:"noise_threshold_decibels,omitempty"` - NoiseThresholdNrs *float64 `json:"noise_threshold_nrs,omitempty" url:"noise_threshold_nrs,omitempty"` + NoiseThresholdId string `json:"noise_threshold_id" url:"-"` + DeviceId string `json:"device_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + StartsDailyAt *string `json:"starts_daily_at,omitempty" url:"-"` + EndsDailyAt *string `json:"ends_daily_at,omitempty" url:"-"` + NoiseThresholdDecibels *float64 `json:"noise_threshold_decibels,omitempty" url:"-"` + NoiseThresholdNrs *float64 `json:"noise_threshold_nrs,omitempty" url:"-"` } diff --git a/noisesensors/noisethresholds/client.go b/noisesensors/noisethresholds/client.go index ce5eb6c..ef6fd7e 100644 --- a/noisesensors/noisethresholds/client.go +++ b/noisesensors/noisethresholds/client.go @@ -3,21 +3,18 @@ package noisethresholds import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" noisesensors "github.com/seamapi/go/noisesensors" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.NoiseThreshold, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "noise_sensors/noise_thresholds/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/noise_sensors/noise_thresholds/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *noisesensors.NoiseThresholdsCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*noisesensors.NoiseThresholdsDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "noise_sensors/noise_thresholds/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/noise_sensors/noise_thresholds/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *noisesensors.NoiseThresholdsDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.NoiseThreshold, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "noise_sensors/noise_thresholds/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/noise_sensors/noise_thresholds/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *noisesensors.NoiseThresholdsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.NoiseThreshold, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "noise_sensors/noise_thresholds/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/noise_sensors/noise_thresholds/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *noisesensors.NoiseThresholdsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -293,56 +242,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*noisesensors.NoiseThresholdsUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "noise_sensors/noise_thresholds/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/noise_sensors/noise_thresholds/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *noisesensors.NoiseThresholdsUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/noisesensors/simulate.go b/noisesensors/simulate.go index 5f06935..1c23f0f 100644 --- a/noisesensors/simulate.go +++ b/noisesensors/simulate.go @@ -5,17 +5,29 @@ package noisesensors import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type SimulateTriggerNoiseThresholdRequest struct { - DeviceId string `json:"device_id" url:"device_id"` + DeviceId string `json:"device_id" url:"-"` } type SimulateTriggerNoiseThresholdResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateTriggerNoiseThresholdResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SimulateTriggerNoiseThresholdResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SimulateTriggerNoiseThresholdResponse) UnmarshalJSON(data []byte) error { @@ -25,17 +37,22 @@ func (s *SimulateTriggerNoiseThresholdResponse) UnmarshalJSON(data []byte) error return err } *s = SimulateTriggerNoiseThresholdResponse(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SimulateTriggerNoiseThresholdResponse) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) diff --git a/noisesensors/simulate/client.go b/noisesensors/simulate/client.go index 009e725..dfcaca0 100644 --- a/noisesensors/simulate/client.go +++ b/noisesensors/simulate/client.go @@ -3,21 +3,18 @@ package simulate import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" noisesensors "github.com/seamapi/go/noisesensors" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) TriggerNoiseThreshold( opts ...option.RequestOption, ) (*noisesensors.SimulateTriggerNoiseThresholdResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "noise_sensors/simulate/trigger_noise_threshold" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/noise_sensors/simulate/trigger_noise_threshold" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *noisesensors.SimulateTriggerNoiseThresholdResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/option/request_option.go b/option/request_option.go index ad59428..250fbe4 100644 --- a/option/request_option.go +++ b/option/request_option.go @@ -5,6 +5,7 @@ package option import ( core "github.com/seamapi/go/core" http "net/http" + url "net/url" ) // RequestOption adapts the behavior of an indivdual request. @@ -33,6 +34,28 @@ func WithHTTPHeader(httpHeader http.Header) *core.HTTPHeaderOption { } } +// WithBodyProperties adds the given body properties to the request. +func WithBodyProperties(bodyProperties map[string]interface{}) *core.BodyPropertiesOption { + copiedBodyProperties := make(map[string]interface{}, len(bodyProperties)) + for key, value := range bodyProperties { + copiedBodyProperties[key] = value + } + return &core.BodyPropertiesOption{ + BodyProperties: copiedBodyProperties, + } +} + +// WithQueryParameters adds the given query parameters to the request. +func WithQueryParameters(queryParameters url.Values) *core.QueryParametersOption { + copiedQueryParameters := make(url.Values, len(queryParameters)) + for key, values := range queryParameters { + copiedQueryParameters[key] = values + } + return &core.QueryParametersOption{ + QueryParameters: copiedQueryParameters, + } +} + // WithMaxAttempts configures the maximum number of retry attempts. func WithMaxAttempts(attempts uint) *core.MaxAttemptsOption { return &core.MaxAttemptsOption{ diff --git a/phones.go b/phones.go index 593e421..be4a21b 100644 --- a/phones.go +++ b/phones.go @@ -5,21 +5,33 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type PhonesDeactivateRequest struct { - DeviceId string `json:"device_id" url:"device_id"` + DeviceId string `json:"device_id" url:"-"` } type PhonesListRequest struct { - OwnerUserIdentityId *string `json:"owner_user_identity_id,omitempty" url:"owner_user_identity_id,omitempty"` + OwnerUserIdentityId *string `json:"owner_user_identity_id,omitempty" url:"-"` } type PhonesDeactivateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhonesDeactivateResponse) GetOk() bool { + if p == nil { + return false + } + return p.Ok +} + +func (p *PhonesDeactivateResponse) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhonesDeactivateResponse) UnmarshalJSON(data []byte) error { @@ -29,17 +41,22 @@ func (p *PhonesDeactivateResponse) UnmarshalJSON(data []byte) error { return err } *p = PhonesDeactivateResponse(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhonesDeactivateResponse) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -49,7 +66,26 @@ type PhonesListResponse struct { Phones []*Phone `json:"phones,omitempty" url:"phones,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhonesListResponse) GetPhones() []*Phone { + if p == nil { + return nil + } + return p.Phones +} + +func (p *PhonesListResponse) GetOk() bool { + if p == nil { + return false + } + return p.Ok +} + +func (p *PhonesListResponse) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhonesListResponse) UnmarshalJSON(data []byte) error { @@ -59,17 +95,22 @@ func (p *PhonesListResponse) UnmarshalJSON(data []byte) error { return err } *p = PhonesListResponse(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhonesListResponse) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) diff --git a/phones/client/client.go b/phones/client/client.go index 8a7bff3..7207056 100644 --- a/phones/client/client.go +++ b/phones/client/client.go @@ -3,21 +3,18 @@ package client import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" simulate "github.com/seamapi/go/phones/simulate" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header Simulate *simulate.Client @@ -27,8 +24,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -44,56 +41,44 @@ func (c *Client) Deactivate( opts ...option.RequestOption, ) (*seamapigo.PhonesDeactivateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "phones/deactivate" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/phones/deactivate" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.PhonesDeactivateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -107,56 +92,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Phone, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "phones/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/phones/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.PhonesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/phones/simulate.go b/phones/simulate.go index cb6fa86..fcc564a 100644 --- a/phones/simulate.go +++ b/phones/simulate.go @@ -6,14 +6,14 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type SimulateCreateSandboxPhoneRequest struct { - CustomSdkInstallationId *string `json:"custom_sdk_installation_id,omitempty" url:"custom_sdk_installation_id,omitempty"` - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - PhoneMetadata *SimulateCreateSandboxPhoneRequestPhoneMetadata `json:"phone_metadata,omitempty" url:"phone_metadata,omitempty"` - AssaAbloyMetadata *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata `json:"assa_abloy_metadata,omitempty" url:"assa_abloy_metadata,omitempty"` + CustomSdkInstallationId *string `json:"custom_sdk_installation_id,omitempty" url:"-"` + UserIdentityId string `json:"user_identity_id" url:"-"` + PhoneMetadata *SimulateCreateSandboxPhoneRequestPhoneMetadata `json:"phone_metadata,omitempty" url:"-"` + AssaAbloyMetadata *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata `json:"assa_abloy_metadata,omitempty" url:"-"` } type SimulateCreateSandboxPhoneRequestAssaAbloyMetadata struct { @@ -24,7 +24,54 @@ type SimulateCreateSandboxPhoneRequestAssaAbloyMetadata struct { SeosAppletVersion *string `json:"seos_applet_version,omitempty" url:"seos_applet_version,omitempty"` SeosTsmEndpointId *float64 `json:"seos_tsm_endpoint_id,omitempty" url:"seos_tsm_endpoint_id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetBleCapability() *bool { + if s == nil { + return nil + } + return s.BleCapability +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetHceCapability() *bool { + if s == nil { + return nil + } + return s.HceCapability +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetNfcCapability() *bool { + if s == nil { + return nil + } + return s.NfcCapability +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetApplicationVersion() *string { + if s == nil { + return nil + } + return s.ApplicationVersion +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetSeosAppletVersion() *string { + if s == nil { + return nil + } + return s.SeosAppletVersion +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetSeosTsmEndpointId() *float64 { + if s == nil { + return nil + } + return s.SeosTsmEndpointId +} + +func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) UnmarshalJSON(data []byte) error { @@ -34,17 +81,22 @@ func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) UnmarshalJSON(data return err } *s = SimulateCreateSandboxPhoneRequestAssaAbloyMetadata(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SimulateCreateSandboxPhoneRequestAssaAbloyMetadata) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) @@ -56,7 +108,40 @@ type SimulateCreateSandboxPhoneRequestPhoneMetadata struct { DeviceManufacturer *string `json:"device_manufacturer,omitempty" url:"device_manufacturer,omitempty"` DeviceModel *string `json:"device_model,omitempty" url:"device_model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) GetOperatingSystem() *seamapigo.PhoneOperatingSystem { + if s == nil { + return nil + } + return s.OperatingSystem +} + +func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) GetOsVersion() *string { + if s == nil { + return nil + } + return s.OsVersion +} + +func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) GetDeviceManufacturer() *string { + if s == nil { + return nil + } + return s.DeviceManufacturer +} + +func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) GetDeviceModel() *string { + if s == nil { + return nil + } + return s.DeviceModel +} + +func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) UnmarshalJSON(data []byte) error { @@ -66,17 +151,22 @@ func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) UnmarshalJSON(data []by return err } *s = SimulateCreateSandboxPhoneRequestPhoneMetadata(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SimulateCreateSandboxPhoneRequestPhoneMetadata) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) @@ -86,7 +176,26 @@ type SimulateCreateSandboxPhoneResponse struct { Phone *seamapigo.Phone `json:"phone,omitempty" url:"phone,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (s *SimulateCreateSandboxPhoneResponse) GetPhone() *seamapigo.Phone { + if s == nil { + return nil + } + return s.Phone +} + +func (s *SimulateCreateSandboxPhoneResponse) GetOk() bool { + if s == nil { + return false + } + return s.Ok +} + +func (s *SimulateCreateSandboxPhoneResponse) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *SimulateCreateSandboxPhoneResponse) UnmarshalJSON(data []byte) error { @@ -96,17 +205,22 @@ func (s *SimulateCreateSandboxPhoneResponse) UnmarshalJSON(data []byte) error { return err } *s = SimulateCreateSandboxPhoneResponse(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *SimulateCreateSandboxPhoneResponse) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) diff --git a/phones/simulate/client.go b/phones/simulate/client.go index bda0cc3..c6846b9 100644 --- a/phones/simulate/client.go +++ b/phones/simulate/client.go @@ -3,21 +3,18 @@ package simulate import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" phones "github.com/seamapi/go/phones" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) CreateSandboxPhone( opts ...option.RequestOption, ) (*seamapigo.Phone, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "phones/simulate/create_sandbox_phone" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/phones/simulate/create_sandbox_phone" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *phones.SimulateCreateSandboxPhoneResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/thermostats.go b/thermostats.go index 769961e..4fe841c 100644 --- a/thermostats.go +++ b/thermostats.go @@ -5,53 +5,53 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) type ThermostatsCoolRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"cooling_set_point_celsius,omitempty"` - CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"cooling_set_point_fahrenheit,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"-"` + CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type ThermostatsGetRequest struct { - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` + DeviceId *string `json:"device_id,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` } type ThermostatsHeatRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"heating_set_point_celsius,omitempty"` - HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"heating_set_point_fahrenheit,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"-"` + HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type ThermostatsHeatCoolRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"heating_set_point_celsius,omitempty"` - HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"heating_set_point_fahrenheit,omitempty"` - CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"cooling_set_point_celsius,omitempty"` - CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"cooling_set_point_fahrenheit,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"-"` + HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"-"` + CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"-"` + CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type ThermostatsListRequest struct { // List all devices owned by this connected account - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"connect_webview_id,omitempty"` - DeviceType *DeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` - DeviceTypes []DeviceType `json:"device_types,omitempty" url:"device_types,omitempty"` - Manufacturer *Manufacturer `json:"manufacturer,omitempty" url:"manufacturer,omitempty"` - DeviceIds []string `json:"device_ids,omitempty" url:"device_ids,omitempty"` - Limit *float64 `json:"limit,omitempty" url:"limit,omitempty"` - CreatedBefore *time.Time `json:"created_before,omitempty" url:"created_before,omitempty"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - CustomMetadataHas map[string]*ThermostatsListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"custom_metadata_has,omitempty"` - IncludeIf []ThermostatsListRequestIncludeIfItem `json:"include_if,omitempty" url:"include_if,omitempty"` - ExcludeIf []ThermostatsListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"exclude_if,omitempty"` + ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"-"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"-"` + ConnectWebviewId *string `json:"connect_webview_id,omitempty" url:"-"` + DeviceType *DeviceType `json:"device_type,omitempty" url:"-"` + DeviceTypes []DeviceType `json:"device_types,omitempty" url:"-"` + Manufacturer *Manufacturer `json:"manufacturer,omitempty" url:"-"` + DeviceIds []string `json:"device_ids,omitempty" url:"-"` + Limit *float64 `json:"limit,omitempty" url:"-"` + CreatedBefore *time.Time `json:"created_before,omitempty" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` + CustomMetadataHas map[string]*ThermostatsListRequestCustomMetadataHasValue `json:"custom_metadata_has,omitempty" url:"-"` + IncludeIf []ThermostatsListRequestIncludeIfItem `json:"include_if,omitempty" url:"-"` + ExcludeIf []ThermostatsListRequestExcludeIfItem `json:"exclude_if,omitempty" url:"-"` } func (t *ThermostatsListRequest) UnmarshalJSON(data []byte) error { @@ -68,31 +68,72 @@ func (t *ThermostatsListRequest) MarshalJSON() ([]byte, error) { type embed ThermostatsListRequest var marshaler = struct { embed - CreatedBefore *core.DateTime `json:"created_before,omitempty"` + CreatedBefore *internal.DateTime `json:"created_before,omitempty"` }{ embed: embed(*t), - CreatedBefore: core.NewOptionalDateTime(t.CreatedBefore), + CreatedBefore: internal.NewOptionalDateTime(t.CreatedBefore), } return json.Marshal(marshaler) } type ThermostatsOffRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` } type ThermostatsSetFanModeRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - FanMode *FanMode `json:"fan_mode,omitempty" url:"fan_mode,omitempty"` - FanModeSetting *ThermostatsSetFanModeRequestFanModeSetting `json:"fan_mode_setting,omitempty" url:"fan_mode_setting,omitempty"` - Sync *bool `json:"sync,omitempty" url:"sync,omitempty"` + DeviceId string `json:"device_id" url:"-"` + FanMode *FanMode `json:"fan_mode,omitempty" url:"-"` + FanModeSetting *ThermostatsSetFanModeRequestFanModeSetting `json:"fan_mode_setting,omitempty" url:"-"` + Sync *bool `json:"sync,omitempty" url:"-"` +} + +type FanMode string + +const ( + FanModeAuto FanMode = "auto" + FanModeOn FanMode = "on" +) + +func NewFanModeFromString(s string) (FanMode, error) { + switch s { + case "auto": + return FanModeAuto, nil + case "on": + return FanModeOn, nil + } + var t FanMode + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (f FanMode) Ptr() *FanMode { + return &f } type ThermostatsCoolResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsCoolResponse) GetActionAttempt() *ActionAttempt { + if t == nil { + return nil + } + return t.ActionAttempt +} + +func (t *ThermostatsCoolResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsCoolResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsCoolResponse) UnmarshalJSON(data []byte) error { @@ -102,17 +143,22 @@ func (t *ThermostatsCoolResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsCoolResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsCoolResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) @@ -122,7 +168,26 @@ type ThermostatsGetResponse struct { Thermostat *Device `json:"thermostat,omitempty" url:"thermostat,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsGetResponse) GetThermostat() *Device { + if t == nil { + return nil + } + return t.Thermostat +} + +func (t *ThermostatsGetResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsGetResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsGetResponse) UnmarshalJSON(data []byte) error { @@ -132,17 +197,22 @@ func (t *ThermostatsGetResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsGetResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsGetResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) @@ -152,7 +222,26 @@ type ThermostatsHeatCoolResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsHeatCoolResponse) GetActionAttempt() *ActionAttempt { + if t == nil { + return nil + } + return t.ActionAttempt +} + +func (t *ThermostatsHeatCoolResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsHeatCoolResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsHeatCoolResponse) UnmarshalJSON(data []byte) error { @@ -162,17 +251,22 @@ func (t *ThermostatsHeatCoolResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsHeatCoolResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsHeatCoolResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) @@ -182,7 +276,26 @@ type ThermostatsHeatResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsHeatResponse) GetActionAttempt() *ActionAttempt { + if t == nil { + return nil + } + return t.ActionAttempt +} + +func (t *ThermostatsHeatResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsHeatResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsHeatResponse) UnmarshalJSON(data []byte) error { @@ -192,46 +305,66 @@ func (t *ThermostatsHeatResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsHeatResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsHeatResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) } type ThermostatsListRequestCustomMetadataHasValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewThermostatsListRequestCustomMetadataHasValueFromString(value string) *ThermostatsListRequestCustomMetadataHasValue { - return &ThermostatsListRequestCustomMetadataHasValue{typeName: "string", String: value} + return &ThermostatsListRequestCustomMetadataHasValue{typ: "String", String: value} } func NewThermostatsListRequestCustomMetadataHasValueFromBoolean(value bool) *ThermostatsListRequestCustomMetadataHasValue { - return &ThermostatsListRequestCustomMetadataHasValue{typeName: "boolean", Boolean: value} + return &ThermostatsListRequestCustomMetadataHasValue{typ: "Boolean", Boolean: value} +} + +func (t *ThermostatsListRequestCustomMetadataHasValue) GetString() string { + if t == nil { + return "" + } + return t.String +} + +func (t *ThermostatsListRequestCustomMetadataHasValue) GetBoolean() bool { + if t == nil { + return false + } + return t.Boolean } func (t *ThermostatsListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - t.typeName = "string" + t.typ = "String" t.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - t.typeName = "boolean" + t.typ = "Boolean" t.Boolean = valueBoolean return nil } @@ -239,14 +372,13 @@ func (t *ThermostatsListRequestCustomMetadataHasValue) UnmarshalJSON(data []byte } func (t ThermostatsListRequestCustomMetadataHasValue) MarshalJSON() ([]byte, error) { - switch t.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", t.typeName, t) - case "string": + if t.typ == "String" || t.String != "" { return json.Marshal(t.String) - case "boolean": + } + if t.typ == "Boolean" || t.Boolean != false { return json.Marshal(t.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", t) } type ThermostatsListRequestCustomMetadataHasValueVisitor interface { @@ -255,14 +387,13 @@ type ThermostatsListRequestCustomMetadataHasValueVisitor interface { } func (t *ThermostatsListRequestCustomMetadataHasValue) Accept(visitor ThermostatsListRequestCustomMetadataHasValueVisitor) error { - switch t.typeName { - default: - return fmt.Errorf("invalid type %s in %T", t.typeName, t) - case "string": + if t.typ == "String" || t.String != "" { return visitor.VisitString(t.String) - case "boolean": + } + if t.typ == "Boolean" || t.Boolean != false { return visitor.VisitBoolean(t.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", t) } type ThermostatsListRequestExcludeIfItem string @@ -273,6 +404,8 @@ const ( ThermostatsListRequestExcludeIfItemCanProgramOfflineAccessCodes ThermostatsListRequestExcludeIfItem = "can_program_offline_access_codes" ThermostatsListRequestExcludeIfItemCanProgramOnlineAccessCodes ThermostatsListRequestExcludeIfItem = "can_program_online_access_codes" ThermostatsListRequestExcludeIfItemCanSimulateRemoval ThermostatsListRequestExcludeIfItem = "can_simulate_removal" + ThermostatsListRequestExcludeIfItemCanSimulateConnection ThermostatsListRequestExcludeIfItem = "can_simulate_connection" + ThermostatsListRequestExcludeIfItemCanSimulateDisconnection ThermostatsListRequestExcludeIfItem = "can_simulate_disconnection" ) func NewThermostatsListRequestExcludeIfItemFromString(s string) (ThermostatsListRequestExcludeIfItem, error) { @@ -287,6 +420,10 @@ func NewThermostatsListRequestExcludeIfItemFromString(s string) (ThermostatsList return ThermostatsListRequestExcludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return ThermostatsListRequestExcludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return ThermostatsListRequestExcludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return ThermostatsListRequestExcludeIfItemCanSimulateDisconnection, nil } var t ThermostatsListRequestExcludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -304,6 +441,8 @@ const ( ThermostatsListRequestIncludeIfItemCanProgramOfflineAccessCodes ThermostatsListRequestIncludeIfItem = "can_program_offline_access_codes" ThermostatsListRequestIncludeIfItemCanProgramOnlineAccessCodes ThermostatsListRequestIncludeIfItem = "can_program_online_access_codes" ThermostatsListRequestIncludeIfItemCanSimulateRemoval ThermostatsListRequestIncludeIfItem = "can_simulate_removal" + ThermostatsListRequestIncludeIfItemCanSimulateConnection ThermostatsListRequestIncludeIfItem = "can_simulate_connection" + ThermostatsListRequestIncludeIfItemCanSimulateDisconnection ThermostatsListRequestIncludeIfItem = "can_simulate_disconnection" ) func NewThermostatsListRequestIncludeIfItemFromString(s string) (ThermostatsListRequestIncludeIfItem, error) { @@ -318,6 +457,10 @@ func NewThermostatsListRequestIncludeIfItemFromString(s string) (ThermostatsList return ThermostatsListRequestIncludeIfItemCanProgramOnlineAccessCodes, nil case "can_simulate_removal": return ThermostatsListRequestIncludeIfItemCanSimulateRemoval, nil + case "can_simulate_connection": + return ThermostatsListRequestIncludeIfItemCanSimulateConnection, nil + case "can_simulate_disconnection": + return ThermostatsListRequestIncludeIfItemCanSimulateDisconnection, nil } var t ThermostatsListRequestIncludeIfItem return "", fmt.Errorf("%s is not a valid %T", s, t) @@ -331,7 +474,26 @@ type ThermostatsListResponse struct { Thermostats []*Device `json:"thermostats,omitempty" url:"thermostats,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsListResponse) GetThermostats() []*Device { + if t == nil { + return nil + } + return t.Thermostats +} + +func (t *ThermostatsListResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsListResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsListResponse) UnmarshalJSON(data []byte) error { @@ -341,17 +503,22 @@ func (t *ThermostatsListResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsListResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsListResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) @@ -361,7 +528,26 @@ type ThermostatsOffResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsOffResponse) GetActionAttempt() *ActionAttempt { + if t == nil { + return nil + } + return t.ActionAttempt +} + +func (t *ThermostatsOffResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsOffResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsOffResponse) UnmarshalJSON(data []byte) error { @@ -371,17 +557,22 @@ func (t *ThermostatsOffResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsOffResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsOffResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) @@ -413,7 +604,26 @@ type ThermostatsSetFanModeResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsSetFanModeResponse) GetActionAttempt() *ActionAttempt { + if t == nil { + return nil + } + return t.ActionAttempt +} + +func (t *ThermostatsSetFanModeResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsSetFanModeResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsSetFanModeResponse) UnmarshalJSON(data []byte) error { @@ -423,17 +633,22 @@ func (t *ThermostatsSetFanModeResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsSetFanModeResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsSetFanModeResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) @@ -449,7 +664,68 @@ type ThermostatsUpdateRequestDefaultClimateSetting struct { HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"heating_set_point_fahrenheit,omitempty"` ManualOverrideAllowed *bool `json:"manual_override_allowed,omitempty" url:"manual_override_allowed,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetAutomaticHeatingEnabled() *bool { + if t == nil { + return nil + } + return t.AutomaticHeatingEnabled +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetAutomaticCoolingEnabled() *bool { + if t == nil { + return nil + } + return t.AutomaticCoolingEnabled +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetHvacModeSetting() *ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting { + if t == nil { + return nil + } + return t.HvacModeSetting +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetCoolingSetPointCelsius() *float64 { + if t == nil { + return nil + } + return t.CoolingSetPointCelsius +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetHeatingSetPointCelsius() *float64 { + if t == nil { + return nil + } + return t.HeatingSetPointCelsius +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetCoolingSetPointFahrenheit() *float64 { + if t == nil { + return nil + } + return t.CoolingSetPointFahrenheit +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetHeatingSetPointFahrenheit() *float64 { + if t == nil { + return nil + } + return t.HeatingSetPointFahrenheit +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetManualOverrideAllowed() *bool { + if t == nil { + return nil + } + return t.ManualOverrideAllowed +} + +func (t *ThermostatsUpdateRequestDefaultClimateSetting) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsUpdateRequestDefaultClimateSetting) UnmarshalJSON(data []byte) error { @@ -459,26 +735,71 @@ func (t *ThermostatsUpdateRequestDefaultClimateSetting) UnmarshalJSON(data []byt return err } *t = ThermostatsUpdateRequestDefaultClimateSetting(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsUpdateRequestDefaultClimateSetting) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) } +type ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting string + +const ( + ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingOff ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "off" + ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeat ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "heat" + ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingCool ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "cool" + ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeatCool ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "heat_cool" +) + +func NewThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingFromString(s string) (ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting, error) { + switch s { + case "off": + return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingOff, nil + case "heat": + return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeat, nil + case "cool": + return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingCool, nil + case "heat_cool": + return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeatCool, nil + } + var t ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting + return "", fmt.Errorf("%s is not a valid %T", s, t) +} + +func (t ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting) Ptr() *ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting { + return &t +} + type ThermostatsUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (t *ThermostatsUpdateResponse) GetOk() bool { + if t == nil { + return false + } + return t.Ok +} + +func (t *ThermostatsUpdateResponse) GetExtraProperties() map[string]interface{} { + return t.extraProperties } func (t *ThermostatsUpdateResponse) UnmarshalJSON(data []byte) error { @@ -488,23 +809,28 @@ func (t *ThermostatsUpdateResponse) UnmarshalJSON(data []byte) error { return err } *t = ThermostatsUpdateResponse(value) - t._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *t) + if err != nil { + return err + } + t.extraProperties = extraProperties + t.rawJSON = json.RawMessage(data) return nil } func (t *ThermostatsUpdateResponse) String() string { - if len(t._rawJSON) > 0 { - if value, err := core.StringifyJSON(t._rawJSON); err == nil { + if len(t.rawJSON) > 0 { + if value, err := internal.StringifyJSON(t.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(t); err == nil { + if value, err := internal.StringifyJSON(t); err == nil { return value } return fmt.Sprintf("%#v", t) } type ThermostatsUpdateRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - DefaultClimateSetting *ThermostatsUpdateRequestDefaultClimateSetting `json:"default_climate_setting,omitempty" url:"default_climate_setting,omitempty"` + DeviceId string `json:"device_id" url:"-"` + DefaultClimateSetting *ThermostatsUpdateRequestDefaultClimateSetting `json:"default_climate_setting,omitempty" url:"-"` } diff --git a/thermostats/client/client.go b/thermostats/client/client.go index 902df95..0c6daf6 100644 --- a/thermostats/client/client.go +++ b/thermostats/client/client.go @@ -3,21 +3,18 @@ package client import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" climatesettingschedules "github.com/seamapi/go/thermostats/climatesettingschedules" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header ClimateSettingSchedules *climatesettingschedules.Client @@ -27,8 +24,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -44,56 +41,44 @@ func (c *Client) Cool( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/cool" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/cool" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsCoolResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -107,56 +92,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -170,56 +143,44 @@ func (c *Client) Heat( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/heat" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/heat" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsHeatResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -233,56 +194,44 @@ func (c *Client) HeatCool( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/heat_cool" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/heat_cool" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsHeatCoolResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -296,56 +245,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -359,56 +296,44 @@ func (c *Client) Off( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/off" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/off" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsOffResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -422,56 +347,44 @@ func (c *Client) SetFanMode( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/set_fan_mode" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/set_fan_mode" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsSetFanModeResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -485,56 +398,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*seamapigo.ThermostatsUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.ThermostatsUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/thermostats/climate_setting_schedules.go b/thermostats/climate_setting_schedules.go index a1b5dae..a66d9c3 100644 --- a/thermostats/climate_setting_schedules.go +++ b/thermostats/climate_setting_schedules.go @@ -6,37 +6,37 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type ClimateSettingSchedulesCreateRequest struct { - ScheduleType *string `json:"schedule_type,omitempty" url:"schedule_type,omitempty"` - DeviceId string `json:"device_id" url:"device_id"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - ScheduleStartsAt string `json:"schedule_starts_at" url:"schedule_starts_at"` - ScheduleEndsAt string `json:"schedule_ends_at" url:"schedule_ends_at"` - AutomaticHeatingEnabled *bool `json:"automatic_heating_enabled,omitempty" url:"automatic_heating_enabled,omitempty"` - AutomaticCoolingEnabled *bool `json:"automatic_cooling_enabled,omitempty" url:"automatic_cooling_enabled,omitempty"` - HvacModeSetting *ClimateSettingSchedulesCreateRequestHvacModeSetting `json:"hvac_mode_setting,omitempty" url:"hvac_mode_setting,omitempty"` - CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"cooling_set_point_celsius,omitempty"` - HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"heating_set_point_celsius,omitempty"` - CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"cooling_set_point_fahrenheit,omitempty"` - HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"heating_set_point_fahrenheit,omitempty"` - ManualOverrideAllowed *bool `json:"manual_override_allowed,omitempty" url:"manual_override_allowed,omitempty"` + ScheduleType *string `json:"schedule_type,omitempty" url:"-"` + DeviceId string `json:"device_id" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + ScheduleStartsAt string `json:"schedule_starts_at" url:"-"` + ScheduleEndsAt string `json:"schedule_ends_at" url:"-"` + AutomaticHeatingEnabled *bool `json:"automatic_heating_enabled,omitempty" url:"-"` + AutomaticCoolingEnabled *bool `json:"automatic_cooling_enabled,omitempty" url:"-"` + HvacModeSetting *ClimateSettingSchedulesCreateRequestHvacModeSetting `json:"hvac_mode_setting,omitempty" url:"-"` + CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"-"` + HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"-"` + CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"-"` + HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"-"` + ManualOverrideAllowed *bool `json:"manual_override_allowed,omitempty" url:"-"` } type ClimateSettingSchedulesDeleteRequest struct { - ClimateSettingScheduleId string `json:"climate_setting_schedule_id" url:"climate_setting_schedule_id"` + ClimateSettingScheduleId string `json:"climate_setting_schedule_id" url:"-"` } type ClimateSettingSchedulesGetRequest struct { - ClimateSettingScheduleId *string `json:"climate_setting_schedule_id,omitempty" url:"climate_setting_schedule_id,omitempty"` - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` + ClimateSettingScheduleId *string `json:"climate_setting_schedule_id,omitempty" url:"-"` + DeviceId *string `json:"device_id,omitempty" url:"-"` } type ClimateSettingSchedulesListRequest struct { - DeviceId string `json:"device_id" url:"device_id"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` + DeviceId string `json:"device_id" url:"-"` + UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"-"` } type ClimateSettingSchedulesCreateRequestHvacModeSetting string @@ -71,7 +71,26 @@ type ClimateSettingSchedulesCreateResponse struct { ClimateSettingSchedule *seamapigo.ClimateSettingSchedule `json:"climate_setting_schedule,omitempty" url:"climate_setting_schedule,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClimateSettingSchedulesCreateResponse) GetClimateSettingSchedule() *seamapigo.ClimateSettingSchedule { + if c == nil { + return nil + } + return c.ClimateSettingSchedule +} + +func (c *ClimateSettingSchedulesCreateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClimateSettingSchedulesCreateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClimateSettingSchedulesCreateResponse) UnmarshalJSON(data []byte) error { @@ -81,17 +100,22 @@ func (c *ClimateSettingSchedulesCreateResponse) UnmarshalJSON(data []byte) error return err } *c = ClimateSettingSchedulesCreateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClimateSettingSchedulesCreateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -100,7 +124,19 @@ func (c *ClimateSettingSchedulesCreateResponse) String() string { type ClimateSettingSchedulesDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClimateSettingSchedulesDeleteResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClimateSettingSchedulesDeleteResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClimateSettingSchedulesDeleteResponse) UnmarshalJSON(data []byte) error { @@ -110,17 +146,22 @@ func (c *ClimateSettingSchedulesDeleteResponse) UnmarshalJSON(data []byte) error return err } *c = ClimateSettingSchedulesDeleteResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClimateSettingSchedulesDeleteResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -130,7 +171,26 @@ type ClimateSettingSchedulesGetResponse struct { ClimateSettingSchedule *seamapigo.ClimateSettingSchedule `json:"climate_setting_schedule,omitempty" url:"climate_setting_schedule,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClimateSettingSchedulesGetResponse) GetClimateSettingSchedule() *seamapigo.ClimateSettingSchedule { + if c == nil { + return nil + } + return c.ClimateSettingSchedule +} + +func (c *ClimateSettingSchedulesGetResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClimateSettingSchedulesGetResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClimateSettingSchedulesGetResponse) UnmarshalJSON(data []byte) error { @@ -140,17 +200,22 @@ func (c *ClimateSettingSchedulesGetResponse) UnmarshalJSON(data []byte) error { return err } *c = ClimateSettingSchedulesGetResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClimateSettingSchedulesGetResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -160,7 +225,26 @@ type ClimateSettingSchedulesListResponse struct { ClimateSettingSchedules []*seamapigo.ClimateSettingSchedule `json:"climate_setting_schedules,omitempty" url:"climate_setting_schedules,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClimateSettingSchedulesListResponse) GetClimateSettingSchedules() []*seamapigo.ClimateSettingSchedule { + if c == nil { + return nil + } + return c.ClimateSettingSchedules +} + +func (c *ClimateSettingSchedulesListResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClimateSettingSchedulesListResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClimateSettingSchedulesListResponse) UnmarshalJSON(data []byte) error { @@ -170,17 +254,22 @@ func (c *ClimateSettingSchedulesListResponse) UnmarshalJSON(data []byte) error { return err } *c = ClimateSettingSchedulesListResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClimateSettingSchedulesListResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -218,7 +307,26 @@ type ClimateSettingSchedulesUpdateResponse struct { ClimateSettingSchedule *seamapigo.ClimateSettingSchedule `json:"climate_setting_schedule,omitempty" url:"climate_setting_schedule,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClimateSettingSchedulesUpdateResponse) GetClimateSettingSchedule() *seamapigo.ClimateSettingSchedule { + if c == nil { + return nil + } + return c.ClimateSettingSchedule +} + +func (c *ClimateSettingSchedulesUpdateResponse) GetOk() bool { + if c == nil { + return false + } + return c.Ok +} + +func (c *ClimateSettingSchedulesUpdateResponse) GetExtraProperties() map[string]interface{} { + return c.extraProperties } func (c *ClimateSettingSchedulesUpdateResponse) UnmarshalJSON(data []byte) error { @@ -228,34 +336,39 @@ func (c *ClimateSettingSchedulesUpdateResponse) UnmarshalJSON(data []byte) error return err } *c = ClimateSettingSchedulesUpdateResponse(value) - c._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *c) + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } func (c *ClimateSettingSchedulesUpdateResponse) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) } type ClimateSettingSchedulesUpdateRequest struct { - ClimateSettingScheduleId string `json:"climate_setting_schedule_id" url:"climate_setting_schedule_id"` - ScheduleType *string `json:"schedule_type,omitempty" url:"schedule_type,omitempty"` - Name *string `json:"name,omitempty" url:"name,omitempty"` - ScheduleStartsAt *string `json:"schedule_starts_at,omitempty" url:"schedule_starts_at,omitempty"` - ScheduleEndsAt *string `json:"schedule_ends_at,omitempty" url:"schedule_ends_at,omitempty"` - AutomaticHeatingEnabled *bool `json:"automatic_heating_enabled,omitempty" url:"automatic_heating_enabled,omitempty"` - AutomaticCoolingEnabled *bool `json:"automatic_cooling_enabled,omitempty" url:"automatic_cooling_enabled,omitempty"` - HvacModeSetting *ClimateSettingSchedulesUpdateRequestHvacModeSetting `json:"hvac_mode_setting,omitempty" url:"hvac_mode_setting,omitempty"` - CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"cooling_set_point_celsius,omitempty"` - HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"heating_set_point_celsius,omitempty"` - CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"cooling_set_point_fahrenheit,omitempty"` - HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"heating_set_point_fahrenheit,omitempty"` - ManualOverrideAllowed *bool `json:"manual_override_allowed,omitempty" url:"manual_override_allowed,omitempty"` + ClimateSettingScheduleId string `json:"climate_setting_schedule_id" url:"-"` + ScheduleType *string `json:"schedule_type,omitempty" url:"-"` + Name *string `json:"name,omitempty" url:"-"` + ScheduleStartsAt *string `json:"schedule_starts_at,omitempty" url:"-"` + ScheduleEndsAt *string `json:"schedule_ends_at,omitempty" url:"-"` + AutomaticHeatingEnabled *bool `json:"automatic_heating_enabled,omitempty" url:"-"` + AutomaticCoolingEnabled *bool `json:"automatic_cooling_enabled,omitempty" url:"-"` + HvacModeSetting *ClimateSettingSchedulesUpdateRequestHvacModeSetting `json:"hvac_mode_setting,omitempty" url:"-"` + CoolingSetPointCelsius *float64 `json:"cooling_set_point_celsius,omitempty" url:"-"` + HeatingSetPointCelsius *float64 `json:"heating_set_point_celsius,omitempty" url:"-"` + CoolingSetPointFahrenheit *float64 `json:"cooling_set_point_fahrenheit,omitempty" url:"-"` + HeatingSetPointFahrenheit *float64 `json:"heating_set_point_fahrenheit,omitempty" url:"-"` + ManualOverrideAllowed *bool `json:"manual_override_allowed,omitempty" url:"-"` } diff --git a/thermostats/climatesettingschedules/client.go b/thermostats/climatesettingschedules/client.go index 2d763df..14bc2df 100644 --- a/thermostats/climatesettingschedules/client.go +++ b/thermostats/climatesettingschedules/client.go @@ -3,21 +3,18 @@ package climatesettingschedules import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" thermostats "github.com/seamapi/go/thermostats" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.ClimateSettingSchedule, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/climate_setting_schedules/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/climate_setting_schedules/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *thermostats.ClimateSettingSchedulesCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*thermostats.ClimateSettingSchedulesDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/climate_setting_schedules/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/climate_setting_schedules/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *thermostats.ClimateSettingSchedulesDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.ClimateSettingSchedule, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/climate_setting_schedules/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/climate_setting_schedules/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *thermostats.ClimateSettingSchedulesGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.ClimateSettingSchedule, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/climate_setting_schedules/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/climate_setting_schedules/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *thermostats.ClimateSettingSchedulesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -293,56 +242,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*thermostats.ClimateSettingSchedulesUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "thermostats/climate_setting_schedules/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/thermostats/climate_setting_schedules/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *thermostats.ClimateSettingSchedulesUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/types.go b/types.go index 6066cbc..a1665cc 100644 --- a/types.go +++ b/types.go @@ -5,184 +5,105 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" time "time" ) -type AccessCode struct { - // Unique identifier for a group of access codes that share the same code. - CommonCodeKey *string `json:"common_code_key,omitempty" url:"common_code_key,omitempty"` - // Indicates whether the code is set on the device according to a preconfigured schedule. - IsScheduledOnDevice *bool `json:"is_scheduled_on_device,omitempty" url:"is_scheduled_on_device,omitempty"` - // Nature of the access code. Values are "ongoing" for access codes that are active continuously until deactivated manually or "time_bound" for access codes that have a specific duration. - Type AccessCodeType `json:"type,omitempty" url:"type,omitempty"` - // Indicates whether the access code is waiting for a code assignment. - IsWaitingForCodeAssignment *bool `json:"is_waiting_for_code_assignment,omitempty" url:"is_waiting_for_code_assignment,omitempty"` - // Unique identifier for the access code. - AccessCodeId string `json:"access_code_id" url:"access_code_id"` - // Unique identifier for the device associated with the access code. - DeviceId string `json:"device_id" url:"device_id"` - // Name of the access code. Enables administrators and users to identify the access code easily, especially when there are numerous access codes. - Name *string `json:"name,omitempty" url:"name,omitempty"` - // Code used for access. Typically, a numeric or alphanumeric string. - Code *string `json:"code,omitempty" url:"code,omitempty"` - // Date and time at which the access code was created. - CreatedAt time.Time `json:"created_at" url:"created_at"` - Errors interface{} `json:"errors,omitempty" url:"errors,omitempty"` - Warnings interface{} `json:"warnings,omitempty" url:"warnings,omitempty"` - // Indicates whether Seam manages the access code. - IsManaged bool `json:"is_managed" url:"is_managed"` - // Date and time at which the time-bound access code becomes active. - StartsAt *time.Time `json:"starts_at,omitempty" url:"starts_at,omitempty"` - // Date and time after which the time-bound access code becomes inactive. - EndsAt *time.Time `json:"ends_at,omitempty" url:"ends_at,omitempty"` - // Current status of the access code within the operational lifecycle. Values are "setting," a transitional phase that indicates that the code is being configured or activated; "set", which indicates that the code is active and operational; "unset," which indicates a deactivated or unused state, either before activation or after deliberate deactivation; "removing," which indicates a transitional period in which the code is being deleted or made inactive; and "unknown," which indicates an indeterminate state, due to reasons such as system errors or incomplete data, that highlights a potential need for system review or troubleshooting. - Status AccessCodeStatus `json:"status,omitempty" url:"status,omitempty"` - // Indicates whether a backup access code is available for use if the primary access code is lost or compromised. - IsBackupAccessCodeAvailable bool `json:"is_backup_access_code_available" url:"is_backup_access_code_available"` - // Indicates whether the access code is a backup code. - IsBackup *bool `json:"is_backup,omitempty" url:"is_backup,omitempty"` - // Identifier of the pulled backup access code. Used to associate the pulled backup access code with the original access code. - PulledBackupAccessCodeId *string `json:"pulled_backup_access_code_id,omitempty" url:"pulled_backup_access_code_id,omitempty"` - // Indicates whether changes to the access code from external sources are permitted. - IsExternalModificationAllowed bool `json:"is_external_modification_allowed" url:"is_external_modification_allowed"` - // Indicates whether the access code can only be used once. If "true," the code becomes invalid after the first use. - IsOneTimeUse bool `json:"is_one_time_use" url:"is_one_time_use"` - // Indicates whether the access code is intended for use in offline scenarios. If "true," this code can be created on a device without a network connection. - IsOfflineAccessCode bool `json:"is_offline_access_code" url:"is_offline_access_code"` - - _rawJSON json.RawMessage -} - -func (a *AccessCode) UnmarshalJSON(data []byte) error { - type embed AccessCode - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - StartsAt *core.DateTime `json:"starts_at,omitempty"` - EndsAt *core.DateTime `json:"ends_at,omitempty"` - }{ - embed: embed(*a), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err - } - *a = AccessCode(unmarshaler.embed) - a.CreatedAt = unmarshaler.CreatedAt.Time() - a.StartsAt = unmarshaler.StartsAt.TimePtr() - a.EndsAt = unmarshaler.EndsAt.TimePtr() - a._rawJSON = json.RawMessage(data) - return nil +type AcsAccessGroup struct { + AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` + AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + Name string `json:"name" url:"name"` + AccessGroupType AcsAccessGroupAccessGroupType `json:"access_group_type" url:"access_group_type"` + AccessGroupTypeDisplayName string `json:"access_group_type_display_name" url:"access_group_type_display_name"` + DisplayName string `json:"display_name" url:"display_name"` + ExternalType AcsAccessGroupExternalType `json:"external_type" url:"external_type"` + ExternalTypeDisplayName string `json:"external_type_display_name" url:"external_type_display_name"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (a *AccessCode) MarshalJSON() ([]byte, error) { - type embed AccessCode - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - StartsAt *core.DateTime `json:"starts_at,omitempty"` - EndsAt *core.DateTime `json:"ends_at,omitempty"` - }{ - embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), - StartsAt: core.NewOptionalDateTime(a.StartsAt), - EndsAt: core.NewOptionalDateTime(a.EndsAt), +func (a *AcsAccessGroup) GetAcsAccessGroupId() string { + if a == nil { + return "" } - return json.Marshal(marshaler) + return a.AcsAccessGroupId } -func (a *AccessCode) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { - return value - } +func (a *AcsAccessGroup) GetAcsSystemId() string { + if a == nil { + return "" } - if value, err := core.StringifyJSON(a); err == nil { - return value - } - return fmt.Sprintf("%#v", a) + return a.AcsSystemId } -// Current status of the access code within the operational lifecycle. Values are "setting," a transitional phase that indicates that the code is being configured or activated; "set", which indicates that the code is active and operational; "unset," which indicates a deactivated or unused state, either before activation or after deliberate deactivation; "removing," which indicates a transitional period in which the code is being deleted or made inactive; and "unknown," which indicates an indeterminate state, due to reasons such as system errors or incomplete data, that highlights a potential need for system review or troubleshooting. -type AccessCodeStatus string +func (a *AcsAccessGroup) GetWorkspaceId() string { + if a == nil { + return "" + } + return a.WorkspaceId +} -const ( - AccessCodeStatusSetting AccessCodeStatus = "setting" - AccessCodeStatusSet AccessCodeStatus = "set" - AccessCodeStatusUnset AccessCodeStatus = "unset" - AccessCodeStatusRemoving AccessCodeStatus = "removing" - AccessCodeStatusUnknown AccessCodeStatus = "unknown" -) +func (a *AcsAccessGroup) GetName() string { + if a == nil { + return "" + } + return a.Name +} -func NewAccessCodeStatusFromString(s string) (AccessCodeStatus, error) { - switch s { - case "setting": - return AccessCodeStatusSetting, nil - case "set": - return AccessCodeStatusSet, nil - case "unset": - return AccessCodeStatusUnset, nil - case "removing": - return AccessCodeStatusRemoving, nil - case "unknown": - return AccessCodeStatusUnknown, nil +func (a *AcsAccessGroup) GetAccessGroupType() AcsAccessGroupAccessGroupType { + if a == nil { + return "" } - var t AccessCodeStatus - return "", fmt.Errorf("%s is not a valid %T", s, t) + return a.AccessGroupType } -func (a AccessCodeStatus) Ptr() *AccessCodeStatus { - return &a +func (a *AcsAccessGroup) GetAccessGroupTypeDisplayName() string { + if a == nil { + return "" + } + return a.AccessGroupTypeDisplayName } -// Nature of the access code. Values are "ongoing" for access codes that are active continuously until deactivated manually or "time_bound" for access codes that have a specific duration. -type AccessCodeType string +func (a *AcsAccessGroup) GetDisplayName() string { + if a == nil { + return "" + } + return a.DisplayName +} -const ( - AccessCodeTypeTimeBound AccessCodeType = "time_bound" - AccessCodeTypeOngoing AccessCodeType = "ongoing" -) +func (a *AcsAccessGroup) GetExternalType() AcsAccessGroupExternalType { + if a == nil { + return "" + } + return a.ExternalType +} -func NewAccessCodeTypeFromString(s string) (AccessCodeType, error) { - switch s { - case "time_bound": - return AccessCodeTypeTimeBound, nil - case "ongoing": - return AccessCodeTypeOngoing, nil +func (a *AcsAccessGroup) GetExternalTypeDisplayName() string { + if a == nil { + return "" } - var t AccessCodeType - return "", fmt.Errorf("%s is not a valid %T", s, t) + return a.ExternalTypeDisplayName } -func (a AccessCodeType) Ptr() *AccessCodeType { - return &a +func (a *AcsAccessGroup) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt } -type AcsAccessGroup struct { - AcsAccessGroupId string `json:"acs_access_group_id" url:"acs_access_group_id"` - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - Name string `json:"name" url:"name"` - // --- - // deprecated: use external_type - // --- - AccessGroupType AcsAccessGroupAccessGroupType `json:"access_group_type,omitempty" url:"access_group_type,omitempty"` - // --- - // deprecated: use external_type_display_name - // --- - AccessGroupTypeDisplayName string `json:"access_group_type_display_name" url:"access_group_type_display_name"` - ExternalType AcsAccessGroupExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` - ExternalTypeDisplayName string `json:"external_type_display_name" url:"external_type_display_name"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - - _rawJSON json.RawMessage +func (a *AcsAccessGroup) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsAccessGroup) UnmarshalJSON(data []byte) error { type embed AcsAccessGroup var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), } @@ -191,7 +112,12 @@ func (a *AcsAccessGroup) UnmarshalJSON(data []byte) error { } *a = AcsAccessGroup(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -199,29 +125,26 @@ func (a *AcsAccessGroup) MarshalJSON() ([]byte, error) { type embed AcsAccessGroup var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + CreatedAt: internal.NewDateTime(a.CreatedAt), } return json.Marshal(marshaler) } func (a *AcsAccessGroup) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) } -// --- -// deprecated: use external_type -// --- type AcsAccessGroupAccessGroupType string const ( @@ -279,33 +202,181 @@ func (a AcsAccessGroupExternalType) Ptr() *AcsAccessGroupExternalType { } type AcsCredential struct { - AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` - AcsUserId *string `json:"acs_user_id,omitempty" url:"acs_user_id,omitempty"` - AcsCredentialPoolId *string `json:"acs_credential_pool_id,omitempty" url:"acs_credential_pool_id,omitempty"` - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` - ParentAcsCredentialId *string `json:"parent_acs_credential_id,omitempty" url:"parent_acs_credential_id,omitempty"` - DisplayName string `json:"display_name" url:"display_name"` - Code *string `json:"code,omitempty" url:"code,omitempty"` - AccessMethod AcsCredentialAccessMethod `json:"access_method,omitempty" url:"access_method,omitempty"` - ExternalType *AcsCredentialExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` - ExternalTypeDisplayName *string `json:"external_type_display_name,omitempty" url:"external_type_display_name,omitempty"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - StartsAt *string `json:"starts_at,omitempty" url:"starts_at,omitempty"` - EndsAt *string `json:"ends_at,omitempty" url:"ends_at,omitempty"` - Errors []*AcsCredentialErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` - Warnings []*AcsCredentialWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` - IsMultiPhoneSyncCredential *bool `json:"is_multi_phone_sync_credential,omitempty" url:"is_multi_phone_sync_credential,omitempty"` - VisionlineMetadata *AcsCredentialVisionlineMetadata `json:"visionline_metadata,omitempty" url:"visionline_metadata,omitempty"` - - _rawJSON json.RawMessage + AcsCredentialId string `json:"acs_credential_id" url:"acs_credential_id"` + AcsUserId *string `json:"acs_user_id,omitempty" url:"acs_user_id,omitempty"` + AcsCredentialPoolId *string `json:"acs_credential_pool_id,omitempty" url:"acs_credential_pool_id,omitempty"` + AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + ParentAcsCredentialId *string `json:"parent_acs_credential_id,omitempty" url:"parent_acs_credential_id,omitempty"` + DisplayName string `json:"display_name" url:"display_name"` + Code *string `json:"code,omitempty" url:"code,omitempty"` + AccessMethod AcsCredentialAccessMethod `json:"access_method" url:"access_method"` + ExternalType *AcsCredentialExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` + ExternalTypeDisplayName *string `json:"external_type_display_name,omitempty" url:"external_type_display_name,omitempty"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + StartsAt *string `json:"starts_at,omitempty" url:"starts_at,omitempty"` + EndsAt *string `json:"ends_at,omitempty" url:"ends_at,omitempty"` + Errors []*AcsCredentialErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` + Warnings []*AcsCredentialWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` + IsMultiPhoneSyncCredential *bool `json:"is_multi_phone_sync_credential,omitempty" url:"is_multi_phone_sync_credential,omitempty"` + IsLatestDesiredStateSyncedWithProvider *bool `json:"is_latest_desired_state_synced_with_provider,omitempty" url:"is_latest_desired_state_synced_with_provider,omitempty"` + LatestDesiredStateSyncedWithProviderAt *time.Time `json:"latest_desired_state_synced_with_provider_at,omitempty" url:"latest_desired_state_synced_with_provider_at,omitempty"` + VisionlineMetadata *AcsCredentialVisionlineMetadata `json:"visionline_metadata,omitempty" url:"visionline_metadata,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsCredential) GetAcsCredentialId() string { + if a == nil { + return "" + } + return a.AcsCredentialId +} + +func (a *AcsCredential) GetAcsUserId() *string { + if a == nil { + return nil + } + return a.AcsUserId +} + +func (a *AcsCredential) GetAcsCredentialPoolId() *string { + if a == nil { + return nil + } + return a.AcsCredentialPoolId +} + +func (a *AcsCredential) GetAcsSystemId() string { + if a == nil { + return "" + } + return a.AcsSystemId +} + +func (a *AcsCredential) GetParentAcsCredentialId() *string { + if a == nil { + return nil + } + return a.ParentAcsCredentialId +} + +func (a *AcsCredential) GetDisplayName() string { + if a == nil { + return "" + } + return a.DisplayName +} + +func (a *AcsCredential) GetCode() *string { + if a == nil { + return nil + } + return a.Code +} + +func (a *AcsCredential) GetAccessMethod() AcsCredentialAccessMethod { + if a == nil { + return "" + } + return a.AccessMethod +} + +func (a *AcsCredential) GetExternalType() *AcsCredentialExternalType { + if a == nil { + return nil + } + return a.ExternalType +} + +func (a *AcsCredential) GetExternalTypeDisplayName() *string { + if a == nil { + return nil + } + return a.ExternalTypeDisplayName +} + +func (a *AcsCredential) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsCredential) GetWorkspaceId() string { + if a == nil { + return "" + } + return a.WorkspaceId +} + +func (a *AcsCredential) GetStartsAt() *string { + if a == nil { + return nil + } + return a.StartsAt +} + +func (a *AcsCredential) GetEndsAt() *string { + if a == nil { + return nil + } + return a.EndsAt +} + +func (a *AcsCredential) GetErrors() []*AcsCredentialErrorsItem { + if a == nil { + return nil + } + return a.Errors +} + +func (a *AcsCredential) GetWarnings() []*AcsCredentialWarningsItem { + if a == nil { + return nil + } + return a.Warnings +} + +func (a *AcsCredential) GetIsMultiPhoneSyncCredential() *bool { + if a == nil { + return nil + } + return a.IsMultiPhoneSyncCredential +} + +func (a *AcsCredential) GetIsLatestDesiredStateSyncedWithProvider() *bool { + if a == nil { + return nil + } + return a.IsLatestDesiredStateSyncedWithProvider +} + +func (a *AcsCredential) GetLatestDesiredStateSyncedWithProviderAt() *time.Time { + if a == nil { + return nil + } + return a.LatestDesiredStateSyncedWithProviderAt +} + +func (a *AcsCredential) GetVisionlineMetadata() *AcsCredentialVisionlineMetadata { + if a == nil { + return nil + } + return a.VisionlineMetadata +} + +func (a *AcsCredential) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsCredential) UnmarshalJSON(data []byte) error { type embed AcsCredential var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` + LatestDesiredStateSyncedWithProviderAt *internal.DateTime `json:"latest_desired_state_synced_with_provider_at,omitempty"` }{ embed: embed(*a), } @@ -314,7 +385,13 @@ func (a *AcsCredential) UnmarshalJSON(data []byte) error { } *a = AcsCredential(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a._rawJSON = json.RawMessage(data) + a.LatestDesiredStateSyncedWithProviderAt = unmarshaler.LatestDesiredStateSyncedWithProviderAt.TimePtr() + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -322,21 +399,23 @@ func (a *AcsCredential) MarshalJSON() ([]byte, error) { type embed AcsCredential var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` + LatestDesiredStateSyncedWithProviderAt *internal.DateTime `json:"latest_desired_state_synced_with_provider_at,omitempty"` }{ - embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + embed: embed(*a), + CreatedAt: internal.NewDateTime(a.CreatedAt), + LatestDesiredStateSyncedWithProviderAt: internal.NewOptionalDateTime(a.LatestDesiredStateSyncedWithProviderAt), } return json.Marshal(marshaler) } func (a *AcsCredential) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -371,7 +450,26 @@ type AcsCredentialErrorsItem struct { ErrorCode string `json:"error_code" url:"error_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsCredentialErrorsItem) GetErrorCode() string { + if a == nil { + return "" + } + return a.ErrorCode +} + +func (a *AcsCredentialErrorsItem) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *AcsCredentialErrorsItem) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsCredentialErrorsItem) UnmarshalJSON(data []byte) error { @@ -381,17 +479,22 @@ func (a *AcsCredentialErrorsItem) UnmarshalJSON(data []byte) error { return err } *a = AcsCredentialErrorsItem(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsCredentialErrorsItem) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -434,18 +537,66 @@ type AcsCredentialPool struct { WorkspaceId string `json:"workspace_id" url:"workspace_id"` externalType string - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsCredentialPool) GetAcsCredentialPoolId() string { + if a == nil { + return "" + } + return a.AcsCredentialPoolId +} + +func (a *AcsCredentialPool) GetAcsSystemId() string { + if a == nil { + return "" + } + return a.AcsSystemId +} + +func (a *AcsCredentialPool) GetDisplayName() string { + if a == nil { + return "" + } + return a.DisplayName +} + +func (a *AcsCredentialPool) GetExternalTypeDisplayName() string { + if a == nil { + return "" + } + return a.ExternalTypeDisplayName +} + +func (a *AcsCredentialPool) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsCredentialPool) GetWorkspaceId() string { + if a == nil { + return "" + } + return a.WorkspaceId } func (a *AcsCredentialPool) ExternalType() string { return a.externalType } +func (a *AcsCredentialPool) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + func (a *AcsCredentialPool) UnmarshalJSON(data []byte) error { type embed AcsCredentialPool var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` + ExternalType string `json:"external_type"` }{ embed: embed(*a), } @@ -454,8 +605,16 @@ func (a *AcsCredentialPool) UnmarshalJSON(data []byte) error { } *a = AcsCredentialPool(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a.externalType = "hid_part_number" - a._rawJSON = json.RawMessage(data) + if unmarshaler.ExternalType != "hid_part_number" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "hid_part_number", unmarshaler.ExternalType) + } + a.externalType = unmarshaler.ExternalType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "external_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -463,23 +622,23 @@ func (a *AcsCredentialPool) MarshalJSON() ([]byte, error) { type embed AcsCredentialPool var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` - ExternalType string `json:"external_type"` + CreatedAt *internal.DateTime `json:"created_at"` + ExternalType string `json:"external_type"` }{ embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + CreatedAt: internal.NewDateTime(a.CreatedAt), ExternalType: "hid_part_number", } return json.Marshal(marshaler) } func (a *AcsCredentialPool) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -492,14 +651,54 @@ type AcsCredentialProvisioningAutomation struct { CreatedAt time.Time `json:"created_at" url:"created_at"` WorkspaceId string `json:"workspace_id" url:"workspace_id"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsCredentialProvisioningAutomation) GetAcsCredentialProvisioningAutomationId() string { + if a == nil { + return "" + } + return a.AcsCredentialProvisioningAutomationId +} + +func (a *AcsCredentialProvisioningAutomation) GetCredentialManagerAcsSystemId() string { + if a == nil { + return "" + } + return a.CredentialManagerAcsSystemId +} + +func (a *AcsCredentialProvisioningAutomation) GetUserIdentityId() string { + if a == nil { + return "" + } + return a.UserIdentityId +} + +func (a *AcsCredentialProvisioningAutomation) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsCredentialProvisioningAutomation) GetWorkspaceId() string { + if a == nil { + return "" + } + return a.WorkspaceId +} + +func (a *AcsCredentialProvisioningAutomation) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsCredentialProvisioningAutomation) UnmarshalJSON(data []byte) error { type embed AcsCredentialProvisioningAutomation var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), } @@ -508,7 +707,12 @@ func (a *AcsCredentialProvisioningAutomation) UnmarshalJSON(data []byte) error { } *a = AcsCredentialProvisioningAutomation(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -516,33 +720,66 @@ func (a *AcsCredentialProvisioningAutomation) MarshalJSON() ([]byte, error) { type embed AcsCredentialProvisioningAutomation var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + CreatedAt: internal.NewDateTime(a.CreatedAt), } return json.Marshal(marshaler) } func (a *AcsCredentialProvisioningAutomation) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) } type AcsCredentialVisionlineMetadata struct { - CardFunctionType AcsCredentialVisionlineMetadataCardFunctionType `json:"card_function_type,omitempty" url:"card_function_type,omitempty"` + CardFunctionType AcsCredentialVisionlineMetadataCardFunctionType `json:"card_function_type" url:"card_function_type"` JoinerAcsCredentialIds []string `json:"joiner_acs_credential_ids,omitempty" url:"joiner_acs_credential_ids,omitempty"` GuestAcsEntranceIds []string `json:"guest_acs_entrance_ids,omitempty" url:"guest_acs_entrance_ids,omitempty"` CommonAcsEntranceIds []string `json:"common_acs_entrance_ids,omitempty" url:"common_acs_entrance_ids,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsCredentialVisionlineMetadata) GetCardFunctionType() AcsCredentialVisionlineMetadataCardFunctionType { + if a == nil { + return "" + } + return a.CardFunctionType +} + +func (a *AcsCredentialVisionlineMetadata) GetJoinerAcsCredentialIds() []string { + if a == nil { + return nil + } + return a.JoinerAcsCredentialIds +} + +func (a *AcsCredentialVisionlineMetadata) GetGuestAcsEntranceIds() []string { + if a == nil { + return nil + } + return a.GuestAcsEntranceIds +} + +func (a *AcsCredentialVisionlineMetadata) GetCommonAcsEntranceIds() []string { + if a == nil { + return nil + } + return a.CommonAcsEntranceIds +} + +func (a *AcsCredentialVisionlineMetadata) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsCredentialVisionlineMetadata) UnmarshalJSON(data []byte) error { @@ -552,17 +789,22 @@ func (a *AcsCredentialVisionlineMetadata) UnmarshalJSON(data []byte) error { return err } *a = AcsCredentialVisionlineMetadata(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsCredentialVisionlineMetadata) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -594,7 +836,26 @@ type AcsCredentialWarningsItem struct { WarningCode string `json:"warning_code" url:"warning_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsCredentialWarningsItem) GetWarningCode() string { + if a == nil { + return "" + } + return a.WarningCode +} + +func (a *AcsCredentialWarningsItem) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *AcsCredentialWarningsItem) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsCredentialWarningsItem) UnmarshalJSON(data []byte) error { @@ -604,39 +865,98 @@ func (a *AcsCredentialWarningsItem) UnmarshalJSON(data []byte) error { return err } *a = AcsCredentialWarningsItem(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsCredentialWarningsItem) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) } type AcsEntrance struct { - AcsEntranceId string `json:"acs_entrance_id" url:"acs_entrance_id"` - DisplayName string `json:"display_name" url:"display_name"` AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + AcsEntranceId string `json:"acs_entrance_id" url:"acs_entrance_id"` CreatedAt time.Time `json:"created_at" url:"created_at"` - LatchMetadata *AcsEntranceLatchMetadata `json:"latch_metadata,omitempty" url:"latch_metadata,omitempty"` + DisplayName string `json:"display_name" url:"display_name"` Errors []*AcsEntranceErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` + LatchMetadata *AcsEntranceLatchMetadata `json:"latch_metadata,omitempty" url:"latch_metadata,omitempty"` VisionlineMetadata *AcsEntranceVisionlineMetadata `json:"visionline_metadata,omitempty" url:"visionline_metadata,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsEntrance) GetAcsSystemId() string { + if a == nil { + return "" + } + return a.AcsSystemId +} + +func (a *AcsEntrance) GetAcsEntranceId() string { + if a == nil { + return "" + } + return a.AcsEntranceId +} + +func (a *AcsEntrance) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsEntrance) GetDisplayName() string { + if a == nil { + return "" + } + return a.DisplayName +} + +func (a *AcsEntrance) GetErrors() []*AcsEntranceErrorsItem { + if a == nil { + return nil + } + return a.Errors +} + +func (a *AcsEntrance) GetLatchMetadata() *AcsEntranceLatchMetadata { + if a == nil { + return nil + } + return a.LatchMetadata +} + +func (a *AcsEntrance) GetVisionlineMetadata() *AcsEntranceVisionlineMetadata { + if a == nil { + return nil + } + return a.VisionlineMetadata +} + +func (a *AcsEntrance) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsEntrance) UnmarshalJSON(data []byte) error { type embed AcsEntrance var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), } @@ -645,7 +965,12 @@ func (a *AcsEntrance) UnmarshalJSON(data []byte) error { } *a = AcsEntrance(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -653,21 +978,21 @@ func (a *AcsEntrance) MarshalJSON() ([]byte, error) { type embed AcsEntrance var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + CreatedAt: internal.NewDateTime(a.CreatedAt), } return json.Marshal(marshaler) } func (a *AcsEntrance) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -677,27 +1002,51 @@ type AcsEntranceErrorsItem struct { ErrorCode string `json:"error_code" url:"error_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (a *AcsEntranceErrorsItem) UnmarshalJSON(data []byte) error { +func (a *AcsEntranceErrorsItem) GetErrorCode() string { + if a == nil { + return "" + } + return a.ErrorCode +} + +func (a *AcsEntranceErrorsItem) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *AcsEntranceErrorsItem) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *AcsEntranceErrorsItem) UnmarshalJSON(data []byte) error { type unmarshaler AcsEntranceErrorsItem var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } *a = AcsEntranceErrorsItem(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsEntranceErrorsItem) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -709,7 +1058,40 @@ type AcsEntranceLatchMetadata struct { DoorType string `json:"door_type" url:"door_type"` IsConnected bool `json:"is_connected" url:"is_connected"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsEntranceLatchMetadata) GetAccessibilityType() string { + if a == nil { + return "" + } + return a.AccessibilityType +} + +func (a *AcsEntranceLatchMetadata) GetDoorName() string { + if a == nil { + return "" + } + return a.DoorName +} + +func (a *AcsEntranceLatchMetadata) GetDoorType() string { + if a == nil { + return "" + } + return a.DoorType +} + +func (a *AcsEntranceLatchMetadata) GetIsConnected() bool { + if a == nil { + return false + } + return a.IsConnected +} + +func (a *AcsEntranceLatchMetadata) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsEntranceLatchMetadata) UnmarshalJSON(data []byte) error { @@ -719,17 +1101,22 @@ func (a *AcsEntranceLatchMetadata) UnmarshalJSON(data []byte) error { return err } *a = AcsEntranceLatchMetadata(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsEntranceLatchMetadata) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -737,10 +1124,36 @@ func (a *AcsEntranceLatchMetadata) String() string { type AcsEntranceVisionlineMetadata struct { DoorName string `json:"door_name" url:"door_name"` - DoorCategory AcsEntranceVisionlineMetadataDoorCategory `json:"door_category,omitempty" url:"door_category,omitempty"` + DoorCategory AcsEntranceVisionlineMetadataDoorCategory `json:"door_category" url:"door_category"` Profiles []*AcsEntranceVisionlineMetadataProfilesItem `json:"profiles,omitempty" url:"profiles,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsEntranceVisionlineMetadata) GetDoorName() string { + if a == nil { + return "" + } + return a.DoorName +} + +func (a *AcsEntranceVisionlineMetadata) GetDoorCategory() AcsEntranceVisionlineMetadataDoorCategory { + if a == nil { + return "" + } + return a.DoorCategory +} + +func (a *AcsEntranceVisionlineMetadata) GetProfiles() []*AcsEntranceVisionlineMetadataProfilesItem { + if a == nil { + return nil + } + return a.Profiles +} + +func (a *AcsEntranceVisionlineMetadata) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsEntranceVisionlineMetadata) UnmarshalJSON(data []byte) error { @@ -750,17 +1163,22 @@ func (a *AcsEntranceVisionlineMetadata) UnmarshalJSON(data []byte) error { return err } *a = AcsEntranceVisionlineMetadata(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsEntranceVisionlineMetadata) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -799,9 +1217,28 @@ func (a AcsEntranceVisionlineMetadataDoorCategory) Ptr() *AcsEntranceVisionlineM type AcsEntranceVisionlineMetadataProfilesItem struct { VisionlineDoorProfileId string `json:"visionline_door_profile_id" url:"visionline_door_profile_id"` - VisionlineDoorProfileType AcsEntranceVisionlineMetadataProfilesItemVisionlineDoorProfileType `json:"visionline_door_profile_type,omitempty" url:"visionline_door_profile_type,omitempty"` + VisionlineDoorProfileType AcsEntranceVisionlineMetadataProfilesItemVisionlineDoorProfileType `json:"visionline_door_profile_type" url:"visionline_door_profile_type"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsEntranceVisionlineMetadataProfilesItem) GetVisionlineDoorProfileId() string { + if a == nil { + return "" + } + return a.VisionlineDoorProfileId +} + +func (a *AcsEntranceVisionlineMetadataProfilesItem) GetVisionlineDoorProfileType() AcsEntranceVisionlineMetadataProfilesItemVisionlineDoorProfileType { + if a == nil { + return "" + } + return a.VisionlineDoorProfileType +} - _rawJSON json.RawMessage +func (a *AcsEntranceVisionlineMetadataProfilesItem) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsEntranceVisionlineMetadataProfilesItem) UnmarshalJSON(data []byte) error { @@ -811,17 +1248,22 @@ func (a *AcsEntranceVisionlineMetadataProfilesItem) UnmarshalJSON(data []byte) e return err } *a = AcsEntranceVisionlineMetadataProfilesItem(value) - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } func (a *AcsEntranceVisionlineMetadataProfilesItem) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -853,36 +1295,156 @@ func (a AcsEntranceVisionlineMetadataProfilesItemVisionlineDoorProfileType) Ptr( } type AcsSystem struct { - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` - ExternalType *AcsSystemExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` - ExternalTypeDisplayName *string `json:"external_type_display_name,omitempty" url:"external_type_display_name,omitempty"` - // --- - // deprecated: use external_type - // --- - SystemType *AcsSystemSystemType `json:"system_type,omitempty" url:"system_type,omitempty"` - // --- - // deprecated: use external_type_display_name - // --- - SystemTypeDisplayName *string `json:"system_type_display_name,omitempty" url:"system_type_display_name,omitempty"` - Name string `json:"name" url:"name"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ImageUrl string `json:"image_url" url:"image_url"` - ImageAltText string `json:"image_alt_text" url:"image_alt_text"` - CanAutomateEnrollment *bool `json:"can_automate_enrollment,omitempty" url:"can_automate_enrollment,omitempty"` - CanCreateAcsAccessGroups *bool `json:"can_create_acs_access_groups,omitempty" url:"can_create_acs_access_groups,omitempty"` - CanRemoveAcsUsersFromAcsAccessGroups *bool `json:"can_remove_acs_users_from_acs_access_groups,omitempty" url:"can_remove_acs_users_from_acs_access_groups,omitempty"` - CanAddAcsUsersToAcsAccessGroups *bool `json:"can_add_acs_users_to_acs_access_groups,omitempty" url:"can_add_acs_users_to_acs_access_groups,omitempty"` - - _rawJSON json.RawMessage + AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + ExternalType *AcsSystemExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` + ExternalTypeDisplayName *string `json:"external_type_display_name,omitempty" url:"external_type_display_name,omitempty"` + SystemType *AcsSystemSystemType `json:"system_type,omitempty" url:"system_type,omitempty"` + SystemTypeDisplayName *string `json:"system_type_display_name,omitempty" url:"system_type_display_name,omitempty"` + Name string `json:"name" url:"name"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` + ImageUrl string `json:"image_url" url:"image_url"` + ImageAltText string `json:"image_alt_text" url:"image_alt_text"` + Errors []*AcsSystemErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` + Warnings []*AcsSystemWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` + CanAutomateEnrollment *bool `json:"can_automate_enrollment,omitempty" url:"can_automate_enrollment,omitempty"` + CanCreateAcsAccessGroups *bool `json:"can_create_acs_access_groups,omitempty" url:"can_create_acs_access_groups,omitempty"` + CanRemoveAcsUsersFromAcsAccessGroups *bool `json:"can_remove_acs_users_from_acs_access_groups,omitempty" url:"can_remove_acs_users_from_acs_access_groups,omitempty"` + CanAddAcsUsersToAcsAccessGroups *bool `json:"can_add_acs_users_to_acs_access_groups,omitempty" url:"can_add_acs_users_to_acs_access_groups,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsSystem) GetAcsSystemId() string { + if a == nil { + return "" + } + return a.AcsSystemId +} + +func (a *AcsSystem) GetExternalType() *AcsSystemExternalType { + if a == nil { + return nil + } + return a.ExternalType +} + +func (a *AcsSystem) GetExternalTypeDisplayName() *string { + if a == nil { + return nil + } + return a.ExternalTypeDisplayName +} + +func (a *AcsSystem) GetSystemType() *AcsSystemSystemType { + if a == nil { + return nil + } + return a.SystemType +} + +func (a *AcsSystem) GetSystemTypeDisplayName() *string { + if a == nil { + return nil + } + return a.SystemTypeDisplayName +} + +func (a *AcsSystem) GetName() string { + if a == nil { + return "" + } + return a.Name +} + +func (a *AcsSystem) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsSystem) GetWorkspaceId() string { + if a == nil { + return "" + } + return a.WorkspaceId +} + +func (a *AcsSystem) GetConnectedAccountIds() []string { + if a == nil { + return nil + } + return a.ConnectedAccountIds +} + +func (a *AcsSystem) GetImageUrl() string { + if a == nil { + return "" + } + return a.ImageUrl +} + +func (a *AcsSystem) GetImageAltText() string { + if a == nil { + return "" + } + return a.ImageAltText +} + +func (a *AcsSystem) GetErrors() []*AcsSystemErrorsItem { + if a == nil { + return nil + } + return a.Errors +} + +func (a *AcsSystem) GetWarnings() []*AcsSystemWarningsItem { + if a == nil { + return nil + } + return a.Warnings +} + +func (a *AcsSystem) GetCanAutomateEnrollment() *bool { + if a == nil { + return nil + } + return a.CanAutomateEnrollment +} + +func (a *AcsSystem) GetCanCreateAcsAccessGroups() *bool { + if a == nil { + return nil + } + return a.CanCreateAcsAccessGroups +} + +func (a *AcsSystem) GetCanRemoveAcsUsersFromAcsAccessGroups() *bool { + if a == nil { + return nil + } + return a.CanRemoveAcsUsersFromAcsAccessGroups +} + +func (a *AcsSystem) GetCanAddAcsUsersToAcsAccessGroups() *bool { + if a == nil { + return nil + } + return a.CanAddAcsUsersToAcsAccessGroups +} + +func (a *AcsSystem) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsSystem) UnmarshalJSON(data []byte) error { type embed AcsSystem var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), } @@ -891,7 +1453,12 @@ func (a *AcsSystem) UnmarshalJSON(data []byte) error { } *a = AcsSystem(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -899,21 +1466,255 @@ func (a *AcsSystem) MarshalJSON() ([]byte, error) { type embed AcsSystem var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + CreatedAt: internal.NewDateTime(a.CreatedAt), } return json.Marshal(marshaler) } func (a *AcsSystem) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AcsSystemErrorsItem struct { + ErrorCode string + SeamBridgeDisconnected *AcsSystemErrorsItemSeamBridgeDisconnected + VisionlineInstanceUnreachable *AcsSystemErrorsItemVisionlineInstanceUnreachable +} + +func NewAcsSystemErrorsItemFromSeamBridgeDisconnected(value *AcsSystemErrorsItemSeamBridgeDisconnected) *AcsSystemErrorsItem { + return &AcsSystemErrorsItem{ErrorCode: "seam_bridge_disconnected", SeamBridgeDisconnected: value} +} + +func NewAcsSystemErrorsItemFromVisionlineInstanceUnreachable(value *AcsSystemErrorsItemVisionlineInstanceUnreachable) *AcsSystemErrorsItem { + return &AcsSystemErrorsItem{ErrorCode: "visionline_instance_unreachable", VisionlineInstanceUnreachable: value} +} + +func (a *AcsSystemErrorsItem) GetErrorCode() string { + if a == nil { + return "" + } + return a.ErrorCode +} + +func (a *AcsSystemErrorsItem) GetSeamBridgeDisconnected() *AcsSystemErrorsItemSeamBridgeDisconnected { + if a == nil { + return nil + } + return a.SeamBridgeDisconnected +} + +func (a *AcsSystemErrorsItem) GetVisionlineInstanceUnreachable() *AcsSystemErrorsItemVisionlineInstanceUnreachable { + if a == nil { + return nil + } + return a.VisionlineInstanceUnreachable +} + +func (a *AcsSystemErrorsItem) UnmarshalJSON(data []byte) error { + var unmarshaler struct { + ErrorCode string `json:"error_code"` + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + a.ErrorCode = unmarshaler.ErrorCode + if unmarshaler.ErrorCode == "" { + return fmt.Errorf("%T did not include discriminant error_code", a) + } + switch unmarshaler.ErrorCode { + case "seam_bridge_disconnected": + value := new(AcsSystemErrorsItemSeamBridgeDisconnected) + if err := json.Unmarshal(data, &value); err != nil { + return err + } + a.SeamBridgeDisconnected = value + case "visionline_instance_unreachable": + value := new(AcsSystemErrorsItemVisionlineInstanceUnreachable) + if err := json.Unmarshal(data, &value); err != nil { + return err + } + a.VisionlineInstanceUnreachable = value + } + return nil +} + +func (a AcsSystemErrorsItem) MarshalJSON() ([]byte, error) { + switch a.ErrorCode { + default: + return nil, fmt.Errorf("invalid type %s in %T", a.ErrorCode, a) + case "seam_bridge_disconnected": + return internal.MarshalJSONWithExtraProperty(a.SeamBridgeDisconnected, "error_code", "seam_bridge_disconnected") + case "visionline_instance_unreachable": + return internal.MarshalJSONWithExtraProperty(a.VisionlineInstanceUnreachable, "error_code", "visionline_instance_unreachable") + } +} + +type AcsSystemErrorsItemVisitor interface { + VisitSeamBridgeDisconnected(*AcsSystemErrorsItemSeamBridgeDisconnected) error + VisitVisionlineInstanceUnreachable(*AcsSystemErrorsItemVisionlineInstanceUnreachable) error +} + +func (a *AcsSystemErrorsItem) Accept(visitor AcsSystemErrorsItemVisitor) error { + switch a.ErrorCode { + default: + return fmt.Errorf("invalid type %s in %T", a.ErrorCode, a) + case "seam_bridge_disconnected": + return visitor.VisitSeamBridgeDisconnected(a.SeamBridgeDisconnected) + case "visionline_instance_unreachable": + return visitor.VisitVisionlineInstanceUnreachable(a.VisionlineInstanceUnreachable) + } +} + +type AcsSystemErrorsItemSeamBridgeDisconnected struct { + CreatedAt time.Time `json:"created_at" url:"created_at"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsSystemErrorsItemSeamBridgeDisconnected) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsSystemErrorsItemSeamBridgeDisconnected) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *AcsSystemErrorsItemSeamBridgeDisconnected) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *AcsSystemErrorsItemSeamBridgeDisconnected) UnmarshalJSON(data []byte) error { + type embed AcsSystemErrorsItemSeamBridgeDisconnected + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AcsSystemErrorsItemSeamBridgeDisconnected(unmarshaler.embed) + a.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *AcsSystemErrorsItemSeamBridgeDisconnected) MarshalJSON() ([]byte, error) { + type embed AcsSystemErrorsItemSeamBridgeDisconnected + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*a), + CreatedAt: internal.NewDateTime(a.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (a *AcsSystemErrorsItemSeamBridgeDisconnected) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AcsSystemErrorsItemVisionlineInstanceUnreachable struct { + CreatedAt time.Time `json:"created_at" url:"created_at"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsSystemErrorsItemVisionlineInstanceUnreachable) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsSystemErrorsItemVisionlineInstanceUnreachable) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *AcsSystemErrorsItemVisionlineInstanceUnreachable) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *AcsSystemErrorsItemVisionlineInstanceUnreachable) UnmarshalJSON(data []byte) error { + type embed AcsSystemErrorsItemVisionlineInstanceUnreachable + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = AcsSystemErrorsItemVisionlineInstanceUnreachable(unmarshaler.embed) + a.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *AcsSystemErrorsItemVisionlineInstanceUnreachable) MarshalJSON() ([]byte, error) { + type embed AcsSystemErrorsItemVisionlineInstanceUnreachable + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*a), + CreatedAt: internal.NewDateTime(a.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (a *AcsSystemErrorsItemVisionlineInstanceUnreachable) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -959,9 +1760,6 @@ func (a AcsSystemExternalType) Ptr() *AcsSystemExternalType { return &a } -// --- -// deprecated: use external_type -// --- type AcsSystemSystemType string const ( @@ -1002,37 +1800,202 @@ func (a AcsSystemSystemType) Ptr() *AcsSystemSystemType { return &a } -type AcsUser struct { - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` - AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` - HidAcsSystemId *string `json:"hid_acs_system_id,omitempty" url:"hid_acs_system_id,omitempty"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - DisplayName string `json:"display_name" url:"display_name"` - ExternalType *AcsUserExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` - ExternalTypeDisplayName *string `json:"external_type_display_name,omitempty" url:"external_type_display_name,omitempty"` - IsSuspended bool `json:"is_suspended" url:"is_suspended"` - AccessSchedule *AcsUserAccessSchedule `json:"access_schedule,omitempty" url:"access_schedule,omitempty"` - UserIdentityId *string `json:"user_identity_id,omitempty" url:"user_identity_id,omitempty"` - UserIdentityFullName *string `json:"user_identity_full_name,omitempty" url:"user_identity_full_name,omitempty"` - UserIdentityEmailAddress *string `json:"user_identity_email_address,omitempty" url:"user_identity_email_address,omitempty"` - UserIdentityPhoneNumber *string `json:"user_identity_phone_number,omitempty" url:"user_identity_phone_number,omitempty"` - FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` - // --- - // deprecated: use email_address. - // --- - Email *string `json:"email,omitempty" url:"email,omitempty"` - EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` - PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` +type AcsSystemWarningsItem struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} - _rawJSON json.RawMessage +func (a *AcsSystemWarningsItem) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *AcsSystemWarningsItem) UnmarshalJSON(data []byte) error { + type unmarshaler AcsSystemWarningsItem + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = AcsSystemWarningsItem(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *AcsSystemWarningsItem) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type AcsUser struct { + AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + AcsSystemId string `json:"acs_system_id" url:"acs_system_id"` + HidAcsSystemId *string `json:"hid_acs_system_id,omitempty" url:"hid_acs_system_id,omitempty"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + DisplayName string `json:"display_name" url:"display_name"` + ExternalType *AcsUserExternalType `json:"external_type,omitempty" url:"external_type,omitempty"` + ExternalTypeDisplayName *string `json:"external_type_display_name,omitempty" url:"external_type_display_name,omitempty"` + IsSuspended bool `json:"is_suspended" url:"is_suspended"` + AccessSchedule *AcsUserAccessSchedule `json:"access_schedule,omitempty" url:"access_schedule,omitempty"` + UserIdentityId *string `json:"user_identity_id,omitempty" url:"user_identity_id,omitempty"` + UserIdentityFullName *string `json:"user_identity_full_name,omitempty" url:"user_identity_full_name,omitempty"` + UserIdentityEmailAddress *string `json:"user_identity_email_address,omitempty" url:"user_identity_email_address,omitempty"` + UserIdentityPhoneNumber *string `json:"user_identity_phone_number,omitempty" url:"user_identity_phone_number,omitempty"` + FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` + Email *string `json:"email,omitempty" url:"email,omitempty"` + EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` + PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsUser) GetAcsUserId() string { + if a == nil { + return "" + } + return a.AcsUserId +} + +func (a *AcsUser) GetAcsSystemId() string { + if a == nil { + return "" + } + return a.AcsSystemId +} + +func (a *AcsUser) GetHidAcsSystemId() *string { + if a == nil { + return nil + } + return a.HidAcsSystemId +} + +func (a *AcsUser) GetWorkspaceId() string { + if a == nil { + return "" + } + return a.WorkspaceId +} + +func (a *AcsUser) GetCreatedAt() time.Time { + if a == nil { + return time.Time{} + } + return a.CreatedAt +} + +func (a *AcsUser) GetDisplayName() string { + if a == nil { + return "" + } + return a.DisplayName +} + +func (a *AcsUser) GetExternalType() *AcsUserExternalType { + if a == nil { + return nil + } + return a.ExternalType +} + +func (a *AcsUser) GetExternalTypeDisplayName() *string { + if a == nil { + return nil + } + return a.ExternalTypeDisplayName +} + +func (a *AcsUser) GetIsSuspended() bool { + if a == nil { + return false + } + return a.IsSuspended +} + +func (a *AcsUser) GetAccessSchedule() *AcsUserAccessSchedule { + if a == nil { + return nil + } + return a.AccessSchedule +} + +func (a *AcsUser) GetUserIdentityId() *string { + if a == nil { + return nil + } + return a.UserIdentityId +} + +func (a *AcsUser) GetUserIdentityFullName() *string { + if a == nil { + return nil + } + return a.UserIdentityFullName +} + +func (a *AcsUser) GetUserIdentityEmailAddress() *string { + if a == nil { + return nil + } + return a.UserIdentityEmailAddress +} + +func (a *AcsUser) GetUserIdentityPhoneNumber() *string { + if a == nil { + return nil + } + return a.UserIdentityPhoneNumber +} + +func (a *AcsUser) GetFullName() *string { + if a == nil { + return nil + } + return a.FullName +} + +func (a *AcsUser) GetEmail() *string { + if a == nil { + return nil + } + return a.Email +} + +func (a *AcsUser) GetEmailAddress() *string { + if a == nil { + return nil + } + return a.EmailAddress +} + +func (a *AcsUser) GetPhoneNumber() *string { + if a == nil { + return nil + } + return a.PhoneNumber +} + +func (a *AcsUser) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsUser) UnmarshalJSON(data []byte) error { type embed AcsUser var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), } @@ -1041,7 +2004,12 @@ func (a *AcsUser) UnmarshalJSON(data []byte) error { } *a = AcsUser(unmarshaler.embed) a.CreatedAt = unmarshaler.CreatedAt.Time() - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -1049,21 +2017,21 @@ func (a *AcsUser) MarshalJSON() ([]byte, error) { type embed AcsUser var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*a), - CreatedAt: core.NewDateTime(a.CreatedAt), + CreatedAt: internal.NewDateTime(a.CreatedAt), } return json.Marshal(marshaler) } func (a *AcsUser) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -1073,15 +2041,34 @@ type AcsUserAccessSchedule struct { StartsAt time.Time `json:"starts_at" url:"starts_at"` EndsAt time.Time `json:"ends_at" url:"ends_at"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *AcsUserAccessSchedule) GetStartsAt() time.Time { + if a == nil { + return time.Time{} + } + return a.StartsAt +} + +func (a *AcsUserAccessSchedule) GetEndsAt() time.Time { + if a == nil { + return time.Time{} + } + return a.EndsAt +} + +func (a *AcsUserAccessSchedule) GetExtraProperties() map[string]interface{} { + return a.extraProperties } func (a *AcsUserAccessSchedule) UnmarshalJSON(data []byte) error { type embed AcsUserAccessSchedule var unmarshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at"` - EndsAt *core.DateTime `json:"ends_at"` + StartsAt *internal.DateTime `json:"starts_at"` + EndsAt *internal.DateTime `json:"ends_at"` }{ embed: embed(*a), } @@ -1091,7 +2078,12 @@ func (a *AcsUserAccessSchedule) UnmarshalJSON(data []byte) error { *a = AcsUserAccessSchedule(unmarshaler.embed) a.StartsAt = unmarshaler.StartsAt.Time() a.EndsAt = unmarshaler.EndsAt.Time() - a._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } @@ -1099,23 +2091,23 @@ func (a *AcsUserAccessSchedule) MarshalJSON() ([]byte, error) { type embed AcsUserAccessSchedule var marshaler = struct { embed - StartsAt *core.DateTime `json:"starts_at"` - EndsAt *core.DateTime `json:"ends_at"` + StartsAt *internal.DateTime `json:"starts_at"` + EndsAt *internal.DateTime `json:"ends_at"` }{ embed: embed(*a), - StartsAt: core.NewDateTime(a.StartsAt), - EndsAt: core.NewDateTime(a.EndsAt), + StartsAt: internal.NewDateTime(a.StartsAt), + EndsAt: internal.NewDateTime(a.EndsAt), } return json.Marshal(marshaler) } func (a *AcsUserAccessSchedule) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) @@ -1153,287 +2145,6847 @@ func (a AcsUserExternalType) Ptr() *AcsUserExternalType { } type ActionAttempt struct { - Status string - Success *ActionAttemptSuccess - Pending *ActionAttemptPending - Error *ActionAttemptError + // Locking door. + ActionAttemptZero *ActionAttemptZero + // Locking door succeeded. + ActionAttemptOne *ActionAttemptOne + // Locking door failed. + ActionAttemptTwo *ActionAttemptTwo + // Unlocking door. + ActionAttemptThree *ActionAttemptThree + // Unlocking door succeeded. + ActionAttemptFour *ActionAttemptFour + // Unlocking door failed. + ActionAttemptFive *ActionAttemptFive + // Resetting sandbox workspace. + ActionAttemptSix *ActionAttemptSix + // Resetting sandbox workspace succeeded. + ActionAttemptSeven *ActionAttemptSeven + // Resetting sandbox workspace failed. + ActionAttemptEight *ActionAttemptEight + // Setting HVAC to cool. + ActionAttemptNine *ActionAttemptNine + // Setting HVAC to cool succeeded. + ActionAttemptTen *ActionAttemptTen + // Setting HVAC to cool failed. + ActionAttemptEleven *ActionAttemptEleven + // Setting HVAC to heat mode. + ActionAttemptTwelve *ActionAttemptTwelve + // Setting HVAC to heat mode succeeded. + ActionAttemptThirteen *ActionAttemptThirteen + // Setting HVAC to heat mode failed. + ActionAttemptFourteen *ActionAttemptFourteen + // Setting HVAC to heat-cool mode. + ActionAttemptFifteen *ActionAttemptFifteen + // Setting HVAC to heat-cool mode succeeded. + ActionAttemptSixteen *ActionAttemptSixteen + // Setting heat-cool mode failed. + ActionAttemptSeventeen *ActionAttemptSeventeen + // Setting fan mode. + ActionAttemptEighteen *ActionAttemptEighteen + // Setting fan mode succeeded. + ActionAttemptNineteen *ActionAttemptNineteen + // Setting fan mode failed. + ActionAttemptTwenty *ActionAttemptTwenty + // Turning HVAC off. + ActionAttemptTwentyOne *ActionAttemptTwentyOne + // Turning HVAC off succeeded. + ActionAttemptTwentyTwo *ActionAttemptTwentyTwo + // Turning HVAC off failed. + ActionAttemptTwentyThree *ActionAttemptTwentyThree + ActionAttemptTwentyFour *ActionAttemptTwentyFour + ActionAttemptTwentyFive *ActionAttemptTwentyFive + ActionAttemptTwentySix *ActionAttemptTwentySix + ActionAttemptTwentySeven *ActionAttemptTwentySeven + ActionAttemptTwentyEight *ActionAttemptTwentyEight + ActionAttemptTwentyNine *ActionAttemptTwentyNine + ActionAttemptThirty *ActionAttemptThirty + ActionAttemptThirtyOne *ActionAttemptThirtyOne + ActionAttemptThirtyTwo *ActionAttemptThirtyTwo + ActionAttemptThirtyThree *ActionAttemptThirtyThree + ActionAttemptThirtyFour *ActionAttemptThirtyFour + ActionAttemptThirtyFive *ActionAttemptThirtyFive + ActionAttemptThirtySix *ActionAttemptThirtySix + ActionAttemptThirtySeven *ActionAttemptThirtySeven + ActionAttemptThirtyEight *ActionAttemptThirtyEight + ActionAttemptThirtyNine *ActionAttemptThirtyNine + ActionAttemptForty *ActionAttemptForty + ActionAttemptFortyOne *ActionAttemptFortyOne + ActionAttemptFortyTwo *ActionAttemptFortyTwo + ActionAttemptFortyThree *ActionAttemptFortyThree + ActionAttemptActionAttemptId *ActionAttemptActionAttemptId + + typ string } -func NewActionAttemptFromSuccess(value *ActionAttemptSuccess) *ActionAttempt { - return &ActionAttempt{Status: "success", Success: value} +func NewActionAttemptFromActionAttemptZero(value *ActionAttemptZero) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptZero", ActionAttemptZero: value} } -func NewActionAttemptFromPending(value *ActionAttemptPending) *ActionAttempt { - return &ActionAttempt{Status: "pending", Pending: value} +func NewActionAttemptFromActionAttemptOne(value *ActionAttemptOne) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptOne", ActionAttemptOne: value} } -func NewActionAttemptFromError(value *ActionAttemptError) *ActionAttempt { - return &ActionAttempt{Status: "error", Error: value} +func NewActionAttemptFromActionAttemptTwo(value *ActionAttemptTwo) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwo", ActionAttemptTwo: value} } -func (a *ActionAttempt) UnmarshalJSON(data []byte) error { - var unmarshaler struct { - Status string `json:"status"` - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err - } - a.Status = unmarshaler.Status - switch unmarshaler.Status { - case "success": - value := new(ActionAttemptSuccess) - if err := json.Unmarshal(data, &value); err != nil { - return err - } - a.Success = value - case "pending": - value := new(ActionAttemptPending) - if err := json.Unmarshal(data, &value); err != nil { - return err - } - a.Pending = value - case "error": - value := new(ActionAttemptError) - if err := json.Unmarshal(data, &value); err != nil { - return err - } - a.Error = value - } - return nil +func NewActionAttemptFromActionAttemptThree(value *ActionAttemptThree) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThree", ActionAttemptThree: value} } -func (a ActionAttempt) MarshalJSON() ([]byte, error) { - switch a.Status { - default: - return nil, fmt.Errorf("invalid type %s in %T", a.Status, a) - case "success": - var marshaler = struct { - Status string `json:"status"` - *ActionAttemptSuccess - }{ - Status: a.Status, - ActionAttemptSuccess: a.Success, - } - return json.Marshal(marshaler) - case "pending": - var marshaler = struct { - Status string `json:"status"` - *ActionAttemptPending - }{ - Status: a.Status, - ActionAttemptPending: a.Pending, - } - return json.Marshal(marshaler) - case "error": - var marshaler = struct { - Status string `json:"status"` - *ActionAttemptError - }{ - Status: a.Status, - ActionAttemptError: a.Error, - } - return json.Marshal(marshaler) - } +func NewActionAttemptFromActionAttemptFour(value *ActionAttemptFour) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFour", ActionAttemptFour: value} } -type ActionAttemptVisitor interface { - VisitSuccess(*ActionAttemptSuccess) error - VisitPending(*ActionAttemptPending) error - VisitError(*ActionAttemptError) error +func NewActionAttemptFromActionAttemptFive(value *ActionAttemptFive) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFive", ActionAttemptFive: value} } -func (a *ActionAttempt) Accept(visitor ActionAttemptVisitor) error { - switch a.Status { - default: - return fmt.Errorf("invalid type %s in %T", a.Status, a) - case "success": - return visitor.VisitSuccess(a.Success) - case "pending": - return visitor.VisitPending(a.Pending) - case "error": - return visitor.VisitError(a.Error) - } +func NewActionAttemptFromActionAttemptSix(value *ActionAttemptSix) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptSix", ActionAttemptSix: value} } -type ActionAttemptError struct { - ActionType string `json:"action_type" url:"action_type"` - ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` - Result *string `json:"result,omitempty" url:"result,omitempty"` - Error *ActionAttemptErrorError `json:"error,omitempty" url:"error,omitempty"` +func NewActionAttemptFromActionAttemptSeven(value *ActionAttemptSeven) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptSeven", ActionAttemptSeven: value} +} - _rawJSON json.RawMessage +func NewActionAttemptFromActionAttemptEight(value *ActionAttemptEight) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptEight", ActionAttemptEight: value} } -func (a *ActionAttemptError) UnmarshalJSON(data []byte) error { - type unmarshaler ActionAttemptError - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func NewActionAttemptFromActionAttemptNine(value *ActionAttemptNine) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptNine", ActionAttemptNine: value} +} + +func NewActionAttemptFromActionAttemptTen(value *ActionAttemptTen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTen", ActionAttemptTen: value} +} + +func NewActionAttemptFromActionAttemptEleven(value *ActionAttemptEleven) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptEleven", ActionAttemptEleven: value} +} + +func NewActionAttemptFromActionAttemptTwelve(value *ActionAttemptTwelve) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwelve", ActionAttemptTwelve: value} +} + +func NewActionAttemptFromActionAttemptThirteen(value *ActionAttemptThirteen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirteen", ActionAttemptThirteen: value} +} + +func NewActionAttemptFromActionAttemptFourteen(value *ActionAttemptFourteen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFourteen", ActionAttemptFourteen: value} +} + +func NewActionAttemptFromActionAttemptFifteen(value *ActionAttemptFifteen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFifteen", ActionAttemptFifteen: value} +} + +func NewActionAttemptFromActionAttemptSixteen(value *ActionAttemptSixteen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptSixteen", ActionAttemptSixteen: value} +} + +func NewActionAttemptFromActionAttemptSeventeen(value *ActionAttemptSeventeen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptSeventeen", ActionAttemptSeventeen: value} +} + +func NewActionAttemptFromActionAttemptEighteen(value *ActionAttemptEighteen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptEighteen", ActionAttemptEighteen: value} +} + +func NewActionAttemptFromActionAttemptNineteen(value *ActionAttemptNineteen) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptNineteen", ActionAttemptNineteen: value} +} + +func NewActionAttemptFromActionAttemptTwenty(value *ActionAttemptTwenty) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwenty", ActionAttemptTwenty: value} +} + +func NewActionAttemptFromActionAttemptTwentyOne(value *ActionAttemptTwentyOne) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyOne", ActionAttemptTwentyOne: value} +} + +func NewActionAttemptFromActionAttemptTwentyTwo(value *ActionAttemptTwentyTwo) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyTwo", ActionAttemptTwentyTwo: value} +} + +func NewActionAttemptFromActionAttemptTwentyThree(value *ActionAttemptTwentyThree) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyThree", ActionAttemptTwentyThree: value} +} + +func NewActionAttemptFromActionAttemptTwentyFour(value *ActionAttemptTwentyFour) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyFour", ActionAttemptTwentyFour: value} +} + +func NewActionAttemptFromActionAttemptTwentyFive(value *ActionAttemptTwentyFive) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyFive", ActionAttemptTwentyFive: value} +} + +func NewActionAttemptFromActionAttemptTwentySix(value *ActionAttemptTwentySix) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentySix", ActionAttemptTwentySix: value} +} + +func NewActionAttemptFromActionAttemptTwentySeven(value *ActionAttemptTwentySeven) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentySeven", ActionAttemptTwentySeven: value} +} + +func NewActionAttemptFromActionAttemptTwentyEight(value *ActionAttemptTwentyEight) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyEight", ActionAttemptTwentyEight: value} +} + +func NewActionAttemptFromActionAttemptTwentyNine(value *ActionAttemptTwentyNine) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptTwentyNine", ActionAttemptTwentyNine: value} +} + +func NewActionAttemptFromActionAttemptThirty(value *ActionAttemptThirty) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirty", ActionAttemptThirty: value} +} + +func NewActionAttemptFromActionAttemptThirtyOne(value *ActionAttemptThirtyOne) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyOne", ActionAttemptThirtyOne: value} +} + +func NewActionAttemptFromActionAttemptThirtyTwo(value *ActionAttemptThirtyTwo) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyTwo", ActionAttemptThirtyTwo: value} +} + +func NewActionAttemptFromActionAttemptThirtyThree(value *ActionAttemptThirtyThree) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyThree", ActionAttemptThirtyThree: value} +} + +func NewActionAttemptFromActionAttemptThirtyFour(value *ActionAttemptThirtyFour) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyFour", ActionAttemptThirtyFour: value} +} + +func NewActionAttemptFromActionAttemptThirtyFive(value *ActionAttemptThirtyFive) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyFive", ActionAttemptThirtyFive: value} +} + +func NewActionAttemptFromActionAttemptThirtySix(value *ActionAttemptThirtySix) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtySix", ActionAttemptThirtySix: value} +} + +func NewActionAttemptFromActionAttemptThirtySeven(value *ActionAttemptThirtySeven) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtySeven", ActionAttemptThirtySeven: value} +} + +func NewActionAttemptFromActionAttemptThirtyEight(value *ActionAttemptThirtyEight) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyEight", ActionAttemptThirtyEight: value} +} + +func NewActionAttemptFromActionAttemptThirtyNine(value *ActionAttemptThirtyNine) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptThirtyNine", ActionAttemptThirtyNine: value} +} + +func NewActionAttemptFromActionAttemptForty(value *ActionAttemptForty) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptForty", ActionAttemptForty: value} +} + +func NewActionAttemptFromActionAttemptFortyOne(value *ActionAttemptFortyOne) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFortyOne", ActionAttemptFortyOne: value} +} + +func NewActionAttemptFromActionAttemptFortyTwo(value *ActionAttemptFortyTwo) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFortyTwo", ActionAttemptFortyTwo: value} +} + +func NewActionAttemptFromActionAttemptFortyThree(value *ActionAttemptFortyThree) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptFortyThree", ActionAttemptFortyThree: value} +} + +func NewActionAttemptFromActionAttemptActionAttemptId(value *ActionAttemptActionAttemptId) *ActionAttempt { + return &ActionAttempt{typ: "ActionAttemptActionAttemptId", ActionAttemptActionAttemptId: value} +} + +func (a *ActionAttempt) GetActionAttemptZero() *ActionAttemptZero { + if a == nil { + return nil } - *a = ActionAttemptError(value) - a._rawJSON = json.RawMessage(data) - return nil + return a.ActionAttemptZero } -func (a *ActionAttemptError) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { - return value - } +func (a *ActionAttempt) GetActionAttemptOne() *ActionAttemptOne { + if a == nil { + return nil } - if value, err := core.StringifyJSON(a); err == nil { - return value + return a.ActionAttemptOne +} + +func (a *ActionAttempt) GetActionAttemptTwo() *ActionAttemptTwo { + if a == nil { + return nil } - return fmt.Sprintf("%#v", a) + return a.ActionAttemptTwo } -type ActionAttemptErrorError struct { - Type string `json:"type" url:"type"` - Message string `json:"message" url:"message"` +func (a *ActionAttempt) GetActionAttemptThree() *ActionAttemptThree { + if a == nil { + return nil + } + return a.ActionAttemptThree +} - _rawJSON json.RawMessage +func (a *ActionAttempt) GetActionAttemptFour() *ActionAttemptFour { + if a == nil { + return nil + } + return a.ActionAttemptFour } -func (a *ActionAttemptErrorError) UnmarshalJSON(data []byte) error { - type unmarshaler ActionAttemptErrorError - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func (a *ActionAttempt) GetActionAttemptFive() *ActionAttemptFive { + if a == nil { + return nil } - *a = ActionAttemptErrorError(value) - a._rawJSON = json.RawMessage(data) - return nil + return a.ActionAttemptFive } -func (a *ActionAttemptErrorError) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { - return value - } +func (a *ActionAttempt) GetActionAttemptSix() *ActionAttemptSix { + if a == nil { + return nil } - if value, err := core.StringifyJSON(a); err == nil { - return value + return a.ActionAttemptSix +} + +func (a *ActionAttempt) GetActionAttemptSeven() *ActionAttemptSeven { + if a == nil { + return nil } - return fmt.Sprintf("%#v", a) + return a.ActionAttemptSeven +} + +func (a *ActionAttempt) GetActionAttemptEight() *ActionAttemptEight { + if a == nil { + return nil + } + return a.ActionAttemptEight +} + +func (a *ActionAttempt) GetActionAttemptNine() *ActionAttemptNine { + if a == nil { + return nil + } + return a.ActionAttemptNine +} + +func (a *ActionAttempt) GetActionAttemptTen() *ActionAttemptTen { + if a == nil { + return nil + } + return a.ActionAttemptTen +} + +func (a *ActionAttempt) GetActionAttemptEleven() *ActionAttemptEleven { + if a == nil { + return nil + } + return a.ActionAttemptEleven +} + +func (a *ActionAttempt) GetActionAttemptTwelve() *ActionAttemptTwelve { + if a == nil { + return nil + } + return a.ActionAttemptTwelve +} + +func (a *ActionAttempt) GetActionAttemptThirteen() *ActionAttemptThirteen { + if a == nil { + return nil + } + return a.ActionAttemptThirteen +} + +func (a *ActionAttempt) GetActionAttemptFourteen() *ActionAttemptFourteen { + if a == nil { + return nil + } + return a.ActionAttemptFourteen +} + +func (a *ActionAttempt) GetActionAttemptFifteen() *ActionAttemptFifteen { + if a == nil { + return nil + } + return a.ActionAttemptFifteen +} + +func (a *ActionAttempt) GetActionAttemptSixteen() *ActionAttemptSixteen { + if a == nil { + return nil + } + return a.ActionAttemptSixteen +} + +func (a *ActionAttempt) GetActionAttemptSeventeen() *ActionAttemptSeventeen { + if a == nil { + return nil + } + return a.ActionAttemptSeventeen +} + +func (a *ActionAttempt) GetActionAttemptEighteen() *ActionAttemptEighteen { + if a == nil { + return nil + } + return a.ActionAttemptEighteen +} + +func (a *ActionAttempt) GetActionAttemptNineteen() *ActionAttemptNineteen { + if a == nil { + return nil + } + return a.ActionAttemptNineteen +} + +func (a *ActionAttempt) GetActionAttemptTwenty() *ActionAttemptTwenty { + if a == nil { + return nil + } + return a.ActionAttemptTwenty +} + +func (a *ActionAttempt) GetActionAttemptTwentyOne() *ActionAttemptTwentyOne { + if a == nil { + return nil + } + return a.ActionAttemptTwentyOne +} + +func (a *ActionAttempt) GetActionAttemptTwentyTwo() *ActionAttemptTwentyTwo { + if a == nil { + return nil + } + return a.ActionAttemptTwentyTwo +} + +func (a *ActionAttempt) GetActionAttemptTwentyThree() *ActionAttemptTwentyThree { + if a == nil { + return nil + } + return a.ActionAttemptTwentyThree +} + +func (a *ActionAttempt) GetActionAttemptTwentyFour() *ActionAttemptTwentyFour { + if a == nil { + return nil + } + return a.ActionAttemptTwentyFour +} + +func (a *ActionAttempt) GetActionAttemptTwentyFive() *ActionAttemptTwentyFive { + if a == nil { + return nil + } + return a.ActionAttemptTwentyFive +} + +func (a *ActionAttempt) GetActionAttemptTwentySix() *ActionAttemptTwentySix { + if a == nil { + return nil + } + return a.ActionAttemptTwentySix +} + +func (a *ActionAttempt) GetActionAttemptTwentySeven() *ActionAttemptTwentySeven { + if a == nil { + return nil + } + return a.ActionAttemptTwentySeven +} + +func (a *ActionAttempt) GetActionAttemptTwentyEight() *ActionAttemptTwentyEight { + if a == nil { + return nil + } + return a.ActionAttemptTwentyEight +} + +func (a *ActionAttempt) GetActionAttemptTwentyNine() *ActionAttemptTwentyNine { + if a == nil { + return nil + } + return a.ActionAttemptTwentyNine +} + +func (a *ActionAttempt) GetActionAttemptThirty() *ActionAttemptThirty { + if a == nil { + return nil + } + return a.ActionAttemptThirty +} + +func (a *ActionAttempt) GetActionAttemptThirtyOne() *ActionAttemptThirtyOne { + if a == nil { + return nil + } + return a.ActionAttemptThirtyOne +} + +func (a *ActionAttempt) GetActionAttemptThirtyTwo() *ActionAttemptThirtyTwo { + if a == nil { + return nil + } + return a.ActionAttemptThirtyTwo +} + +func (a *ActionAttempt) GetActionAttemptThirtyThree() *ActionAttemptThirtyThree { + if a == nil { + return nil + } + return a.ActionAttemptThirtyThree +} + +func (a *ActionAttempt) GetActionAttemptThirtyFour() *ActionAttemptThirtyFour { + if a == nil { + return nil + } + return a.ActionAttemptThirtyFour +} + +func (a *ActionAttempt) GetActionAttemptThirtyFive() *ActionAttemptThirtyFive { + if a == nil { + return nil + } + return a.ActionAttemptThirtyFive +} + +func (a *ActionAttempt) GetActionAttemptThirtySix() *ActionAttemptThirtySix { + if a == nil { + return nil + } + return a.ActionAttemptThirtySix +} + +func (a *ActionAttempt) GetActionAttemptThirtySeven() *ActionAttemptThirtySeven { + if a == nil { + return nil + } + return a.ActionAttemptThirtySeven +} + +func (a *ActionAttempt) GetActionAttemptThirtyEight() *ActionAttemptThirtyEight { + if a == nil { + return nil + } + return a.ActionAttemptThirtyEight +} + +func (a *ActionAttempt) GetActionAttemptThirtyNine() *ActionAttemptThirtyNine { + if a == nil { + return nil + } + return a.ActionAttemptThirtyNine +} + +func (a *ActionAttempt) GetActionAttemptForty() *ActionAttemptForty { + if a == nil { + return nil + } + return a.ActionAttemptForty +} + +func (a *ActionAttempt) GetActionAttemptFortyOne() *ActionAttemptFortyOne { + if a == nil { + return nil + } + return a.ActionAttemptFortyOne +} + +func (a *ActionAttempt) GetActionAttemptFortyTwo() *ActionAttemptFortyTwo { + if a == nil { + return nil + } + return a.ActionAttemptFortyTwo +} + +func (a *ActionAttempt) GetActionAttemptFortyThree() *ActionAttemptFortyThree { + if a == nil { + return nil + } + return a.ActionAttemptFortyThree +} + +func (a *ActionAttempt) GetActionAttemptActionAttemptId() *ActionAttemptActionAttemptId { + if a == nil { + return nil + } + return a.ActionAttemptActionAttemptId +} + +func (a *ActionAttempt) UnmarshalJSON(data []byte) error { + valueActionAttemptZero := new(ActionAttemptZero) + if err := json.Unmarshal(data, &valueActionAttemptZero); err == nil { + a.typ = "ActionAttemptZero" + a.ActionAttemptZero = valueActionAttemptZero + return nil + } + valueActionAttemptOne := new(ActionAttemptOne) + if err := json.Unmarshal(data, &valueActionAttemptOne); err == nil { + a.typ = "ActionAttemptOne" + a.ActionAttemptOne = valueActionAttemptOne + return nil + } + valueActionAttemptTwo := new(ActionAttemptTwo) + if err := json.Unmarshal(data, &valueActionAttemptTwo); err == nil { + a.typ = "ActionAttemptTwo" + a.ActionAttemptTwo = valueActionAttemptTwo + return nil + } + valueActionAttemptThree := new(ActionAttemptThree) + if err := json.Unmarshal(data, &valueActionAttemptThree); err == nil { + a.typ = "ActionAttemptThree" + a.ActionAttemptThree = valueActionAttemptThree + return nil + } + valueActionAttemptFour := new(ActionAttemptFour) + if err := json.Unmarshal(data, &valueActionAttemptFour); err == nil { + a.typ = "ActionAttemptFour" + a.ActionAttemptFour = valueActionAttemptFour + return nil + } + valueActionAttemptFive := new(ActionAttemptFive) + if err := json.Unmarshal(data, &valueActionAttemptFive); err == nil { + a.typ = "ActionAttemptFive" + a.ActionAttemptFive = valueActionAttemptFive + return nil + } + valueActionAttemptSix := new(ActionAttemptSix) + if err := json.Unmarshal(data, &valueActionAttemptSix); err == nil { + a.typ = "ActionAttemptSix" + a.ActionAttemptSix = valueActionAttemptSix + return nil + } + valueActionAttemptSeven := new(ActionAttemptSeven) + if err := json.Unmarshal(data, &valueActionAttemptSeven); err == nil { + a.typ = "ActionAttemptSeven" + a.ActionAttemptSeven = valueActionAttemptSeven + return nil + } + valueActionAttemptEight := new(ActionAttemptEight) + if err := json.Unmarshal(data, &valueActionAttemptEight); err == nil { + a.typ = "ActionAttemptEight" + a.ActionAttemptEight = valueActionAttemptEight + return nil + } + valueActionAttemptNine := new(ActionAttemptNine) + if err := json.Unmarshal(data, &valueActionAttemptNine); err == nil { + a.typ = "ActionAttemptNine" + a.ActionAttemptNine = valueActionAttemptNine + return nil + } + valueActionAttemptTen := new(ActionAttemptTen) + if err := json.Unmarshal(data, &valueActionAttemptTen); err == nil { + a.typ = "ActionAttemptTen" + a.ActionAttemptTen = valueActionAttemptTen + return nil + } + valueActionAttemptEleven := new(ActionAttemptEleven) + if err := json.Unmarshal(data, &valueActionAttemptEleven); err == nil { + a.typ = "ActionAttemptEleven" + a.ActionAttemptEleven = valueActionAttemptEleven + return nil + } + valueActionAttemptTwelve := new(ActionAttemptTwelve) + if err := json.Unmarshal(data, &valueActionAttemptTwelve); err == nil { + a.typ = "ActionAttemptTwelve" + a.ActionAttemptTwelve = valueActionAttemptTwelve + return nil + } + valueActionAttemptThirteen := new(ActionAttemptThirteen) + if err := json.Unmarshal(data, &valueActionAttemptThirteen); err == nil { + a.typ = "ActionAttemptThirteen" + a.ActionAttemptThirteen = valueActionAttemptThirteen + return nil + } + valueActionAttemptFourteen := new(ActionAttemptFourteen) + if err := json.Unmarshal(data, &valueActionAttemptFourteen); err == nil { + a.typ = "ActionAttemptFourteen" + a.ActionAttemptFourteen = valueActionAttemptFourteen + return nil + } + valueActionAttemptFifteen := new(ActionAttemptFifteen) + if err := json.Unmarshal(data, &valueActionAttemptFifteen); err == nil { + a.typ = "ActionAttemptFifteen" + a.ActionAttemptFifteen = valueActionAttemptFifteen + return nil + } + valueActionAttemptSixteen := new(ActionAttemptSixteen) + if err := json.Unmarshal(data, &valueActionAttemptSixteen); err == nil { + a.typ = "ActionAttemptSixteen" + a.ActionAttemptSixteen = valueActionAttemptSixteen + return nil + } + valueActionAttemptSeventeen := new(ActionAttemptSeventeen) + if err := json.Unmarshal(data, &valueActionAttemptSeventeen); err == nil { + a.typ = "ActionAttemptSeventeen" + a.ActionAttemptSeventeen = valueActionAttemptSeventeen + return nil + } + valueActionAttemptEighteen := new(ActionAttemptEighteen) + if err := json.Unmarshal(data, &valueActionAttemptEighteen); err == nil { + a.typ = "ActionAttemptEighteen" + a.ActionAttemptEighteen = valueActionAttemptEighteen + return nil + } + valueActionAttemptNineteen := new(ActionAttemptNineteen) + if err := json.Unmarshal(data, &valueActionAttemptNineteen); err == nil { + a.typ = "ActionAttemptNineteen" + a.ActionAttemptNineteen = valueActionAttemptNineteen + return nil + } + valueActionAttemptTwenty := new(ActionAttemptTwenty) + if err := json.Unmarshal(data, &valueActionAttemptTwenty); err == nil { + a.typ = "ActionAttemptTwenty" + a.ActionAttemptTwenty = valueActionAttemptTwenty + return nil + } + valueActionAttemptTwentyOne := new(ActionAttemptTwentyOne) + if err := json.Unmarshal(data, &valueActionAttemptTwentyOne); err == nil { + a.typ = "ActionAttemptTwentyOne" + a.ActionAttemptTwentyOne = valueActionAttemptTwentyOne + return nil + } + valueActionAttemptTwentyTwo := new(ActionAttemptTwentyTwo) + if err := json.Unmarshal(data, &valueActionAttemptTwentyTwo); err == nil { + a.typ = "ActionAttemptTwentyTwo" + a.ActionAttemptTwentyTwo = valueActionAttemptTwentyTwo + return nil + } + valueActionAttemptTwentyThree := new(ActionAttemptTwentyThree) + if err := json.Unmarshal(data, &valueActionAttemptTwentyThree); err == nil { + a.typ = "ActionAttemptTwentyThree" + a.ActionAttemptTwentyThree = valueActionAttemptTwentyThree + return nil + } + valueActionAttemptTwentyFour := new(ActionAttemptTwentyFour) + if err := json.Unmarshal(data, &valueActionAttemptTwentyFour); err == nil { + a.typ = "ActionAttemptTwentyFour" + a.ActionAttemptTwentyFour = valueActionAttemptTwentyFour + return nil + } + valueActionAttemptTwentyFive := new(ActionAttemptTwentyFive) + if err := json.Unmarshal(data, &valueActionAttemptTwentyFive); err == nil { + a.typ = "ActionAttemptTwentyFive" + a.ActionAttemptTwentyFive = valueActionAttemptTwentyFive + return nil + } + valueActionAttemptTwentySix := new(ActionAttemptTwentySix) + if err := json.Unmarshal(data, &valueActionAttemptTwentySix); err == nil { + a.typ = "ActionAttemptTwentySix" + a.ActionAttemptTwentySix = valueActionAttemptTwentySix + return nil + } + valueActionAttemptTwentySeven := new(ActionAttemptTwentySeven) + if err := json.Unmarshal(data, &valueActionAttemptTwentySeven); err == nil { + a.typ = "ActionAttemptTwentySeven" + a.ActionAttemptTwentySeven = valueActionAttemptTwentySeven + return nil + } + valueActionAttemptTwentyEight := new(ActionAttemptTwentyEight) + if err := json.Unmarshal(data, &valueActionAttemptTwentyEight); err == nil { + a.typ = "ActionAttemptTwentyEight" + a.ActionAttemptTwentyEight = valueActionAttemptTwentyEight + return nil + } + valueActionAttemptTwentyNine := new(ActionAttemptTwentyNine) + if err := json.Unmarshal(data, &valueActionAttemptTwentyNine); err == nil { + a.typ = "ActionAttemptTwentyNine" + a.ActionAttemptTwentyNine = valueActionAttemptTwentyNine + return nil + } + valueActionAttemptThirty := new(ActionAttemptThirty) + if err := json.Unmarshal(data, &valueActionAttemptThirty); err == nil { + a.typ = "ActionAttemptThirty" + a.ActionAttemptThirty = valueActionAttemptThirty + return nil + } + valueActionAttemptThirtyOne := new(ActionAttemptThirtyOne) + if err := json.Unmarshal(data, &valueActionAttemptThirtyOne); err == nil { + a.typ = "ActionAttemptThirtyOne" + a.ActionAttemptThirtyOne = valueActionAttemptThirtyOne + return nil + } + valueActionAttemptThirtyTwo := new(ActionAttemptThirtyTwo) + if err := json.Unmarshal(data, &valueActionAttemptThirtyTwo); err == nil { + a.typ = "ActionAttemptThirtyTwo" + a.ActionAttemptThirtyTwo = valueActionAttemptThirtyTwo + return nil + } + valueActionAttemptThirtyThree := new(ActionAttemptThirtyThree) + if err := json.Unmarshal(data, &valueActionAttemptThirtyThree); err == nil { + a.typ = "ActionAttemptThirtyThree" + a.ActionAttemptThirtyThree = valueActionAttemptThirtyThree + return nil + } + valueActionAttemptThirtyFour := new(ActionAttemptThirtyFour) + if err := json.Unmarshal(data, &valueActionAttemptThirtyFour); err == nil { + a.typ = "ActionAttemptThirtyFour" + a.ActionAttemptThirtyFour = valueActionAttemptThirtyFour + return nil + } + valueActionAttemptThirtyFive := new(ActionAttemptThirtyFive) + if err := json.Unmarshal(data, &valueActionAttemptThirtyFive); err == nil { + a.typ = "ActionAttemptThirtyFive" + a.ActionAttemptThirtyFive = valueActionAttemptThirtyFive + return nil + } + valueActionAttemptThirtySix := new(ActionAttemptThirtySix) + if err := json.Unmarshal(data, &valueActionAttemptThirtySix); err == nil { + a.typ = "ActionAttemptThirtySix" + a.ActionAttemptThirtySix = valueActionAttemptThirtySix + return nil + } + valueActionAttemptThirtySeven := new(ActionAttemptThirtySeven) + if err := json.Unmarshal(data, &valueActionAttemptThirtySeven); err == nil { + a.typ = "ActionAttemptThirtySeven" + a.ActionAttemptThirtySeven = valueActionAttemptThirtySeven + return nil + } + valueActionAttemptThirtyEight := new(ActionAttemptThirtyEight) + if err := json.Unmarshal(data, &valueActionAttemptThirtyEight); err == nil { + a.typ = "ActionAttemptThirtyEight" + a.ActionAttemptThirtyEight = valueActionAttemptThirtyEight + return nil + } + valueActionAttemptThirtyNine := new(ActionAttemptThirtyNine) + if err := json.Unmarshal(data, &valueActionAttemptThirtyNine); err == nil { + a.typ = "ActionAttemptThirtyNine" + a.ActionAttemptThirtyNine = valueActionAttemptThirtyNine + return nil + } + valueActionAttemptForty := new(ActionAttemptForty) + if err := json.Unmarshal(data, &valueActionAttemptForty); err == nil { + a.typ = "ActionAttemptForty" + a.ActionAttemptForty = valueActionAttemptForty + return nil + } + valueActionAttemptFortyOne := new(ActionAttemptFortyOne) + if err := json.Unmarshal(data, &valueActionAttemptFortyOne); err == nil { + a.typ = "ActionAttemptFortyOne" + a.ActionAttemptFortyOne = valueActionAttemptFortyOne + return nil + } + valueActionAttemptFortyTwo := new(ActionAttemptFortyTwo) + if err := json.Unmarshal(data, &valueActionAttemptFortyTwo); err == nil { + a.typ = "ActionAttemptFortyTwo" + a.ActionAttemptFortyTwo = valueActionAttemptFortyTwo + return nil + } + valueActionAttemptFortyThree := new(ActionAttemptFortyThree) + if err := json.Unmarshal(data, &valueActionAttemptFortyThree); err == nil { + a.typ = "ActionAttemptFortyThree" + a.ActionAttemptFortyThree = valueActionAttemptFortyThree + return nil + } + valueActionAttemptActionAttemptId := new(ActionAttemptActionAttemptId) + if err := json.Unmarshal(data, &valueActionAttemptActionAttemptId); err == nil { + a.typ = "ActionAttemptActionAttemptId" + a.ActionAttemptActionAttemptId = valueActionAttemptActionAttemptId + return nil + } + return fmt.Errorf("%s cannot be deserialized as a %T", data, a) +} + +func (a ActionAttempt) MarshalJSON() ([]byte, error) { + if a.typ == "ActionAttemptZero" || a.ActionAttemptZero != nil { + return json.Marshal(a.ActionAttemptZero) + } + if a.typ == "ActionAttemptOne" || a.ActionAttemptOne != nil { + return json.Marshal(a.ActionAttemptOne) + } + if a.typ == "ActionAttemptTwo" || a.ActionAttemptTwo != nil { + return json.Marshal(a.ActionAttemptTwo) + } + if a.typ == "ActionAttemptThree" || a.ActionAttemptThree != nil { + return json.Marshal(a.ActionAttemptThree) + } + if a.typ == "ActionAttemptFour" || a.ActionAttemptFour != nil { + return json.Marshal(a.ActionAttemptFour) + } + if a.typ == "ActionAttemptFive" || a.ActionAttemptFive != nil { + return json.Marshal(a.ActionAttemptFive) + } + if a.typ == "ActionAttemptSix" || a.ActionAttemptSix != nil { + return json.Marshal(a.ActionAttemptSix) + } + if a.typ == "ActionAttemptSeven" || a.ActionAttemptSeven != nil { + return json.Marshal(a.ActionAttemptSeven) + } + if a.typ == "ActionAttemptEight" || a.ActionAttemptEight != nil { + return json.Marshal(a.ActionAttemptEight) + } + if a.typ == "ActionAttemptNine" || a.ActionAttemptNine != nil { + return json.Marshal(a.ActionAttemptNine) + } + if a.typ == "ActionAttemptTen" || a.ActionAttemptTen != nil { + return json.Marshal(a.ActionAttemptTen) + } + if a.typ == "ActionAttemptEleven" || a.ActionAttemptEleven != nil { + return json.Marshal(a.ActionAttemptEleven) + } + if a.typ == "ActionAttemptTwelve" || a.ActionAttemptTwelve != nil { + return json.Marshal(a.ActionAttemptTwelve) + } + if a.typ == "ActionAttemptThirteen" || a.ActionAttemptThirteen != nil { + return json.Marshal(a.ActionAttemptThirteen) + } + if a.typ == "ActionAttemptFourteen" || a.ActionAttemptFourteen != nil { + return json.Marshal(a.ActionAttemptFourteen) + } + if a.typ == "ActionAttemptFifteen" || a.ActionAttemptFifteen != nil { + return json.Marshal(a.ActionAttemptFifteen) + } + if a.typ == "ActionAttemptSixteen" || a.ActionAttemptSixteen != nil { + return json.Marshal(a.ActionAttemptSixteen) + } + if a.typ == "ActionAttemptSeventeen" || a.ActionAttemptSeventeen != nil { + return json.Marshal(a.ActionAttemptSeventeen) + } + if a.typ == "ActionAttemptEighteen" || a.ActionAttemptEighteen != nil { + return json.Marshal(a.ActionAttemptEighteen) + } + if a.typ == "ActionAttemptNineteen" || a.ActionAttemptNineteen != nil { + return json.Marshal(a.ActionAttemptNineteen) + } + if a.typ == "ActionAttemptTwenty" || a.ActionAttemptTwenty != nil { + return json.Marshal(a.ActionAttemptTwenty) + } + if a.typ == "ActionAttemptTwentyOne" || a.ActionAttemptTwentyOne != nil { + return json.Marshal(a.ActionAttemptTwentyOne) + } + if a.typ == "ActionAttemptTwentyTwo" || a.ActionAttemptTwentyTwo != nil { + return json.Marshal(a.ActionAttemptTwentyTwo) + } + if a.typ == "ActionAttemptTwentyThree" || a.ActionAttemptTwentyThree != nil { + return json.Marshal(a.ActionAttemptTwentyThree) + } + if a.typ == "ActionAttemptTwentyFour" || a.ActionAttemptTwentyFour != nil { + return json.Marshal(a.ActionAttemptTwentyFour) + } + if a.typ == "ActionAttemptTwentyFive" || a.ActionAttemptTwentyFive != nil { + return json.Marshal(a.ActionAttemptTwentyFive) + } + if a.typ == "ActionAttemptTwentySix" || a.ActionAttemptTwentySix != nil { + return json.Marshal(a.ActionAttemptTwentySix) + } + if a.typ == "ActionAttemptTwentySeven" || a.ActionAttemptTwentySeven != nil { + return json.Marshal(a.ActionAttemptTwentySeven) + } + if a.typ == "ActionAttemptTwentyEight" || a.ActionAttemptTwentyEight != nil { + return json.Marshal(a.ActionAttemptTwentyEight) + } + if a.typ == "ActionAttemptTwentyNine" || a.ActionAttemptTwentyNine != nil { + return json.Marshal(a.ActionAttemptTwentyNine) + } + if a.typ == "ActionAttemptThirty" || a.ActionAttemptThirty != nil { + return json.Marshal(a.ActionAttemptThirty) + } + if a.typ == "ActionAttemptThirtyOne" || a.ActionAttemptThirtyOne != nil { + return json.Marshal(a.ActionAttemptThirtyOne) + } + if a.typ == "ActionAttemptThirtyTwo" || a.ActionAttemptThirtyTwo != nil { + return json.Marshal(a.ActionAttemptThirtyTwo) + } + if a.typ == "ActionAttemptThirtyThree" || a.ActionAttemptThirtyThree != nil { + return json.Marshal(a.ActionAttemptThirtyThree) + } + if a.typ == "ActionAttemptThirtyFour" || a.ActionAttemptThirtyFour != nil { + return json.Marshal(a.ActionAttemptThirtyFour) + } + if a.typ == "ActionAttemptThirtyFive" || a.ActionAttemptThirtyFive != nil { + return json.Marshal(a.ActionAttemptThirtyFive) + } + if a.typ == "ActionAttemptThirtySix" || a.ActionAttemptThirtySix != nil { + return json.Marshal(a.ActionAttemptThirtySix) + } + if a.typ == "ActionAttemptThirtySeven" || a.ActionAttemptThirtySeven != nil { + return json.Marshal(a.ActionAttemptThirtySeven) + } + if a.typ == "ActionAttemptThirtyEight" || a.ActionAttemptThirtyEight != nil { + return json.Marshal(a.ActionAttemptThirtyEight) + } + if a.typ == "ActionAttemptThirtyNine" || a.ActionAttemptThirtyNine != nil { + return json.Marshal(a.ActionAttemptThirtyNine) + } + if a.typ == "ActionAttemptForty" || a.ActionAttemptForty != nil { + return json.Marshal(a.ActionAttemptForty) + } + if a.typ == "ActionAttemptFortyOne" || a.ActionAttemptFortyOne != nil { + return json.Marshal(a.ActionAttemptFortyOne) + } + if a.typ == "ActionAttemptFortyTwo" || a.ActionAttemptFortyTwo != nil { + return json.Marshal(a.ActionAttemptFortyTwo) + } + if a.typ == "ActionAttemptFortyThree" || a.ActionAttemptFortyThree != nil { + return json.Marshal(a.ActionAttemptFortyThree) + } + if a.typ == "ActionAttemptActionAttemptId" || a.ActionAttemptActionAttemptId != nil { + return json.Marshal(a.ActionAttemptActionAttemptId) + } + return nil, fmt.Errorf("type %T does not include a non-empty union type", a) +} + +type ActionAttemptVisitor interface { + VisitActionAttemptZero(*ActionAttemptZero) error + VisitActionAttemptOne(*ActionAttemptOne) error + VisitActionAttemptTwo(*ActionAttemptTwo) error + VisitActionAttemptThree(*ActionAttemptThree) error + VisitActionAttemptFour(*ActionAttemptFour) error + VisitActionAttemptFive(*ActionAttemptFive) error + VisitActionAttemptSix(*ActionAttemptSix) error + VisitActionAttemptSeven(*ActionAttemptSeven) error + VisitActionAttemptEight(*ActionAttemptEight) error + VisitActionAttemptNine(*ActionAttemptNine) error + VisitActionAttemptTen(*ActionAttemptTen) error + VisitActionAttemptEleven(*ActionAttemptEleven) error + VisitActionAttemptTwelve(*ActionAttemptTwelve) error + VisitActionAttemptThirteen(*ActionAttemptThirteen) error + VisitActionAttemptFourteen(*ActionAttemptFourteen) error + VisitActionAttemptFifteen(*ActionAttemptFifteen) error + VisitActionAttemptSixteen(*ActionAttemptSixteen) error + VisitActionAttemptSeventeen(*ActionAttemptSeventeen) error + VisitActionAttemptEighteen(*ActionAttemptEighteen) error + VisitActionAttemptNineteen(*ActionAttemptNineteen) error + VisitActionAttemptTwenty(*ActionAttemptTwenty) error + VisitActionAttemptTwentyOne(*ActionAttemptTwentyOne) error + VisitActionAttemptTwentyTwo(*ActionAttemptTwentyTwo) error + VisitActionAttemptTwentyThree(*ActionAttemptTwentyThree) error + VisitActionAttemptTwentyFour(*ActionAttemptTwentyFour) error + VisitActionAttemptTwentyFive(*ActionAttemptTwentyFive) error + VisitActionAttemptTwentySix(*ActionAttemptTwentySix) error + VisitActionAttemptTwentySeven(*ActionAttemptTwentySeven) error + VisitActionAttemptTwentyEight(*ActionAttemptTwentyEight) error + VisitActionAttemptTwentyNine(*ActionAttemptTwentyNine) error + VisitActionAttemptThirty(*ActionAttemptThirty) error + VisitActionAttemptThirtyOne(*ActionAttemptThirtyOne) error + VisitActionAttemptThirtyTwo(*ActionAttemptThirtyTwo) error + VisitActionAttemptThirtyThree(*ActionAttemptThirtyThree) error + VisitActionAttemptThirtyFour(*ActionAttemptThirtyFour) error + VisitActionAttemptThirtyFive(*ActionAttemptThirtyFive) error + VisitActionAttemptThirtySix(*ActionAttemptThirtySix) error + VisitActionAttemptThirtySeven(*ActionAttemptThirtySeven) error + VisitActionAttemptThirtyEight(*ActionAttemptThirtyEight) error + VisitActionAttemptThirtyNine(*ActionAttemptThirtyNine) error + VisitActionAttemptForty(*ActionAttemptForty) error + VisitActionAttemptFortyOne(*ActionAttemptFortyOne) error + VisitActionAttemptFortyTwo(*ActionAttemptFortyTwo) error + VisitActionAttemptFortyThree(*ActionAttemptFortyThree) error + VisitActionAttemptActionAttemptId(*ActionAttemptActionAttemptId) error +} + +func (a *ActionAttempt) Accept(visitor ActionAttemptVisitor) error { + if a.typ == "ActionAttemptZero" || a.ActionAttemptZero != nil { + return visitor.VisitActionAttemptZero(a.ActionAttemptZero) + } + if a.typ == "ActionAttemptOne" || a.ActionAttemptOne != nil { + return visitor.VisitActionAttemptOne(a.ActionAttemptOne) + } + if a.typ == "ActionAttemptTwo" || a.ActionAttemptTwo != nil { + return visitor.VisitActionAttemptTwo(a.ActionAttemptTwo) + } + if a.typ == "ActionAttemptThree" || a.ActionAttemptThree != nil { + return visitor.VisitActionAttemptThree(a.ActionAttemptThree) + } + if a.typ == "ActionAttemptFour" || a.ActionAttemptFour != nil { + return visitor.VisitActionAttemptFour(a.ActionAttemptFour) + } + if a.typ == "ActionAttemptFive" || a.ActionAttemptFive != nil { + return visitor.VisitActionAttemptFive(a.ActionAttemptFive) + } + if a.typ == "ActionAttemptSix" || a.ActionAttemptSix != nil { + return visitor.VisitActionAttemptSix(a.ActionAttemptSix) + } + if a.typ == "ActionAttemptSeven" || a.ActionAttemptSeven != nil { + return visitor.VisitActionAttemptSeven(a.ActionAttemptSeven) + } + if a.typ == "ActionAttemptEight" || a.ActionAttemptEight != nil { + return visitor.VisitActionAttemptEight(a.ActionAttemptEight) + } + if a.typ == "ActionAttemptNine" || a.ActionAttemptNine != nil { + return visitor.VisitActionAttemptNine(a.ActionAttemptNine) + } + if a.typ == "ActionAttemptTen" || a.ActionAttemptTen != nil { + return visitor.VisitActionAttemptTen(a.ActionAttemptTen) + } + if a.typ == "ActionAttemptEleven" || a.ActionAttemptEleven != nil { + return visitor.VisitActionAttemptEleven(a.ActionAttemptEleven) + } + if a.typ == "ActionAttemptTwelve" || a.ActionAttemptTwelve != nil { + return visitor.VisitActionAttemptTwelve(a.ActionAttemptTwelve) + } + if a.typ == "ActionAttemptThirteen" || a.ActionAttemptThirteen != nil { + return visitor.VisitActionAttemptThirteen(a.ActionAttemptThirteen) + } + if a.typ == "ActionAttemptFourteen" || a.ActionAttemptFourteen != nil { + return visitor.VisitActionAttemptFourteen(a.ActionAttemptFourteen) + } + if a.typ == "ActionAttemptFifteen" || a.ActionAttemptFifteen != nil { + return visitor.VisitActionAttemptFifteen(a.ActionAttemptFifteen) + } + if a.typ == "ActionAttemptSixteen" || a.ActionAttemptSixteen != nil { + return visitor.VisitActionAttemptSixteen(a.ActionAttemptSixteen) + } + if a.typ == "ActionAttemptSeventeen" || a.ActionAttemptSeventeen != nil { + return visitor.VisitActionAttemptSeventeen(a.ActionAttemptSeventeen) + } + if a.typ == "ActionAttemptEighteen" || a.ActionAttemptEighteen != nil { + return visitor.VisitActionAttemptEighteen(a.ActionAttemptEighteen) + } + if a.typ == "ActionAttemptNineteen" || a.ActionAttemptNineteen != nil { + return visitor.VisitActionAttemptNineteen(a.ActionAttemptNineteen) + } + if a.typ == "ActionAttemptTwenty" || a.ActionAttemptTwenty != nil { + return visitor.VisitActionAttemptTwenty(a.ActionAttemptTwenty) + } + if a.typ == "ActionAttemptTwentyOne" || a.ActionAttemptTwentyOne != nil { + return visitor.VisitActionAttemptTwentyOne(a.ActionAttemptTwentyOne) + } + if a.typ == "ActionAttemptTwentyTwo" || a.ActionAttemptTwentyTwo != nil { + return visitor.VisitActionAttemptTwentyTwo(a.ActionAttemptTwentyTwo) + } + if a.typ == "ActionAttemptTwentyThree" || a.ActionAttemptTwentyThree != nil { + return visitor.VisitActionAttemptTwentyThree(a.ActionAttemptTwentyThree) + } + if a.typ == "ActionAttemptTwentyFour" || a.ActionAttemptTwentyFour != nil { + return visitor.VisitActionAttemptTwentyFour(a.ActionAttemptTwentyFour) + } + if a.typ == "ActionAttemptTwentyFive" || a.ActionAttemptTwentyFive != nil { + return visitor.VisitActionAttemptTwentyFive(a.ActionAttemptTwentyFive) + } + if a.typ == "ActionAttemptTwentySix" || a.ActionAttemptTwentySix != nil { + return visitor.VisitActionAttemptTwentySix(a.ActionAttemptTwentySix) + } + if a.typ == "ActionAttemptTwentySeven" || a.ActionAttemptTwentySeven != nil { + return visitor.VisitActionAttemptTwentySeven(a.ActionAttemptTwentySeven) + } + if a.typ == "ActionAttemptTwentyEight" || a.ActionAttemptTwentyEight != nil { + return visitor.VisitActionAttemptTwentyEight(a.ActionAttemptTwentyEight) + } + if a.typ == "ActionAttemptTwentyNine" || a.ActionAttemptTwentyNine != nil { + return visitor.VisitActionAttemptTwentyNine(a.ActionAttemptTwentyNine) + } + if a.typ == "ActionAttemptThirty" || a.ActionAttemptThirty != nil { + return visitor.VisitActionAttemptThirty(a.ActionAttemptThirty) + } + if a.typ == "ActionAttemptThirtyOne" || a.ActionAttemptThirtyOne != nil { + return visitor.VisitActionAttemptThirtyOne(a.ActionAttemptThirtyOne) + } + if a.typ == "ActionAttemptThirtyTwo" || a.ActionAttemptThirtyTwo != nil { + return visitor.VisitActionAttemptThirtyTwo(a.ActionAttemptThirtyTwo) + } + if a.typ == "ActionAttemptThirtyThree" || a.ActionAttemptThirtyThree != nil { + return visitor.VisitActionAttemptThirtyThree(a.ActionAttemptThirtyThree) + } + if a.typ == "ActionAttemptThirtyFour" || a.ActionAttemptThirtyFour != nil { + return visitor.VisitActionAttemptThirtyFour(a.ActionAttemptThirtyFour) + } + if a.typ == "ActionAttemptThirtyFive" || a.ActionAttemptThirtyFive != nil { + return visitor.VisitActionAttemptThirtyFive(a.ActionAttemptThirtyFive) + } + if a.typ == "ActionAttemptThirtySix" || a.ActionAttemptThirtySix != nil { + return visitor.VisitActionAttemptThirtySix(a.ActionAttemptThirtySix) + } + if a.typ == "ActionAttemptThirtySeven" || a.ActionAttemptThirtySeven != nil { + return visitor.VisitActionAttemptThirtySeven(a.ActionAttemptThirtySeven) + } + if a.typ == "ActionAttemptThirtyEight" || a.ActionAttemptThirtyEight != nil { + return visitor.VisitActionAttemptThirtyEight(a.ActionAttemptThirtyEight) + } + if a.typ == "ActionAttemptThirtyNine" || a.ActionAttemptThirtyNine != nil { + return visitor.VisitActionAttemptThirtyNine(a.ActionAttemptThirtyNine) + } + if a.typ == "ActionAttemptForty" || a.ActionAttemptForty != nil { + return visitor.VisitActionAttemptForty(a.ActionAttemptForty) + } + if a.typ == "ActionAttemptFortyOne" || a.ActionAttemptFortyOne != nil { + return visitor.VisitActionAttemptFortyOne(a.ActionAttemptFortyOne) + } + if a.typ == "ActionAttemptFortyTwo" || a.ActionAttemptFortyTwo != nil { + return visitor.VisitActionAttemptFortyTwo(a.ActionAttemptFortyTwo) + } + if a.typ == "ActionAttemptFortyThree" || a.ActionAttemptFortyThree != nil { + return visitor.VisitActionAttemptFortyThree(a.ActionAttemptFortyThree) + } + if a.typ == "ActionAttemptActionAttemptId" || a.ActionAttemptActionAttemptId != nil { + return visitor.VisitActionAttemptActionAttemptId(a.ActionAttemptActionAttemptId) + } + return fmt.Errorf("type %T does not include a non-empty union type", a) +} + +type ActionAttemptActionAttemptId struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptActionAttemptIdError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptActionAttemptId) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptActionAttemptId) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptActionAttemptId) GetError() *ActionAttemptActionAttemptIdError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptActionAttemptId) Status() string { + return a.status +} + +func (a *ActionAttemptActionAttemptId) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptActionAttemptId) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptActionAttemptId) UnmarshalJSON(data []byte) error { + type embed ActionAttemptActionAttemptId + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptActionAttemptId(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UPDATE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UPDATE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptActionAttemptId) MarshalJSON() ([]byte, error) { + type embed ActionAttemptActionAttemptId + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "UPDATE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptActionAttemptId) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptActionAttemptIdError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptActionAttemptIdError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptActionAttemptIdError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptActionAttemptIdError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptActionAttemptIdError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptActionAttemptIdError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptActionAttemptIdError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptActionAttemptIdError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Resetting sandbox workspace failed. +type ActionAttemptEight struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptEightError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptEight) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptEight) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptEight) GetError() *ActionAttemptEightError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptEight) Status() string { + return a.status +} + +func (a *ActionAttemptEight) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptEight) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptEight) UnmarshalJSON(data []byte) error { + type embed ActionAttemptEight + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptEight(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "RESET_SANDBOX_WORKSPACE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "RESET_SANDBOX_WORKSPACE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptEight) MarshalJSON() ([]byte, error) { + type embed ActionAttemptEight + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "RESET_SANDBOX_WORKSPACE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptEight) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptEightError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptEightError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptEightError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptEightError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptEightError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptEightError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptEightError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptEightError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting fan mode. +type ActionAttemptEighteen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptEighteen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptEighteen) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptEighteen) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptEighteen) Status() string { + return a.status +} + +func (a *ActionAttemptEighteen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptEighteen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptEighteen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptEighteen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptEighteen(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_FAN_MODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_FAN_MODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptEighteen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptEighteen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "SET_FAN_MODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptEighteen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to cool failed. +type ActionAttemptEleven struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptElevenError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptEleven) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptEleven) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptEleven) GetError() *ActionAttemptElevenError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptEleven) Status() string { + return a.status +} + +func (a *ActionAttemptEleven) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptEleven) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptEleven) UnmarshalJSON(data []byte) error { + type embed ActionAttemptEleven + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptEleven(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_COOL" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_COOL", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptEleven) MarshalJSON() ([]byte, error) { + type embed ActionAttemptEleven + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "SET_COOL", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptEleven) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptElevenError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptElevenError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptElevenError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptElevenError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptElevenError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptElevenError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptElevenError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptElevenError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to heat-cool mode. +type ActionAttemptFifteen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFifteen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFifteen) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFifteen) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFifteen) Status() string { + return a.status +} + +func (a *ActionAttemptFifteen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFifteen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFifteen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFifteen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFifteen(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_HEAT_COOL" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_HEAT_COOL", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFifteen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFifteen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "SET_HEAT_COOL", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFifteen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Unlocking door failed. +type ActionAttemptFive struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptFiveError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFive) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFive) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFive) GetError() *ActionAttemptFiveError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFive) Status() string { + return a.status +} + +func (a *ActionAttemptFive) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFive) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFive) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFive + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFive(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UNLOCK_DOOR" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UNLOCK_DOOR", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFive) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFive + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "UNLOCK_DOOR", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFive) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFiveError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFiveError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptFiveError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptFiveError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFiveError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptFiveError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptFiveError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFiveError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptForty struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptForty) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptForty) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptForty) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptForty) Status() string { + return a.status +} + +func (a *ActionAttemptForty) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptForty) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptForty) UnmarshalJSON(data []byte) error { + type embed ActionAttemptForty + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptForty(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "DELETE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "DELETE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptForty) MarshalJSON() ([]byte, error) { + type embed ActionAttemptForty + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "DELETE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptForty) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFortyOne struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptFortyOneError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFortyOne) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFortyOne) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFortyOne) GetError() *ActionAttemptFortyOneError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFortyOne) Status() string { + return a.status +} + +func (a *ActionAttemptFortyOne) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFortyOne) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFortyOne) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFortyOne + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFortyOne(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "DELETE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "DELETE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFortyOne) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFortyOne + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "DELETE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFortyOne) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFortyOneError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFortyOneError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptFortyOneError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptFortyOneError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFortyOneError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptFortyOneError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptFortyOneError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFortyOneError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFortyThree struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFortyThree) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFortyThree) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFortyThree) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFortyThree) Status() string { + return a.status +} + +func (a *ActionAttemptFortyThree) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFortyThree) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFortyThree) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFortyThree + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFortyThree(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UPDATE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UPDATE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFortyThree) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFortyThree + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "UPDATE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFortyThree) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFortyTwo struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFortyTwo) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFortyTwo) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFortyTwo) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFortyTwo) Status() string { + return a.status +} + +func (a *ActionAttemptFortyTwo) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFortyTwo) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFortyTwo) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFortyTwo + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFortyTwo(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UPDATE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UPDATE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFortyTwo) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFortyTwo + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "UPDATE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFortyTwo) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Unlocking door succeeded. +type ActionAttemptFour struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptFourResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFour) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFour) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFour) GetResult() *ActionAttemptFourResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFour) Status() string { + return a.status +} + +func (a *ActionAttemptFour) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFour) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFour) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFour + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFour(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UNLOCK_DOOR" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UNLOCK_DOOR", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFour) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFour + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "UNLOCK_DOOR", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFour) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFourResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFourResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFourResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptFourResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptFourResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFourResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to heat mode failed. +type ActionAttemptFourteen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptFourteenError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFourteen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptFourteen) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptFourteen) GetError() *ActionAttemptFourteenError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptFourteen) Status() string { + return a.status +} + +func (a *ActionAttemptFourteen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptFourteen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFourteen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptFourteen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptFourteen(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_HEAT" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_HEAT", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFourteen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptFourteen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "SET_HEAT", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptFourteen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptFourteenError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptFourteenError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptFourteenError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptFourteenError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptFourteenError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptFourteenError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptFourteenError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptFourteenError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to cool. +type ActionAttemptNine struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptNine) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptNine) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptNine) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptNine) Status() string { + return a.status +} + +func (a *ActionAttemptNine) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptNine) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptNine) UnmarshalJSON(data []byte) error { + type embed ActionAttemptNine + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptNine(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_COOL" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_COOL", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptNine) MarshalJSON() ([]byte, error) { + type embed ActionAttemptNine + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "SET_COOL", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptNine) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting fan mode succeeded. +type ActionAttemptNineteen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptNineteenResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptNineteen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptNineteen) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptNineteen) GetResult() *ActionAttemptNineteenResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptNineteen) Status() string { + return a.status +} + +func (a *ActionAttemptNineteen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptNineteen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptNineteen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptNineteen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptNineteen(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_FAN_MODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_FAN_MODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptNineteen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptNineteen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "SET_FAN_MODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptNineteen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptNineteenResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptNineteenResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptNineteenResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptNineteenResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptNineteenResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptNineteenResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Locking door succeeded. +type ActionAttemptOne struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptOneResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptOne) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptOne) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptOne) GetResult() *ActionAttemptOneResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptOne) Status() string { + return a.status +} + +func (a *ActionAttemptOne) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptOne) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptOne) UnmarshalJSON(data []byte) error { + type embed ActionAttemptOne + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptOne(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "LOCK_DOOR" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "LOCK_DOOR", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptOne) MarshalJSON() ([]byte, error) { + type embed ActionAttemptOne + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "LOCK_DOOR", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptOne) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptOneResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptOneResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptOneResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptOneResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptOneResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptOneResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Resetting sandbox workspace succeeded. +type ActionAttemptSeven struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptSevenResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSeven) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptSeven) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptSeven) GetResult() *ActionAttemptSevenResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptSeven) Status() string { + return a.status +} + +func (a *ActionAttemptSeven) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptSeven) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSeven) UnmarshalJSON(data []byte) error { + type embed ActionAttemptSeven + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptSeven(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "RESET_SANDBOX_WORKSPACE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "RESET_SANDBOX_WORKSPACE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSeven) MarshalJSON() ([]byte, error) { + type embed ActionAttemptSeven + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "RESET_SANDBOX_WORKSPACE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptSeven) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptSevenResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSevenResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSevenResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptSevenResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptSevenResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSevenResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting heat-cool mode failed. +type ActionAttemptSeventeen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptSeventeenError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSeventeen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptSeventeen) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptSeventeen) GetError() *ActionAttemptSeventeenError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptSeventeen) Status() string { + return a.status +} + +func (a *ActionAttemptSeventeen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptSeventeen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSeventeen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptSeventeen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptSeventeen(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_HEAT_COOL" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_HEAT_COOL", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSeventeen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptSeventeen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "SET_HEAT_COOL", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptSeventeen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptSeventeenError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSeventeenError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptSeventeenError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptSeventeenError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSeventeenError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptSeventeenError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptSeventeenError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSeventeenError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Resetting sandbox workspace. +type ActionAttemptSix struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSix) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptSix) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptSix) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptSix) Status() string { + return a.status +} + +func (a *ActionAttemptSix) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptSix) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSix) UnmarshalJSON(data []byte) error { + type embed ActionAttemptSix + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptSix(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "RESET_SANDBOX_WORKSPACE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "RESET_SANDBOX_WORKSPACE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSix) MarshalJSON() ([]byte, error) { + type embed ActionAttemptSix + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "RESET_SANDBOX_WORKSPACE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptSix) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to heat-cool mode succeeded. +type ActionAttemptSixteen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptSixteenResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSixteen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptSixteen) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptSixteen) GetResult() *ActionAttemptSixteenResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptSixteen) Status() string { + return a.status +} + +func (a *ActionAttemptSixteen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptSixteen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSixteen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptSixteen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptSixteen(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_HEAT_COOL" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_HEAT_COOL", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSixteen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptSixteen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "SET_HEAT_COOL", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptSixteen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptSixteenResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptSixteenResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptSixteenResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptSixteenResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptSixteenResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptSixteenResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to cool succeeded. +type ActionAttemptTen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptTenResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTen) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTen) GetResult() *ActionAttemptTenResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTen) Status() string { + return a.status +} + +func (a *ActionAttemptTen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTen(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_COOL" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_COOL", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "SET_COOL", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTenResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTenResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTenResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTenResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptTenResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTenResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to heat mode succeeded. +type ActionAttemptThirteen struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptThirteenResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirteen) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirteen) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirteen) GetResult() *ActionAttemptThirteenResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirteen) Status() string { + return a.status +} + +func (a *ActionAttemptThirteen) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirteen) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirteen) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirteen + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirteen(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_HEAT" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_HEAT", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirteen) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirteen + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "SET_HEAT", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirteen) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirteenResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirteenResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirteenResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptThirteenResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptThirteenResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirteenResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirty struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirty) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirty) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirty) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirty) Status() string { + return a.status +} + +func (a *ActionAttemptThirty) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirty) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirty) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirty + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirty(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "DELETE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "DELETE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirty) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirty + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "DELETE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirty) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyEight struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptThirtyEightError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyEight) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyEight) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyEight) GetError() *ActionAttemptThirtyEightError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyEight) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyEight) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyEight) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyEight) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyEight + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyEight(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "CREATE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "CREATE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyEight) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyEight + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "CREATE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyEight) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyEightError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyEightError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptThirtyEightError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptThirtyEightError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyEightError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptThirtyEightError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptThirtyEightError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyEightError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyFive struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptThirtyFiveError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyFive) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyFive) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyFive) GetError() *ActionAttemptThirtyFiveError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyFive) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyFive) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyFive) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyFive) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyFive + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyFive(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UPDATE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UPDATE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyFive) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyFive + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "UPDATE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyFive) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyFiveError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyFiveError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptThirtyFiveError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptThirtyFiveError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyFiveError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptThirtyFiveError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptThirtyFiveError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyFiveError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyFour struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyFour) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyFour) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyFour) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyFour) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyFour) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyFour) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyFour) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyFour + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyFour(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UPDATE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UPDATE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyFour) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyFour + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "UPDATE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyFour) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyNine struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyNine) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyNine) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyNine) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyNine) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyNine) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyNine) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyNine) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyNine + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyNine(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "DELETE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "DELETE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyNine) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyNine + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "DELETE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyNine) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyOne struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyOne) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyOne) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyOne) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyOne) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyOne) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyOne) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyOne) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyOne + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyOne(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "DELETE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "DELETE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyOne) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyOne + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "DELETE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyOne) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtySeven struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtySeven) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtySeven) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtySeven) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtySeven) Status() string { + return a.status +} + +func (a *ActionAttemptThirtySeven) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtySeven) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtySeven) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtySeven + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtySeven(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "CREATE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "CREATE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtySeven) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtySeven + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "CREATE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtySeven) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtySix struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtySix) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtySix) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtySix) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtySix) Status() string { + return a.status +} + +func (a *ActionAttemptThirtySix) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtySix) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtySix) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtySix + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtySix(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "CREATE_NOISE_THRESHOLD" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "CREATE_NOISE_THRESHOLD", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtySix) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtySix + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "CREATE_NOISE_THRESHOLD", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtySix) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyThree struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyThree) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyThree) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyThree) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyThree) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyThree) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyThree) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyThree) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyThree + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyThree(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UPDATE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UPDATE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyThree) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyThree + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "UPDATE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyThree) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyTwo struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptThirtyTwoError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyTwo) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThirtyTwo) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThirtyTwo) GetError() *ActionAttemptThirtyTwoError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThirtyTwo) Status() string { + return a.status +} + +func (a *ActionAttemptThirtyTwo) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThirtyTwo) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyTwo) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThirtyTwo + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThirtyTwo(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "DELETE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "DELETE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyTwo) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThirtyTwo + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "DELETE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThirtyTwo) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptThirtyTwoError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThirtyTwoError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptThirtyTwoError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptThirtyTwoError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThirtyTwoError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptThirtyTwoError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptThirtyTwoError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThirtyTwoError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Unlocking door. +type ActionAttemptThree struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptThree) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptThree) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptThree) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptThree) Status() string { + return a.status +} + +func (a *ActionAttemptThree) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptThree) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptThree) UnmarshalJSON(data []byte) error { + type embed ActionAttemptThree + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptThree(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "UNLOCK_DOOR" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "UNLOCK_DOOR", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptThree) MarshalJSON() ([]byte, error) { + type embed ActionAttemptThree + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "UNLOCK_DOOR", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptThree) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting HVAC to heat mode. +type ActionAttemptTwelve struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwelve) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwelve) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwelve) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwelve) Status() string { + return a.status +} + +func (a *ActionAttemptTwelve) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwelve) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwelve) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwelve + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwelve(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_HEAT" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_HEAT", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwelve) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwelve + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "SET_HEAT", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwelve) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Setting fan mode failed. +type ActionAttemptTwenty struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptTwentyError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwenty) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwenty) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwenty) GetError() *ActionAttemptTwentyError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwenty) Status() string { + return a.status +} + +func (a *ActionAttemptTwenty) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwenty) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwenty) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwenty + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwenty(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_FAN_MODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_FAN_MODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwenty) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwenty + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "SET_FAN_MODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwenty) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyEight struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyEight) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyEight) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyEight) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyEight) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyEight) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyEight) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyEight) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyEight + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyEight(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "CREATE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "CREATE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyEight) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyEight + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "CREATE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyEight) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptTwentyError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptTwentyError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTwentyError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptTwentyError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyFive struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyFive) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyFive) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyFive) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyFive) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyFive) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyFive) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyFive) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyFive + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyFive(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SYNC_ACCESS_CODES" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SYNC_ACCESS_CODES", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyFive) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyFive + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "SYNC_ACCESS_CODES", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyFive) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyFour struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyFour) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyFour) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyFour) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyFour) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyFour) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyFour) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyFour) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyFour + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyFour(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SYNC_ACCESS_CODES" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SYNC_ACCESS_CODES", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyFour) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyFour + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "SYNC_ACCESS_CODES", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyFour) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyNine struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptTwentyNineError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyNine) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyNine) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyNine) GetError() *ActionAttemptTwentyNineError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyNine) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyNine) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyNine) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyNine) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyNine + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyNine(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "CREATE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "CREATE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyNine) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyNine + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "CREATE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyNine) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyNineError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyNineError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptTwentyNineError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptTwentyNineError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyNineError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTwentyNineError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptTwentyNineError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyNineError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Turning HVAC off. +type ActionAttemptTwentyOne struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyOne) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyOne) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyOne) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyOne) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyOne) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyOne) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyOne) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyOne + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyOne(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_THERMOSTAT_OFF" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_THERMOSTAT_OFF", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyOne) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyOne + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "SET_THERMOSTAT_OFF", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyOne) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentySeven struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentySeven) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentySeven) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentySeven) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentySeven) Status() string { + return a.status +} + +func (a *ActionAttemptTwentySeven) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentySeven) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentySeven) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentySeven + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentySeven(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "CREATE_ACCESS_CODE" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "CREATE_ACCESS_CODE", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentySeven) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentySeven + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "pending", + ActionType: "CREATE_ACCESS_CODE", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentySeven) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentySix struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptTwentySixError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentySix) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentySix) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentySix) GetError() *ActionAttemptTwentySixError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentySix) Status() string { + return a.status +} + +func (a *ActionAttemptTwentySix) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentySix) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentySix) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentySix + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentySix(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SYNC_ACCESS_CODES" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SYNC_ACCESS_CODES", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentySix) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentySix + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "SYNC_ACCESS_CODES", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentySix) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentySixError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentySixError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptTwentySixError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptTwentySixError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentySixError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTwentySixError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptTwentySixError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentySixError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Turning HVAC off failed. +type ActionAttemptTwentyThree struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptTwentyThreeError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyThree) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyThree) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyThree) GetError() *ActionAttemptTwentyThreeError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyThree) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyThree) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyThree) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyThree) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyThree + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyThree(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_THERMOSTAT_OFF" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_THERMOSTAT_OFF", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyThree) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyThree + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "SET_THERMOSTAT_OFF", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyThree) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyThreeError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyThreeError) GetType() string { + if a == nil { + return "" + } + return a.Type +} + +func (a *ActionAttemptTwentyThreeError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} + +func (a *ActionAttemptTwentyThreeError) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyThreeError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTwentyThreeError + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptTwentyThreeError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyThreeError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Turning HVAC off succeeded. +type ActionAttemptTwentyTwo struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + Result *ActionAttemptTwentyTwoResult `json:"result,omitempty" url:"result,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyTwo) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwentyTwo) GetError() interface{} { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwentyTwo) GetResult() *ActionAttemptTwentyTwoResult { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwentyTwo) Status() string { + return a.status +} + +func (a *ActionAttemptTwentyTwo) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwentyTwo) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyTwo) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwentyTwo + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwentyTwo(unmarshaler.embed) + if unmarshaler.Status != "success" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "success", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "SET_THERMOSTAT_OFF" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "SET_THERMOSTAT_OFF", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyTwo) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwentyTwo + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "success", + ActionType: "SET_THERMOSTAT_OFF", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwentyTwo) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwentyTwoResult struct { + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwentyTwoResult) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwentyTwoResult) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTwentyTwoResult + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *a = ActionAttemptTwentyTwoResult(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwentyTwoResult) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +// Locking door failed. +type ActionAttemptTwo struct { + // The ID of the action attempt. + ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` + Result interface{} `json:"result,omitempty" url:"result,omitempty"` + Error *ActionAttemptTwoError `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwo) GetActionAttemptId() string { + if a == nil { + return "" + } + return a.ActionAttemptId +} + +func (a *ActionAttemptTwo) GetResult() interface{} { + if a == nil { + return nil + } + return a.Result +} + +func (a *ActionAttemptTwo) GetError() *ActionAttemptTwoError { + if a == nil { + return nil + } + return a.Error +} + +func (a *ActionAttemptTwo) Status() string { + return a.status +} + +func (a *ActionAttemptTwo) ActionType() string { + return a.actionType +} + +func (a *ActionAttemptTwo) GetExtraProperties() map[string]interface{} { + return a.extraProperties +} + +func (a *ActionAttemptTwo) UnmarshalJSON(data []byte) error { + type embed ActionAttemptTwo + var unmarshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *a = ActionAttemptTwo(unmarshaler.embed) + if unmarshaler.Status != "error" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "error", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "LOCK_DOOR" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "LOCK_DOOR", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) + return nil +} + +func (a *ActionAttemptTwo) MarshalJSON() ([]byte, error) { + type embed ActionAttemptTwo + var marshaler = struct { + embed + Status string `json:"status"` + ActionType string `json:"action_type"` + }{ + embed: embed(*a), + Status: "error", + ActionType: "LOCK_DOOR", + } + return json.Marshal(marshaler) +} + +func (a *ActionAttemptTwo) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(a); err == nil { + return value + } + return fmt.Sprintf("%#v", a) +} + +type ActionAttemptTwoError struct { + Type string `json:"type" url:"type"` + Message string `json:"message" url:"message"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (a *ActionAttemptTwoError) GetType() string { + if a == nil { + return "" + } + return a.Type } -type ActionAttemptPending struct { - ActionType string `json:"action_type" url:"action_type"` - ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` - Result *string `json:"result,omitempty" url:"result,omitempty"` - Error *string `json:"error,omitempty" url:"error,omitempty"` +func (a *ActionAttemptTwoError) GetMessage() string { + if a == nil { + return "" + } + return a.Message +} - _rawJSON json.RawMessage +func (a *ActionAttemptTwoError) GetExtraProperties() map[string]interface{} { + return a.extraProperties } -func (a *ActionAttemptPending) UnmarshalJSON(data []byte) error { - type unmarshaler ActionAttemptPending +func (a *ActionAttemptTwoError) UnmarshalJSON(data []byte) error { + type unmarshaler ActionAttemptTwoError var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *a = ActionAttemptPending(value) - a._rawJSON = json.RawMessage(data) + *a = ActionAttemptTwoError(value) + extraProperties, err := internal.ExtractExtraProperties(data, *a) + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } -func (a *ActionAttemptPending) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { +func (a *ActionAttemptTwoError) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(a); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } return fmt.Sprintf("%#v", a) } -type ActionAttemptSuccess struct { - ActionType string `json:"action_type" url:"action_type"` +// Locking door. +type ActionAttemptZero struct { + // The ID of the action attempt. ActionAttemptId string `json:"action_attempt_id" url:"action_attempt_id"` Result interface{} `json:"result,omitempty" url:"result,omitempty"` - Error *string `json:"error,omitempty" url:"error,omitempty"` + Error interface{} `json:"error,omitempty" url:"error,omitempty"` + status string + actionType string - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (a *ActionAttemptSuccess) UnmarshalJSON(data []byte) error { - type unmarshaler ActionAttemptSuccess - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func (a *ActionAttemptZero) GetActionAttemptId() string { + if a == nil { + return "" } - *a = ActionAttemptSuccess(value) - a._rawJSON = json.RawMessage(data) - return nil + return a.ActionAttemptId } -func (a *ActionAttemptSuccess) String() string { - if len(a._rawJSON) > 0 { - if value, err := core.StringifyJSON(a._rawJSON); err == nil { - return value - } +func (a *ActionAttemptZero) GetResult() interface{} { + if a == nil { + return nil } - if value, err := core.StringifyJSON(a); err == nil { - return value + return a.Result +} + +func (a *ActionAttemptZero) GetError() interface{} { + if a == nil { + return nil } - return fmt.Sprintf("%#v", a) + return a.Error } -type ClientSession struct { - ClientSessionId string `json:"client_session_id" url:"client_session_id"` - UserIdentifierKey *string `json:"user_identifier_key,omitempty" url:"user_identifier_key,omitempty"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - Token string `json:"token" url:"token"` - DeviceCount float64 `json:"device_count" url:"device_count"` - ConnectedAccountIds []string `json:"connected_account_ids,omitempty" url:"connected_account_ids,omitempty"` - ConnectWebviewIds []string `json:"connect_webview_ids,omitempty" url:"connect_webview_ids,omitempty"` - UserIdentityIds []string `json:"user_identity_ids,omitempty" url:"user_identity_ids,omitempty"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` +func (a *ActionAttemptZero) Status() string { + return a.status +} + +func (a *ActionAttemptZero) ActionType() string { + return a.actionType +} - _rawJSON json.RawMessage +func (a *ActionAttemptZero) GetExtraProperties() map[string]interface{} { + return a.extraProperties } -func (c *ClientSession) UnmarshalJSON(data []byte) error { - type embed ClientSession +func (a *ActionAttemptZero) UnmarshalJSON(data []byte) error { + type embed ActionAttemptZero var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + Status string `json:"status"` + ActionType string `json:"action_type"` }{ - embed: embed(*c), + embed: embed(*a), } if err := json.Unmarshal(data, &unmarshaler); err != nil { return err } - *c = ClientSession(unmarshaler.embed) - c.CreatedAt = unmarshaler.CreatedAt.Time() - c._rawJSON = json.RawMessage(data) + *a = ActionAttemptZero(unmarshaler.embed) + if unmarshaler.Status != "pending" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "pending", unmarshaler.Status) + } + a.status = unmarshaler.Status + if unmarshaler.ActionType != "LOCK_DOOR" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", a, "LOCK_DOOR", unmarshaler.ActionType) + } + a.actionType = unmarshaler.ActionType + extraProperties, err := internal.ExtractExtraProperties(data, *a, "status", "action_type") + if err != nil { + return err + } + a.extraProperties = extraProperties + a.rawJSON = json.RawMessage(data) return nil } -func (c *ClientSession) MarshalJSON() ([]byte, error) { - type embed ClientSession +func (a *ActionAttemptZero) MarshalJSON() ([]byte, error) { + type embed ActionAttemptZero var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + Status string `json:"status"` + ActionType string `json:"action_type"` }{ - embed: embed(*c), - CreatedAt: core.NewDateTime(c.CreatedAt), + embed: embed(*a), + Status: "pending", + ActionType: "LOCK_DOOR", } return json.Marshal(marshaler) } -func (c *ClientSession) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { +func (a *ActionAttemptZero) String() string { + if len(a.rawJSON) > 0 { + if value, err := internal.StringifyJSON(a.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(a); err == nil { return value } - return fmt.Sprintf("%#v", c) + return fmt.Sprintf("%#v", a) } type ClimateSettingSchedule struct { @@ -1454,18 +9006,129 @@ type ClimateSettingSchedule struct { ManualOverrideAllowed *bool `json:"manual_override_allowed,omitempty" url:"manual_override_allowed,omitempty"` scheduleType string - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (c *ClimateSettingSchedule) GetClimateSettingScheduleId() string { + if c == nil { + return "" + } + return c.ClimateSettingScheduleId +} + +func (c *ClimateSettingSchedule) GetDeviceId() string { + if c == nil { + return "" + } + return c.DeviceId +} + +func (c *ClimateSettingSchedule) GetName() *string { + if c == nil { + return nil + } + return c.Name +} + +func (c *ClimateSettingSchedule) GetScheduleStartsAt() string { + if c == nil { + return "" + } + return c.ScheduleStartsAt +} + +func (c *ClimateSettingSchedule) GetScheduleEndsAt() string { + if c == nil { + return "" + } + return c.ScheduleEndsAt +} + +func (c *ClimateSettingSchedule) GetCreatedAt() time.Time { + if c == nil { + return time.Time{} + } + return c.CreatedAt +} + +func (c *ClimateSettingSchedule) GetErrors() interface{} { + if c == nil { + return nil + } + return c.Errors +} + +func (c *ClimateSettingSchedule) GetAutomaticHeatingEnabled() *bool { + if c == nil { + return nil + } + return c.AutomaticHeatingEnabled +} + +func (c *ClimateSettingSchedule) GetAutomaticCoolingEnabled() *bool { + if c == nil { + return nil + } + return c.AutomaticCoolingEnabled +} + +func (c *ClimateSettingSchedule) GetHvacModeSetting() *ClimateSettingScheduleHvacModeSetting { + if c == nil { + return nil + } + return c.HvacModeSetting +} + +func (c *ClimateSettingSchedule) GetCoolingSetPointCelsius() *float64 { + if c == nil { + return nil + } + return c.CoolingSetPointCelsius +} + +func (c *ClimateSettingSchedule) GetHeatingSetPointCelsius() *float64 { + if c == nil { + return nil + } + return c.HeatingSetPointCelsius +} + +func (c *ClimateSettingSchedule) GetCoolingSetPointFahrenheit() *float64 { + if c == nil { + return nil + } + return c.CoolingSetPointFahrenheit +} + +func (c *ClimateSettingSchedule) GetHeatingSetPointFahrenheit() *float64 { + if c == nil { + return nil + } + return c.HeatingSetPointFahrenheit +} + +func (c *ClimateSettingSchedule) GetManualOverrideAllowed() *bool { + if c == nil { + return nil + } + return c.ManualOverrideAllowed } func (c *ClimateSettingSchedule) ScheduleType() string { return c.scheduleType } +func (c *ClimateSettingSchedule) GetExtraProperties() map[string]interface{} { + return c.extraProperties +} + func (c *ClimateSettingSchedule) UnmarshalJSON(data []byte) error { type embed ClimateSettingSchedule var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` + ScheduleType string `json:"schedule_type"` }{ embed: embed(*c), } @@ -1474,8 +9137,16 @@ func (c *ClimateSettingSchedule) UnmarshalJSON(data []byte) error { } *c = ClimateSettingSchedule(unmarshaler.embed) c.CreatedAt = unmarshaler.CreatedAt.Time() - c.scheduleType = "time_bound" - c._rawJSON = json.RawMessage(data) + if unmarshaler.ScheduleType != "time_bound" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", c, "time_bound", unmarshaler.ScheduleType) + } + c.scheduleType = unmarshaler.ScheduleType + extraProperties, err := internal.ExtractExtraProperties(data, *c, "schedule_type") + if err != nil { + return err + } + c.extraProperties = extraProperties + c.rawJSON = json.RawMessage(data) return nil } @@ -1483,23 +9154,23 @@ func (c *ClimateSettingSchedule) MarshalJSON() ([]byte, error) { type embed ClimateSettingSchedule var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` - ScheduleType string `json:"schedule_type"` + CreatedAt *internal.DateTime `json:"created_at"` + ScheduleType string `json:"schedule_type"` }{ embed: embed(*c), - CreatedAt: core.NewDateTime(c.CreatedAt), + CreatedAt: internal.NewDateTime(c.CreatedAt), ScheduleType: "time_bound", } return json.Marshal(marshaler) } func (c *ClimateSettingSchedule) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { + if len(c.rawJSON) > 0 { + if value, err := internal.StringifyJSON(c.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(c); err == nil { return value } return fmt.Sprintf("%#v", c) @@ -1533,350 +9204,202 @@ func (c ClimateSettingScheduleHvacModeSetting) Ptr() *ClimateSettingScheduleHvac return &c } -type ConnectWebview struct { - ConnectWebviewId string `json:"connect_webview_id" url:"connect_webview_id"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - Url string `json:"url" url:"url"` - DeviceSelectionMode SelectionMode `json:"device_selection_mode,omitempty" url:"device_selection_mode,omitempty"` - AcceptedProviders []string `json:"accepted_providers,omitempty" url:"accepted_providers,omitempty"` - // --- - // deprecated: Unused. Will be removed. - // --- - AcceptedDevices []string `json:"accepted_devices,omitempty" url:"accepted_devices,omitempty"` - // --- - // deprecated: Unused. Will be removed. - // --- - AnyDeviceAllowed bool `json:"any_device_allowed" url:"any_device_allowed"` - AnyProviderAllowed bool `json:"any_provider_allowed" url:"any_provider_allowed"` - LoginSuccessful bool `json:"login_successful" url:"login_successful"` - Status ConnectWebviewStatus `json:"status,omitempty" url:"status,omitempty"` - CustomRedirectUrl *string `json:"custom_redirect_url,omitempty" url:"custom_redirect_url,omitempty"` - CustomRedirectFailureUrl *string `json:"custom_redirect_failure_url,omitempty" url:"custom_redirect_failure_url,omitempty"` - CustomMetadata map[string]*ConnectWebviewCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` - AutomaticallyManageNewDevices bool `json:"automatically_manage_new_devices" url:"automatically_manage_new_devices"` - WaitForDeviceCreation bool `json:"wait_for_device_creation" url:"wait_for_device_creation"` - AuthorizedAt *time.Time `json:"authorized_at,omitempty" url:"authorized_at,omitempty"` - SelectedProvider *string `json:"selected_provider,omitempty" url:"selected_provider,omitempty"` - - _rawJSON json.RawMessage -} - -func (c *ConnectWebview) UnmarshalJSON(data []byte) error { - type embed ConnectWebview - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - AuthorizedAt *core.DateTime `json:"authorized_at,omitempty"` - }{ - embed: embed(*c), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err - } - *c = ConnectWebview(unmarshaler.embed) - c.CreatedAt = unmarshaler.CreatedAt.Time() - c.AuthorizedAt = unmarshaler.AuthorizedAt.TimePtr() - c._rawJSON = json.RawMessage(data) - return nil -} +type Device struct { + // Unique identifier for the device. + DeviceId string `json:"device_id" url:"device_id"` + // Type of the device. + DeviceType DeviceType `json:"device_type" url:"device_type"` + // Optional nickname to describe the device, settable through Seam + Nickname *string `json:"nickname,omitempty" url:"nickname,omitempty"` + // Display name of the device, defaults to nickname (if it is set) or properties.appearance.name otherwise. Enables administrators and users to identify the device easily, especially when there are numerous devices. + DisplayName string `json:"display_name" url:"display_name"` + // Collection of capabilities that the device supports when connected to Seam. Values are "access_code," which indicates that the device can manage and utilize digital PIN codes for secure access; "lock," which indicates that the device controls a door locking mechanism, enabling the remote opening and closing of doors and other entry points; "noise_detection," which indicates that the device supports monitoring and responding to ambient noise levels; "thermostat," which indicates that the device can regulate and adjust indoor temperatures; and "battery," which indicates that the device can manage battery life and health. + CapabilitiesSupported []DeviceCapabilitiesSupportedItem `json:"capabilities_supported,omitempty" url:"capabilities_supported,omitempty"` + // Properties of the device. + Properties *DeviceProperties `json:"properties,omitempty" url:"properties,omitempty"` + // Location information for the device. + Location *DeviceLocation `json:"location,omitempty" url:"location,omitempty"` + // Unique identifier for the account associated with the device. + ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` + // Unique identifier for the Seam workspace associated with the device. + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + // Array of errors associated with the device. Each error object within the array contains two fields: "error_code" and "message." "error_code" is a string that uniquely identifies the type of error, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the error, offering insights into the issue and potentially how to rectify it. + Errors []*DeviceErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` + // Array of warnings associated with the device. Each warning object within the array contains two fields: "warning_code" and "message." "warning_code" is a string that uniquely identifies the type of warning, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the warning, offering insights into the issue and potentially how to rectify it. + Warnings []*DeviceWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` + // Date and time at which the device object was created. + CreatedAt time.Time `json:"created_at" url:"created_at"` + // Indicates whether Seam manages the device. + IsManaged bool `json:"is_managed" url:"is_managed"` + CustomMetadata map[string]*DeviceCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` + CanRemotelyUnlock *bool `json:"can_remotely_unlock,omitempty" url:"can_remotely_unlock,omitempty"` + CanRemotelyLock *bool `json:"can_remotely_lock,omitempty" url:"can_remotely_lock,omitempty"` + CanProgramOfflineAccessCodes *bool `json:"can_program_offline_access_codes,omitempty" url:"can_program_offline_access_codes,omitempty"` + CanProgramOnlineAccessCodes *bool `json:"can_program_online_access_codes,omitempty" url:"can_program_online_access_codes,omitempty"` + CanSimulateRemoval *bool `json:"can_simulate_removal,omitempty" url:"can_simulate_removal,omitempty"` + CanSimulateConnection *bool `json:"can_simulate_connection,omitempty" url:"can_simulate_connection,omitempty"` + CanSimulateDisconnection *bool `json:"can_simulate_disconnection,omitempty" url:"can_simulate_disconnection,omitempty"` -func (c *ConnectWebview) MarshalJSON() ([]byte, error) { - type embed ConnectWebview - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - AuthorizedAt *core.DateTime `json:"authorized_at,omitempty"` - }{ - embed: embed(*c), - CreatedAt: core.NewDateTime(c.CreatedAt), - AuthorizedAt: core.NewOptionalDateTime(c.AuthorizedAt), - } - return json.Marshal(marshaler) + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (c *ConnectWebview) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(c); err == nil { - return value +func (d *Device) GetDeviceId() string { + if d == nil { + return "" } - return fmt.Sprintf("%#v", c) -} - -type ConnectWebviewCustomMetadataValue struct { - typeName string - String string - Boolean bool + return d.DeviceId } -func NewConnectWebviewCustomMetadataValueFromString(value string) *ConnectWebviewCustomMetadataValue { - return &ConnectWebviewCustomMetadataValue{typeName: "string", String: value} -} - -func NewConnectWebviewCustomMetadataValueFromBoolean(value bool) *ConnectWebviewCustomMetadataValue { - return &ConnectWebviewCustomMetadataValue{typeName: "boolean", Boolean: value} +func (d *Device) GetDeviceType() DeviceType { + if d == nil { + return "" + } + return d.DeviceType } -func (c *ConnectWebviewCustomMetadataValue) UnmarshalJSON(data []byte) error { - var valueString string - if err := json.Unmarshal(data, &valueString); err == nil { - c.typeName = "string" - c.String = valueString - return nil - } - var valueBoolean bool - if err := json.Unmarshal(data, &valueBoolean); err == nil { - c.typeName = "boolean" - c.Boolean = valueBoolean +func (d *Device) GetNickname() *string { + if d == nil { return nil } - return fmt.Errorf("%s cannot be deserialized as a %T", data, c) + return d.Nickname } -func (c ConnectWebviewCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": - return json.Marshal(c.String) - case "boolean": - return json.Marshal(c.Boolean) +func (d *Device) GetDisplayName() string { + if d == nil { + return "" } + return d.DisplayName } -type ConnectWebviewCustomMetadataValueVisitor interface { - VisitString(string) error - VisitBoolean(bool) error -} - -func (c *ConnectWebviewCustomMetadataValue) Accept(visitor ConnectWebviewCustomMetadataValueVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": - return visitor.VisitString(c.String) - case "boolean": - return visitor.VisitBoolean(c.Boolean) +func (d *Device) GetCapabilitiesSupported() []DeviceCapabilitiesSupportedItem { + if d == nil { + return nil } + return d.CapabilitiesSupported } -type ConnectWebviewStatus string - -const ( - ConnectWebviewStatusPending ConnectWebviewStatus = "pending" - ConnectWebviewStatusFailed ConnectWebviewStatus = "failed" - ConnectWebviewStatusAuthorized ConnectWebviewStatus = "authorized" -) - -func NewConnectWebviewStatusFromString(s string) (ConnectWebviewStatus, error) { - switch s { - case "pending": - return ConnectWebviewStatusPending, nil - case "failed": - return ConnectWebviewStatusFailed, nil - case "authorized": - return ConnectWebviewStatusAuthorized, nil - } - var t ConnectWebviewStatus - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (c ConnectWebviewStatus) Ptr() *ConnectWebviewStatus { - return &c -} - -type ConnectedAccount struct { - ConnectedAccountId *string `json:"connected_account_id,omitempty" url:"connected_account_id,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty" url:"created_at,omitempty"` - UserIdentifier *ConnectedAccountUserIdentifier `json:"user_identifier,omitempty" url:"user_identifier,omitempty"` - AccountType *string `json:"account_type,omitempty" url:"account_type,omitempty"` - AccountTypeDisplayName string `json:"account_type_display_name" url:"account_type_display_name"` - Errors interface{} `json:"errors,omitempty" url:"errors,omitempty"` - Warnings interface{} `json:"warnings,omitempty" url:"warnings,omitempty"` - CustomMetadata map[string]*ConnectedAccountCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` - AutomaticallyManageNewDevices bool `json:"automatically_manage_new_devices" url:"automatically_manage_new_devices"` - - _rawJSON json.RawMessage -} - -func (c *ConnectedAccount) UnmarshalJSON(data []byte) error { - type embed ConnectedAccount - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at,omitempty"` - }{ - embed: embed(*c), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err +func (d *Device) GetProperties() *DeviceProperties { + if d == nil { + return nil } - *c = ConnectedAccount(unmarshaler.embed) - c.CreatedAt = unmarshaler.CreatedAt.TimePtr() - c._rawJSON = json.RawMessage(data) - return nil + return d.Properties } -func (c *ConnectedAccount) MarshalJSON() ([]byte, error) { - type embed ConnectedAccount - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at,omitempty"` - }{ - embed: embed(*c), - CreatedAt: core.NewOptionalDateTime(c.CreatedAt), +func (d *Device) GetLocation() *DeviceLocation { + if d == nil { + return nil } - return json.Marshal(marshaler) + return d.Location } -func (c *ConnectedAccount) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(c); err == nil { - return value +func (d *Device) GetConnectedAccountId() string { + if d == nil { + return "" } - return fmt.Sprintf("%#v", c) -} - -type ConnectedAccountCustomMetadataValue struct { - typeName string - String string - Boolean bool -} - -func NewConnectedAccountCustomMetadataValueFromString(value string) *ConnectedAccountCustomMetadataValue { - return &ConnectedAccountCustomMetadataValue{typeName: "string", String: value} + return d.ConnectedAccountId } -func NewConnectedAccountCustomMetadataValueFromBoolean(value bool) *ConnectedAccountCustomMetadataValue { - return &ConnectedAccountCustomMetadataValue{typeName: "boolean", Boolean: value} +func (d *Device) GetWorkspaceId() string { + if d == nil { + return "" + } + return d.WorkspaceId } -func (c *ConnectedAccountCustomMetadataValue) UnmarshalJSON(data []byte) error { - var valueString string - if err := json.Unmarshal(data, &valueString); err == nil { - c.typeName = "string" - c.String = valueString +func (d *Device) GetErrors() []*DeviceErrorsItem { + if d == nil { return nil } - var valueBoolean bool - if err := json.Unmarshal(data, &valueBoolean); err == nil { - c.typeName = "boolean" - c.Boolean = valueBoolean - return nil - } - return fmt.Errorf("%s cannot be deserialized as a %T", data, c) + return d.Errors } -func (c ConnectedAccountCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch c.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": - return json.Marshal(c.String) - case "boolean": - return json.Marshal(c.Boolean) +func (d *Device) GetWarnings() []*DeviceWarningsItem { + if d == nil { + return nil } + return d.Warnings } -type ConnectedAccountCustomMetadataValueVisitor interface { - VisitString(string) error - VisitBoolean(bool) error -} - -func (c *ConnectedAccountCustomMetadataValue) Accept(visitor ConnectedAccountCustomMetadataValueVisitor) error { - switch c.typeName { - default: - return fmt.Errorf("invalid type %s in %T", c.typeName, c) - case "string": - return visitor.VisitString(c.String) - case "boolean": - return visitor.VisitBoolean(c.Boolean) +func (d *Device) GetCreatedAt() time.Time { + if d == nil { + return time.Time{} } + return d.CreatedAt } -type ConnectedAccountUserIdentifier struct { - Username *string `json:"username,omitempty" url:"username,omitempty"` - ApiUrl *string `json:"api_url,omitempty" url:"api_url,omitempty"` - Email *string `json:"email,omitempty" url:"email,omitempty"` - Phone *string `json:"phone,omitempty" url:"phone,omitempty"` - Exclusive *bool `json:"exclusive,omitempty" url:"exclusive,omitempty"` - - _rawJSON json.RawMessage +func (d *Device) GetIsManaged() bool { + if d == nil { + return false + } + return d.IsManaged } -func (c *ConnectedAccountUserIdentifier) UnmarshalJSON(data []byte) error { - type unmarshaler ConnectedAccountUserIdentifier - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func (d *Device) GetCustomMetadata() map[string]*DeviceCustomMetadataValue { + if d == nil { + return nil } - *c = ConnectedAccountUserIdentifier(value) - c._rawJSON = json.RawMessage(data) - return nil + return d.CustomMetadata } -func (c *ConnectedAccountUserIdentifier) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(c); err == nil { - return value +func (d *Device) GetCanRemotelyUnlock() *bool { + if d == nil { + return nil } - return fmt.Sprintf("%#v", c) + return d.CanRemotelyUnlock } -type Device struct { - // Unique identifier for the device. - DeviceId string `json:"device_id" url:"device_id"` - // Type of the device. - DeviceType DeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` - // Optional nickname to describe the device, settable through Seam - Nickname *string `json:"nickname,omitempty" url:"nickname,omitempty"` - // Display name of the device, defaults to nickname (if it is set) or properties.appearance.name otherwise. Enables administrators and users to identify the device easily, especially when there are numerous devices. - DisplayName string `json:"display_name" url:"display_name"` - // Collection of capabilities that the device supports when connected to Seam. Values are "access_code," which indicates that the device can manage and utilize digital PIN codes for secure access; "lock," which indicates that the device controls a door locking mechanism, enabling the remote opening and closing of doors and other entry points; "noise_detection," which indicates that the device supports monitoring and responding to ambient noise levels; "thermostat," which indicates that the device can regulate and adjust indoor temperatures; and "battery," which indicates that the device can manage battery life and health. - CapabilitiesSupported []DeviceCapabilitiesSupportedItem `json:"capabilities_supported,omitempty" url:"capabilities_supported,omitempty"` - // Properties of the device. - Properties *DeviceProperties `json:"properties,omitempty" url:"properties,omitempty"` - // Location information for the device. - Location *DeviceLocation `json:"location,omitempty" url:"location,omitempty"` - // Unique identifier for the account associated with the device. - ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` - // Unique identifier for the Seam workspace associated with the device. - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - // Array of errors associated with the device. Each error object within the array contains two fields: "error_code" and "message." "error_code" is a string that uniquely identifies the type of error, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the error, offering insights into the issue and potentially how to rectify it. - Errors []*DeviceErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` - // Array of warnings associated with the device. Each warning object within the array contains two fields: "warning_code" and "message." "warning_code" is a string that uniquely identifies the type of warning, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the warning, offering insights into the issue and potentially how to rectify it. - Warnings []*DeviceWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` - // Date and time at which the device object was created. - CreatedAt time.Time `json:"created_at" url:"created_at"` - // Indicates whether Seam manages the device. - IsManaged bool `json:"is_managed" url:"is_managed"` - CustomMetadata map[string]*DeviceCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` - CanRemotelyUnlock *bool `json:"can_remotely_unlock,omitempty" url:"can_remotely_unlock,omitempty"` - CanRemotelyLock *bool `json:"can_remotely_lock,omitempty" url:"can_remotely_lock,omitempty"` - CanProgramOfflineAccessCodes *bool `json:"can_program_offline_access_codes,omitempty" url:"can_program_offline_access_codes,omitempty"` - CanProgramOnlineAccessCodes *bool `json:"can_program_online_access_codes,omitempty" url:"can_program_online_access_codes,omitempty"` - CanSimulateRemoval *bool `json:"can_simulate_removal,omitempty" url:"can_simulate_removal,omitempty"` +func (d *Device) GetCanRemotelyLock() *bool { + if d == nil { + return nil + } + return d.CanRemotelyLock +} + +func (d *Device) GetCanProgramOfflineAccessCodes() *bool { + if d == nil { + return nil + } + return d.CanProgramOfflineAccessCodes +} + +func (d *Device) GetCanProgramOnlineAccessCodes() *bool { + if d == nil { + return nil + } + return d.CanProgramOnlineAccessCodes +} + +func (d *Device) GetCanSimulateRemoval() *bool { + if d == nil { + return nil + } + return d.CanSimulateRemoval +} + +func (d *Device) GetCanSimulateConnection() *bool { + if d == nil { + return nil + } + return d.CanSimulateConnection +} + +func (d *Device) GetCanSimulateDisconnection() *bool { + if d == nil { + return nil + } + return d.CanSimulateDisconnection +} - _rawJSON json.RawMessage +func (d *Device) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *Device) UnmarshalJSON(data []byte) error { type embed Device var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*d), } @@ -1885,7 +9408,12 @@ func (d *Device) UnmarshalJSON(data []byte) error { } *d = Device(unmarshaler.embed) d.CreatedAt = unmarshaler.CreatedAt.Time() - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } @@ -1893,21 +9421,21 @@ func (d *Device) MarshalJSON() ([]byte, error) { type embed Device var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*d), - CreatedAt: core.NewDateTime(d.CreatedAt), + CreatedAt: internal.NewDateTime(d.CreatedAt), } return json.Marshal(marshaler) } func (d *Device) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -1948,29 +9476,44 @@ func (d DeviceCapabilitiesSupportedItem) Ptr() *DeviceCapabilitiesSupportedItem } type DeviceCustomMetadataValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewDeviceCustomMetadataValueFromString(value string) *DeviceCustomMetadataValue { - return &DeviceCustomMetadataValue{typeName: "string", String: value} + return &DeviceCustomMetadataValue{typ: "String", String: value} } func NewDeviceCustomMetadataValueFromBoolean(value bool) *DeviceCustomMetadataValue { - return &DeviceCustomMetadataValue{typeName: "boolean", Boolean: value} + return &DeviceCustomMetadataValue{typ: "Boolean", Boolean: value} +} + +func (d *DeviceCustomMetadataValue) GetString() string { + if d == nil { + return "" + } + return d.String +} + +func (d *DeviceCustomMetadataValue) GetBoolean() bool { + if d == nil { + return false + } + return d.Boolean } func (d *DeviceCustomMetadataValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - d.typeName = "string" + d.typ = "String" d.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - d.typeName = "boolean" + d.typ = "Boolean" d.Boolean = valueBoolean return nil } @@ -1978,14 +9521,13 @@ func (d *DeviceCustomMetadataValue) UnmarshalJSON(data []byte) error { } func (d DeviceCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch d.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "string": + if d.typ == "String" || d.String != "" { return json.Marshal(d.String) - case "boolean": + } + if d.typ == "Boolean" || d.Boolean != false { return json.Marshal(d.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", d) } type DeviceCustomMetadataValueVisitor interface { @@ -1994,21 +9536,39 @@ type DeviceCustomMetadataValueVisitor interface { } func (d *DeviceCustomMetadataValue) Accept(visitor DeviceCustomMetadataValueVisitor) error { - switch d.typeName { - default: - return fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "string": + if d.typ == "String" || d.String != "" { return visitor.VisitString(d.String) - case "boolean": + } + if d.typ == "Boolean" || d.Boolean != false { return visitor.VisitBoolean(d.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", d) } type DeviceErrorsItem struct { ErrorCode string `json:"error_code" url:"error_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DeviceErrorsItem) GetErrorCode() string { + if d == nil { + return "" + } + return d.ErrorCode +} + +func (d *DeviceErrorsItem) GetMessage() string { + if d == nil { + return "" + } + return d.Message +} + +func (d *DeviceErrorsItem) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DeviceErrorsItem) UnmarshalJSON(data []byte) error { @@ -2018,17 +9578,22 @@ func (d *DeviceErrorsItem) UnmarshalJSON(data []byte) error { return err } *d = DeviceErrorsItem(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DeviceErrorsItem) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2041,7 +9606,26 @@ type DeviceLocation struct { // Time zone of the device location. Timezone *string `json:"timezone,omitempty" url:"timezone,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DeviceLocation) GetLocationName() *string { + if d == nil { + return nil + } + return d.LocationName +} + +func (d *DeviceLocation) GetTimezone() *string { + if d == nil { + return nil + } + return d.Timezone +} + +func (d *DeviceLocation) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DeviceLocation) UnmarshalJSON(data []byte) error { @@ -2051,17 +9635,22 @@ func (d *DeviceLocation) UnmarshalJSON(data []byte) error { return err } *d = DeviceLocation(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DeviceLocation) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2071,9 +9660,6 @@ func (d *DeviceLocation) String() string { type DeviceProperties struct { // Indicates whether the device is online. Online bool `json:"online" url:"online"` - // --- - // deprecated: use device.display_name instead - // --- // Name of the device. Name string `json:"name" url:"name"` // Represents the accessory keypad state. @@ -2097,15 +9683,13 @@ type DeviceProperties struct { // Indicates whether it is currently possible to use online access codes for the device. OnlineAccessCodesEnabled *bool `json:"online_access_codes_enabled,omitempty" url:"online_access_codes_enabled,omitempty"` // Indicates whether it is currently possible to use offline access codes for the device. - OfflineAccessCodesEnabled *bool `json:"offline_access_codes_enabled,omitempty" url:"offline_access_codes_enabled,omitempty"` - // --- - // deprecated: use model.accessory_keypad_supported - // --- - SupportsAccessoryKeypad *bool `json:"supports_accessory_keypad,omitempty" url:"supports_accessory_keypad,omitempty"` - // --- - // deprecated: use offline_access_codes_enabled - // --- - SupportsOfflineAccessCodes *bool `json:"supports_offline_access_codes,omitempty" url:"supports_offline_access_codes,omitempty"` + OfflineAccessCodesEnabled *bool `json:"offline_access_codes_enabled,omitempty" url:"offline_access_codes_enabled,omitempty"` + SupportsAccessoryKeypad *bool `json:"supports_accessory_keypad,omitempty" url:"supports_accessory_keypad,omitempty"` + SupportsOfflineAccessCodes *bool `json:"supports_offline_access_codes,omitempty" url:"supports_offline_access_codes,omitempty"` + // Indicates current noise level in decibels, if the device supports noise detection. + NoiseLevelDecibels *float64 `json:"noise_level_decibels,omitempty" url:"noise_level_decibels,omitempty"` + // Array of noise threshold IDs that are currently triggering. + CurrentlyTriggeringNoiseThresholdIds []string `json:"currently_triggering_noise_threshold_ids,omitempty" url:"currently_triggering_noise_threshold_ids,omitempty"` AssaAbloyCredentialServiceMetadata *DevicePropertiesAssaAbloyCredentialServiceMetadata `json:"assa_abloy_credential_service_metadata,omitempty" url:"assa_abloy_credential_service_metadata,omitempty"` AugustMetadata *DevicePropertiesAugustMetadata `json:"august_metadata,omitempty" url:"august_metadata,omitempty"` AvigilonAltaMetadata *DevicePropertiesAvigilonAltaMetadata `json:"avigilon_alta_metadata,omitempty" url:"avigilon_alta_metadata,omitempty"` @@ -2143,7 +9727,390 @@ type DeviceProperties struct { KeypadBattery *DevicePropertiesKeypadBattery `json:"keypad_battery,omitempty" url:"keypad_battery,omitempty"` DoorOpen *bool `json:"door_open,omitempty" url:"door_open,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DeviceProperties) GetOnline() bool { + if d == nil { + return false + } + return d.Online +} + +func (d *DeviceProperties) GetName() string { + if d == nil { + return "" + } + return d.Name +} + +func (d *DeviceProperties) GetAccessoryKeypad() *DevicePropertiesAccessoryKeypad { + if d == nil { + return nil + } + return d.AccessoryKeypad +} + +func (d *DeviceProperties) GetAppearance() *DevicePropertiesAppearance { + if d == nil { + return nil + } + return d.Appearance +} + +func (d *DeviceProperties) GetModel() *DevicePropertiesModel { + if d == nil { + return nil + } + return d.Model +} + +func (d *DeviceProperties) GetHasDirectPower() *bool { + if d == nil { + return nil + } + return d.HasDirectPower +} + +func (d *DeviceProperties) GetBatteryLevel() *float64 { + if d == nil { + return nil + } + return d.BatteryLevel +} + +func (d *DeviceProperties) GetBattery() *DevicePropertiesBattery { + if d == nil { + return nil + } + return d.Battery +} + +func (d *DeviceProperties) GetManufacturer() *string { + if d == nil { + return nil + } + return d.Manufacturer +} + +func (d *DeviceProperties) GetImageUrl() *string { + if d == nil { + return nil + } + return d.ImageUrl +} + +func (d *DeviceProperties) GetImageAltText() *string { + if d == nil { + return nil + } + return d.ImageAltText +} + +func (d *DeviceProperties) GetSerialNumber() *string { + if d == nil { + return nil + } + return d.SerialNumber +} + +func (d *DeviceProperties) GetOnlineAccessCodesEnabled() *bool { + if d == nil { + return nil + } + return d.OnlineAccessCodesEnabled +} + +func (d *DeviceProperties) GetOfflineAccessCodesEnabled() *bool { + if d == nil { + return nil + } + return d.OfflineAccessCodesEnabled +} + +func (d *DeviceProperties) GetSupportsAccessoryKeypad() *bool { + if d == nil { + return nil + } + return d.SupportsAccessoryKeypad +} + +func (d *DeviceProperties) GetSupportsOfflineAccessCodes() *bool { + if d == nil { + return nil + } + return d.SupportsOfflineAccessCodes +} + +func (d *DeviceProperties) GetNoiseLevelDecibels() *float64 { + if d == nil { + return nil + } + return d.NoiseLevelDecibels +} + +func (d *DeviceProperties) GetCurrentlyTriggeringNoiseThresholdIds() []string { + if d == nil { + return nil + } + return d.CurrentlyTriggeringNoiseThresholdIds +} + +func (d *DeviceProperties) GetAssaAbloyCredentialServiceMetadata() *DevicePropertiesAssaAbloyCredentialServiceMetadata { + if d == nil { + return nil + } + return d.AssaAbloyCredentialServiceMetadata +} + +func (d *DeviceProperties) GetAugustMetadata() *DevicePropertiesAugustMetadata { + if d == nil { + return nil + } + return d.AugustMetadata +} + +func (d *DeviceProperties) GetAvigilonAltaMetadata() *DevicePropertiesAvigilonAltaMetadata { + if d == nil { + return nil + } + return d.AvigilonAltaMetadata +} + +func (d *DeviceProperties) GetSchlageMetadata() *DevicePropertiesSchlageMetadata { + if d == nil { + return nil + } + return d.SchlageMetadata +} + +func (d *DeviceProperties) GetSmartthingsMetadata() *DevicePropertiesSmartthingsMetadata { + if d == nil { + return nil + } + return d.SmartthingsMetadata +} + +func (d *DeviceProperties) GetLocklyMetadata() *DevicePropertiesLocklyMetadata { + if d == nil { + return nil + } + return d.LocklyMetadata +} + +func (d *DeviceProperties) GetNukiMetadata() *DevicePropertiesNukiMetadata { + if d == nil { + return nil + } + return d.NukiMetadata +} + +func (d *DeviceProperties) GetKwiksetMetadata() *DevicePropertiesKwiksetMetadata { + if d == nil { + return nil + } + return d.KwiksetMetadata +} + +func (d *DeviceProperties) GetSaltoMetadata() *DevicePropertiesSaltoMetadata { + if d == nil { + return nil + } + return d.SaltoMetadata +} + +func (d *DeviceProperties) GetGenieMetadata() *DevicePropertiesGenieMetadata { + if d == nil { + return nil + } + return d.GenieMetadata +} + +func (d *DeviceProperties) GetBrivoMetadata() *DevicePropertiesBrivoMetadata { + if d == nil { + return nil + } + return d.BrivoMetadata +} + +func (d *DeviceProperties) GetIglooMetadata() *DevicePropertiesIglooMetadata { + if d == nil { + return nil + } + return d.IglooMetadata +} + +func (d *DeviceProperties) GetNoiseawareMetadata() *DevicePropertiesNoiseawareMetadata { + if d == nil { + return nil + } + return d.NoiseawareMetadata +} + +func (d *DeviceProperties) GetMinutMetadata() *DevicePropertiesMinutMetadata { + if d == nil { + return nil + } + return d.MinutMetadata +} + +func (d *DeviceProperties) GetFourSuitesMetadata() *DevicePropertiesFourSuitesMetadata { + if d == nil { + return nil + } + return d.FourSuitesMetadata +} + +func (d *DeviceProperties) GetTwoNMetadata() *DevicePropertiesTwoNMetadata { + if d == nil { + return nil + } + return d.TwoNMetadata +} + +func (d *DeviceProperties) GetControlbywebMetadata() *DevicePropertiesControlbywebMetadata { + if d == nil { + return nil + } + return d.ControlbywebMetadata +} + +func (d *DeviceProperties) GetTtlockMetadata() *DevicePropertiesTtlockMetadata { + if d == nil { + return nil + } + return d.TtlockMetadata +} + +func (d *DeviceProperties) GetSeamBridgeMetadata() *DevicePropertiesSeamBridgeMetadata { + if d == nil { + return nil + } + return d.SeamBridgeMetadata +} + +func (d *DeviceProperties) GetIgloohomeMetadata() *DevicePropertiesIgloohomeMetadata { + if d == nil { + return nil + } + return d.IgloohomeMetadata +} + +func (d *DeviceProperties) GetNestMetadata() *DevicePropertiesNestMetadata { + if d == nil { + return nil + } + return d.NestMetadata +} + +func (d *DeviceProperties) GetEcobeeMetadata() *DevicePropertiesEcobeeMetadata { + if d == nil { + return nil + } + return d.EcobeeMetadata +} + +func (d *DeviceProperties) GetHoneywellResideoMetadata() *DevicePropertiesHoneywellResideoMetadata { + if d == nil { + return nil + } + return d.HoneywellResideoMetadata +} + +func (d *DeviceProperties) GetHubitatMetadata() *DevicePropertiesHubitatMetadata { + if d == nil { + return nil + } + return d.HubitatMetadata +} + +func (d *DeviceProperties) GetDormakabaOracodeMetadata() *DevicePropertiesDormakabaOracodeMetadata { + if d == nil { + return nil + } + return d.DormakabaOracodeMetadata +} + +func (d *DeviceProperties) GetWyzeMetadata() *DevicePropertiesWyzeMetadata { + if d == nil { + return nil + } + return d.WyzeMetadata +} + +func (d *DeviceProperties) GetTedeeMetadata() *DevicePropertiesTedeeMetadata { + if d == nil { + return nil + } + return d.TedeeMetadata +} + +func (d *DeviceProperties) GetExperimentalSupportedCodeFromAccessCodesLengths() []float64 { + if d == nil { + return nil + } + return d.ExperimentalSupportedCodeFromAccessCodesLengths +} + +func (d *DeviceProperties) GetCodeConstraints() []*DevicePropertiesCodeConstraintsItem { + if d == nil { + return nil + } + return d.CodeConstraints +} + +func (d *DeviceProperties) GetSupportedCodeLengths() []float64 { + if d == nil { + return nil + } + return d.SupportedCodeLengths +} + +func (d *DeviceProperties) GetMaxActiveCodesSupported() *float64 { + if d == nil { + return nil + } + return d.MaxActiveCodesSupported +} + +func (d *DeviceProperties) GetSupportsBackupAccessCodePool() *bool { + if d == nil { + return nil + } + return d.SupportsBackupAccessCodePool +} + +func (d *DeviceProperties) GetHasNativeEntryEvents() *bool { + if d == nil { + return nil + } + return d.HasNativeEntryEvents +} + +func (d *DeviceProperties) GetLocked() *bool { + if d == nil { + return nil + } + return d.Locked +} + +func (d *DeviceProperties) GetKeypadBattery() *DevicePropertiesKeypadBattery { + if d == nil { + return nil + } + return d.KeypadBattery +} + +func (d *DeviceProperties) GetDoorOpen() *bool { + if d == nil { + return nil + } + return d.DoorOpen +} + +func (d *DeviceProperties) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DeviceProperties) UnmarshalJSON(data []byte) error { @@ -2153,17 +10120,22 @@ func (d *DeviceProperties) UnmarshalJSON(data []byte) error { return err } *d = DeviceProperties(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DeviceProperties) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2176,7 +10148,26 @@ type DevicePropertiesAccessoryKeypad struct { // Indicates if the keypad battery properties. Battery *DevicePropertiesAccessoryKeypadBattery `json:"battery,omitempty" url:"battery,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAccessoryKeypad) GetIsConnected() bool { + if d == nil { + return false + } + return d.IsConnected +} + +func (d *DevicePropertiesAccessoryKeypad) GetBattery() *DevicePropertiesAccessoryKeypadBattery { + if d == nil { + return nil + } + return d.Battery +} + +func (d *DevicePropertiesAccessoryKeypad) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAccessoryKeypad) UnmarshalJSON(data []byte) error { @@ -2186,17 +10177,22 @@ func (d *DevicePropertiesAccessoryKeypad) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesAccessoryKeypad(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAccessoryKeypad) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2206,7 +10202,19 @@ func (d *DevicePropertiesAccessoryKeypad) String() string { type DevicePropertiesAccessoryKeypadBattery struct { Level float64 `json:"level" url:"level"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAccessoryKeypadBattery) GetLevel() float64 { + if d == nil { + return 0 + } + return d.Level +} + +func (d *DevicePropertiesAccessoryKeypadBattery) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAccessoryKeypadBattery) UnmarshalJSON(data []byte) error { @@ -2216,17 +10224,22 @@ func (d *DevicePropertiesAccessoryKeypadBattery) UnmarshalJSON(data []byte) erro return err } *d = DevicePropertiesAccessoryKeypadBattery(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAccessoryKeypadBattery) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2236,7 +10249,19 @@ type DevicePropertiesAppearance struct { // Name of the device as seen from the provider API and application, not settable through Seam. Name string `json:"name" url:"name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAppearance) GetName() string { + if d == nil { + return "" + } + return d.Name +} + +func (d *DevicePropertiesAppearance) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAppearance) UnmarshalJSON(data []byte) error { @@ -2246,17 +10271,22 @@ func (d *DevicePropertiesAppearance) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesAppearance(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAppearance) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2266,7 +10296,26 @@ type DevicePropertiesAssaAbloyCredentialServiceMetadata struct { HasActiveEndpoint bool `json:"has_active_endpoint" url:"has_active_endpoint"` Endpoints []*DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem `json:"endpoints,omitempty" url:"endpoints,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAssaAbloyCredentialServiceMetadata) GetHasActiveEndpoint() bool { + if d == nil { + return false + } + return d.HasActiveEndpoint +} + +func (d *DevicePropertiesAssaAbloyCredentialServiceMetadata) GetEndpoints() []*DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem { + if d == nil { + return nil + } + return d.Endpoints +} + +func (d *DevicePropertiesAssaAbloyCredentialServiceMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAssaAbloyCredentialServiceMetadata) UnmarshalJSON(data []byte) error { @@ -2276,17 +10325,22 @@ func (d *DevicePropertiesAssaAbloyCredentialServiceMetadata) UnmarshalJSON(data return err } *d = DevicePropertiesAssaAbloyCredentialServiceMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAssaAbloyCredentialServiceMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2296,7 +10350,26 @@ type DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem struct { EndpointId string `json:"endpoint_id" url:"endpoint_id"` IsActive bool `json:"is_active" url:"is_active"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) GetEndpointId() string { + if d == nil { + return "" + } + return d.EndpointId +} + +func (d *DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) GetIsActive() bool { + if d == nil { + return false + } + return d.IsActive +} + +func (d *DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) UnmarshalJSON(data []byte) error { @@ -2306,17 +10379,22 @@ func (d *DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) Unmars return err } *d = DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2331,7 +10409,61 @@ type DevicePropertiesAugustMetadata struct { Model *string `json:"model,omitempty" url:"model,omitempty"` HouseId *string `json:"house_id,omitempty" url:"house_id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAugustMetadata) GetLockId() string { + if d == nil { + return "" + } + return d.LockId +} + +func (d *DevicePropertiesAugustMetadata) GetLockName() string { + if d == nil { + return "" + } + return d.LockName +} + +func (d *DevicePropertiesAugustMetadata) GetHouseName() string { + if d == nil { + return "" + } + return d.HouseName +} + +func (d *DevicePropertiesAugustMetadata) GetHasKeypad() bool { + if d == nil { + return false + } + return d.HasKeypad +} + +func (d *DevicePropertiesAugustMetadata) GetKeypadBatteryLevel() *string { + if d == nil { + return nil + } + return d.KeypadBatteryLevel +} + +func (d *DevicePropertiesAugustMetadata) GetModel() *string { + if d == nil { + return nil + } + return d.Model +} + +func (d *DevicePropertiesAugustMetadata) GetHouseId() *string { + if d == nil { + return nil + } + return d.HouseId +} + +func (d *DevicePropertiesAugustMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAugustMetadata) UnmarshalJSON(data []byte) error { @@ -2341,17 +10473,22 @@ func (d *DevicePropertiesAugustMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesAugustMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAugustMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2366,7 +10503,61 @@ type DevicePropertiesAvigilonAltaMetadata struct { SiteName string `json:"site_name" url:"site_name"` EntryRelaysTotalCount float64 `json:"entry_relays_total_count" url:"entry_relays_total_count"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetEntryName() string { + if d == nil { + return "" + } + return d.EntryName +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetOrgName() string { + if d == nil { + return "" + } + return d.OrgName +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetZoneId() float64 { + if d == nil { + return 0 + } + return d.ZoneId +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetZoneName() string { + if d == nil { + return "" + } + return d.ZoneName +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetSiteId() float64 { + if d == nil { + return 0 + } + return d.SiteId +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetSiteName() string { + if d == nil { + return "" + } + return d.SiteName +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetEntryRelaysTotalCount() float64 { + if d == nil { + return 0 + } + return d.EntryRelaysTotalCount +} + +func (d *DevicePropertiesAvigilonAltaMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesAvigilonAltaMetadata) UnmarshalJSON(data []byte) error { @@ -2376,17 +10567,22 @@ func (d *DevicePropertiesAvigilonAltaMetadata) UnmarshalJSON(data []byte) error return err } *d = DevicePropertiesAvigilonAltaMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesAvigilonAltaMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2395,9 +10591,28 @@ func (d *DevicePropertiesAvigilonAltaMetadata) String() string { // Represents the current status of the battery charge level. Values are "critical," which indicates an extremely low level, suggesting imminent shutdown or an urgent need for charging; "low," which signifies that the battery is under the preferred threshold and should be charged soon; "good," which denotes a satisfactory charge level, adequate for normal use without the immediate need for recharging; and "full," which represents a battery that is fully charged, providing the maximum duration of usage. type DevicePropertiesBattery struct { Level float64 `json:"level" url:"level"` - Status DevicePropertiesBatteryStatus `json:"status,omitempty" url:"status,omitempty"` + Status DevicePropertiesBatteryStatus `json:"status" url:"status"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesBattery) GetLevel() float64 { + if d == nil { + return 0 + } + return d.Level +} - _rawJSON json.RawMessage +func (d *DevicePropertiesBattery) GetStatus() DevicePropertiesBatteryStatus { + if d == nil { + return "" + } + return d.Status +} + +func (d *DevicePropertiesBattery) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesBattery) UnmarshalJSON(data []byte) error { @@ -2407,17 +10622,22 @@ func (d *DevicePropertiesBattery) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesBattery(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesBattery) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2454,7 +10674,19 @@ func (d DevicePropertiesBatteryStatus) Ptr() *DevicePropertiesBatteryStatus { type DevicePropertiesBrivoMetadata struct { DeviceName string `json:"device_name" url:"device_name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesBrivoMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesBrivoMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesBrivoMetadata) UnmarshalJSON(data []byte) error { @@ -2464,46 +10696,66 @@ func (d *DevicePropertiesBrivoMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesBrivoMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesBrivoMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) } type DevicePropertiesCodeConstraintsItem struct { - typeName string DevicePropertiesCodeConstraintsItemZero *DevicePropertiesCodeConstraintsItemZero DevicePropertiesCodeConstraintsItemMaxLength *DevicePropertiesCodeConstraintsItemMaxLength + + typ string } func NewDevicePropertiesCodeConstraintsItemFromDevicePropertiesCodeConstraintsItemZero(value *DevicePropertiesCodeConstraintsItemZero) *DevicePropertiesCodeConstraintsItem { - return &DevicePropertiesCodeConstraintsItem{typeName: "devicePropertiesCodeConstraintsItemZero", DevicePropertiesCodeConstraintsItemZero: value} + return &DevicePropertiesCodeConstraintsItem{typ: "DevicePropertiesCodeConstraintsItemZero", DevicePropertiesCodeConstraintsItemZero: value} } func NewDevicePropertiesCodeConstraintsItemFromDevicePropertiesCodeConstraintsItemMaxLength(value *DevicePropertiesCodeConstraintsItemMaxLength) *DevicePropertiesCodeConstraintsItem { - return &DevicePropertiesCodeConstraintsItem{typeName: "devicePropertiesCodeConstraintsItemMaxLength", DevicePropertiesCodeConstraintsItemMaxLength: value} + return &DevicePropertiesCodeConstraintsItem{typ: "DevicePropertiesCodeConstraintsItemMaxLength", DevicePropertiesCodeConstraintsItemMaxLength: value} +} + +func (d *DevicePropertiesCodeConstraintsItem) GetDevicePropertiesCodeConstraintsItemZero() *DevicePropertiesCodeConstraintsItemZero { + if d == nil { + return nil + } + return d.DevicePropertiesCodeConstraintsItemZero +} + +func (d *DevicePropertiesCodeConstraintsItem) GetDevicePropertiesCodeConstraintsItemMaxLength() *DevicePropertiesCodeConstraintsItemMaxLength { + if d == nil { + return nil + } + return d.DevicePropertiesCodeConstraintsItemMaxLength } func (d *DevicePropertiesCodeConstraintsItem) UnmarshalJSON(data []byte) error { valueDevicePropertiesCodeConstraintsItemZero := new(DevicePropertiesCodeConstraintsItemZero) if err := json.Unmarshal(data, &valueDevicePropertiesCodeConstraintsItemZero); err == nil { - d.typeName = "devicePropertiesCodeConstraintsItemZero" + d.typ = "DevicePropertiesCodeConstraintsItemZero" d.DevicePropertiesCodeConstraintsItemZero = valueDevicePropertiesCodeConstraintsItemZero return nil } valueDevicePropertiesCodeConstraintsItemMaxLength := new(DevicePropertiesCodeConstraintsItemMaxLength) if err := json.Unmarshal(data, &valueDevicePropertiesCodeConstraintsItemMaxLength); err == nil { - d.typeName = "devicePropertiesCodeConstraintsItemMaxLength" + d.typ = "DevicePropertiesCodeConstraintsItemMaxLength" d.DevicePropertiesCodeConstraintsItemMaxLength = valueDevicePropertiesCodeConstraintsItemMaxLength return nil } @@ -2511,14 +10763,13 @@ func (d *DevicePropertiesCodeConstraintsItem) UnmarshalJSON(data []byte) error { } func (d DevicePropertiesCodeConstraintsItem) MarshalJSON() ([]byte, error) { - switch d.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "devicePropertiesCodeConstraintsItemZero": + if d.typ == "DevicePropertiesCodeConstraintsItemZero" || d.DevicePropertiesCodeConstraintsItemZero != nil { return json.Marshal(d.DevicePropertiesCodeConstraintsItemZero) - case "devicePropertiesCodeConstraintsItemMaxLength": + } + if d.typ == "DevicePropertiesCodeConstraintsItemMaxLength" || d.DevicePropertiesCodeConstraintsItemMaxLength != nil { return json.Marshal(d.DevicePropertiesCodeConstraintsItemMaxLength) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", d) } type DevicePropertiesCodeConstraintsItemVisitor interface { @@ -2527,22 +10778,47 @@ type DevicePropertiesCodeConstraintsItemVisitor interface { } func (d *DevicePropertiesCodeConstraintsItem) Accept(visitor DevicePropertiesCodeConstraintsItemVisitor) error { - switch d.typeName { - default: - return fmt.Errorf("invalid type %s in %T", d.typeName, d) - case "devicePropertiesCodeConstraintsItemZero": + if d.typ == "DevicePropertiesCodeConstraintsItemZero" || d.DevicePropertiesCodeConstraintsItemZero != nil { return visitor.VisitDevicePropertiesCodeConstraintsItemZero(d.DevicePropertiesCodeConstraintsItemZero) - case "devicePropertiesCodeConstraintsItemMaxLength": + } + if d.typ == "DevicePropertiesCodeConstraintsItemMaxLength" || d.DevicePropertiesCodeConstraintsItemMaxLength != nil { return visitor.VisitDevicePropertiesCodeConstraintsItemMaxLength(d.DevicePropertiesCodeConstraintsItemMaxLength) } + return fmt.Errorf("type %T does not include a non-empty union type", d) } type DevicePropertiesCodeConstraintsItemMaxLength struct { - ConstraintType DevicePropertiesCodeConstraintsItemMaxLengthConstraintType `json:"constraint_type,omitempty" url:"constraint_type,omitempty"` + ConstraintType DevicePropertiesCodeConstraintsItemMaxLengthConstraintType `json:"constraint_type" url:"constraint_type"` MinLength *float64 `json:"min_length,omitempty" url:"min_length,omitempty"` MaxLength *float64 `json:"max_length,omitempty" url:"max_length,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesCodeConstraintsItemMaxLength) GetConstraintType() DevicePropertiesCodeConstraintsItemMaxLengthConstraintType { + if d == nil { + return "" + } + return d.ConstraintType +} + +func (d *DevicePropertiesCodeConstraintsItemMaxLength) GetMinLength() *float64 { + if d == nil { + return nil + } + return d.MinLength +} + +func (d *DevicePropertiesCodeConstraintsItemMaxLength) GetMaxLength() *float64 { + if d == nil { + return nil + } + return d.MaxLength +} + +func (d *DevicePropertiesCodeConstraintsItemMaxLength) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesCodeConstraintsItemMaxLength) UnmarshalJSON(data []byte) error { @@ -2552,17 +10828,22 @@ func (d *DevicePropertiesCodeConstraintsItemMaxLength) UnmarshalJSON(data []byte return err } *d = DevicePropertiesCodeConstraintsItemMaxLength(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesCodeConstraintsItemMaxLength) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2591,9 +10872,21 @@ func (d DevicePropertiesCodeConstraintsItemMaxLengthConstraintType) Ptr() *Devic } type DevicePropertiesCodeConstraintsItemZero struct { - ConstraintType DevicePropertiesCodeConstraintsItemZeroConstraintType `json:"constraint_type,omitempty" url:"constraint_type,omitempty"` + ConstraintType DevicePropertiesCodeConstraintsItemZeroConstraintType `json:"constraint_type" url:"constraint_type"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesCodeConstraintsItemZero) GetConstraintType() DevicePropertiesCodeConstraintsItemZeroConstraintType { + if d == nil { + return "" + } + return d.ConstraintType +} - _rawJSON json.RawMessage +func (d *DevicePropertiesCodeConstraintsItemZero) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesCodeConstraintsItemZero) UnmarshalJSON(data []byte) error { @@ -2603,17 +10896,22 @@ func (d *DevicePropertiesCodeConstraintsItemZero) UnmarshalJSON(data []byte) err return err } *d = DevicePropertiesCodeConstraintsItemZero(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesCodeConstraintsItemZero) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2667,7 +10965,33 @@ type DevicePropertiesControlbywebMetadata struct { DeviceName string `json:"device_name" url:"device_name"` RelayName *string `json:"relay_name,omitempty" url:"relay_name,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesControlbywebMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesControlbywebMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesControlbywebMetadata) GetRelayName() *string { + if d == nil { + return nil + } + return d.RelayName +} + +func (d *DevicePropertiesControlbywebMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesControlbywebMetadata) UnmarshalJSON(data []byte) error { @@ -2677,17 +11001,22 @@ func (d *DevicePropertiesControlbywebMetadata) UnmarshalJSON(data []byte) error return err } *d = DevicePropertiesControlbywebMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesControlbywebMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2703,7 +11032,68 @@ type DevicePropertiesDormakabaOracodeMetadata struct { IanaTimezone *string `json:"iana_timezone,omitempty" url:"iana_timezone,omitempty"` PredefinedTimeSlots []*DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem `json:"predefined_time_slots,omitempty" url:"predefined_time_slots,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetDoorId() float64 { + if d == nil { + return 0 + } + return d.DoorId +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetDoorName() string { + if d == nil { + return "" + } + return d.DoorName +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetDeviceId() *float64 { + if d == nil { + return nil + } + return d.DeviceId +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetDoorIsWireless() bool { + if d == nil { + return false + } + return d.DoorIsWireless +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetSiteId() float64 { + if d == nil { + return 0 + } + return d.SiteId +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetSiteName() string { + if d == nil { + return "" + } + return d.SiteName +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetIanaTimezone() *string { + if d == nil { + return nil + } + return d.IanaTimezone +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetPredefinedTimeSlots() []*DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem { + if d == nil { + return nil + } + return d.PredefinedTimeSlots +} + +func (d *DevicePropertiesDormakabaOracodeMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesDormakabaOracodeMetadata) UnmarshalJSON(data []byte) error { @@ -2713,35 +11103,115 @@ func (d *DevicePropertiesDormakabaOracodeMetadata) UnmarshalJSON(data []byte) er return err } *d = DevicePropertiesDormakabaOracodeMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesDormakabaOracodeMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { - return value + if value, err := internal.StringifyJSON(d); err == nil { + return value + } + return fmt.Sprintf("%#v", d) +} + +type DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem struct { + Name string `json:"name" url:"name"` + Prefix float64 `json:"prefix" url:"prefix"` + CheckInTime string `json:"check_in_time" url:"check_in_time"` + CheckOutTime string `json:"check_out_time" url:"check_out_time"` + Is24Hour bool `json:"is_24_hour" url:"is_24_hour"` + IsBiweeklyMode bool `json:"is_biweekly_mode" url:"is_biweekly_mode"` + IsOneShot bool `json:"is_one_shot" url:"is_one_shot"` + IsMaster bool `json:"is_master" url:"is_master"` + ExtDormakabaOracodeUserLevelPrefix float64 `json:"ext_dormakaba_oracode_user_level_prefix" url:"ext_dormakaba_oracode_user_level_prefix"` + DormakabaOracodeUserLevelId string `json:"dormakaba_oracode_user_level_id" url:"dormakaba_oracode_user_level_id"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetName() string { + if d == nil { + return "" + } + return d.Name +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetPrefix() float64 { + if d == nil { + return 0 + } + return d.Prefix +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetCheckInTime() string { + if d == nil { + return "" + } + return d.CheckInTime +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetCheckOutTime() string { + if d == nil { + return "" + } + return d.CheckOutTime +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetIs24Hour() bool { + if d == nil { + return false + } + return d.Is24Hour +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetIsBiweeklyMode() bool { + if d == nil { + return false + } + return d.IsBiweeklyMode +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetIsOneShot() bool { + if d == nil { + return false + } + return d.IsOneShot +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetIsMaster() bool { + if d == nil { + return false + } + return d.IsMaster +} + +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetExtDormakabaOracodeUserLevelPrefix() float64 { + if d == nil { + return 0 } - return fmt.Sprintf("%#v", d) + return d.ExtDormakabaOracodeUserLevelPrefix } -type DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem struct { - Name string `json:"name" url:"name"` - Prefix float64 `json:"prefix" url:"prefix"` - CheckInTime string `json:"check_in_time" url:"check_in_time"` - CheckOutTime string `json:"check_out_time" url:"check_out_time"` - Is24Hour bool `json:"is_24_hour" url:"is_24_hour"` - IsBiweeklyMode bool `json:"is_biweekly_mode" url:"is_biweekly_mode"` - IsOneShot bool `json:"is_one_shot" url:"is_one_shot"` - IsMaster bool `json:"is_master" url:"is_master"` - ExtDormakabaOracodeUserLevelPrefix float64 `json:"ext_dormakaba_oracode_user_level_prefix" url:"ext_dormakaba_oracode_user_level_prefix"` - DormakabaOracodeUserLevelId string `json:"dormakaba_oracode_user_level_id" url:"dormakaba_oracode_user_level_id"` +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetDormakabaOracodeUserLevelId() string { + if d == nil { + return "" + } + return d.DormakabaOracodeUserLevelId +} - _rawJSON json.RawMessage +func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) UnmarshalJSON(data []byte) error { @@ -2751,17 +11221,22 @@ func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) Unmars return err } *d = DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesDormakabaOracodeMetadataPredefinedTimeSlotsItem) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2771,7 +11246,26 @@ type DevicePropertiesEcobeeMetadata struct { EcobeeDeviceId string `json:"ecobee_device_id" url:"ecobee_device_id"` DeviceName string `json:"device_name" url:"device_name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesEcobeeMetadata) GetEcobeeDeviceId() string { + if d == nil { + return "" + } + return d.EcobeeDeviceId +} + +func (d *DevicePropertiesEcobeeMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesEcobeeMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesEcobeeMetadata) UnmarshalJSON(data []byte) error { @@ -2781,17 +11275,22 @@ func (d *DevicePropertiesEcobeeMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesEcobeeMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesEcobeeMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2802,7 +11301,33 @@ type DevicePropertiesFourSuitesMetadata struct { DeviceName string `json:"device_name" url:"device_name"` RecloseDelayInSeconds float64 `json:"reclose_delay_in_seconds" url:"reclose_delay_in_seconds"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesFourSuitesMetadata) GetDeviceId() float64 { + if d == nil { + return 0 + } + return d.DeviceId +} + +func (d *DevicePropertiesFourSuitesMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesFourSuitesMetadata) GetRecloseDelayInSeconds() float64 { + if d == nil { + return 0 + } + return d.RecloseDelayInSeconds +} + +func (d *DevicePropertiesFourSuitesMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesFourSuitesMetadata) UnmarshalJSON(data []byte) error { @@ -2812,17 +11337,22 @@ func (d *DevicePropertiesFourSuitesMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesFourSuitesMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesFourSuitesMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2832,7 +11362,26 @@ type DevicePropertiesGenieMetadata struct { DeviceName string `json:"device_name" url:"device_name"` DoorName string `json:"door_name" url:"door_name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesGenieMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesGenieMetadata) GetDoorName() string { + if d == nil { + return "" + } + return d.DoorName +} + +func (d *DevicePropertiesGenieMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesGenieMetadata) UnmarshalJSON(data []byte) error { @@ -2842,17 +11391,22 @@ func (d *DevicePropertiesGenieMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesGenieMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesGenieMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2862,7 +11416,26 @@ type DevicePropertiesHoneywellResideoMetadata struct { HoneywellResideoDeviceId string `json:"honeywell_resideo_device_id" url:"honeywell_resideo_device_id"` DeviceName string `json:"device_name" url:"device_name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesHoneywellResideoMetadata) GetHoneywellResideoDeviceId() string { + if d == nil { + return "" + } + return d.HoneywellResideoDeviceId +} + +func (d *DevicePropertiesHoneywellResideoMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesHoneywellResideoMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesHoneywellResideoMetadata) UnmarshalJSON(data []byte) error { @@ -2872,17 +11445,22 @@ func (d *DevicePropertiesHoneywellResideoMetadata) UnmarshalJSON(data []byte) er return err } *d = DevicePropertiesHoneywellResideoMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesHoneywellResideoMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2893,7 +11471,33 @@ type DevicePropertiesHubitatMetadata struct { DeviceName string `json:"device_name" url:"device_name"` DeviceLabel string `json:"device_label" url:"device_label"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesHubitatMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesHubitatMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesHubitatMetadata) GetDeviceLabel() string { + if d == nil { + return "" + } + return d.DeviceLabel +} + +func (d *DevicePropertiesHubitatMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesHubitatMetadata) UnmarshalJSON(data []byte) error { @@ -2903,17 +11507,22 @@ func (d *DevicePropertiesHubitatMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesHubitatMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesHubitatMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2924,7 +11533,33 @@ type DevicePropertiesIglooMetadata struct { BridgeId string `json:"bridge_id" url:"bridge_id"` Model *string `json:"model,omitempty" url:"model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesIglooMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesIglooMetadata) GetBridgeId() string { + if d == nil { + return "" + } + return d.BridgeId +} + +func (d *DevicePropertiesIglooMetadata) GetModel() *string { + if d == nil { + return nil + } + return d.Model +} + +func (d *DevicePropertiesIglooMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesIglooMetadata) UnmarshalJSON(data []byte) error { @@ -2934,17 +11569,22 @@ func (d *DevicePropertiesIglooMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesIglooMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesIglooMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2957,7 +11597,47 @@ type DevicePropertiesIgloohomeMetadata struct { BridgeName *string `json:"bridge_name,omitempty" url:"bridge_name,omitempty"` KeypadId *string `json:"keypad_id,omitempty" url:"keypad_id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesIgloohomeMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesIgloohomeMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesIgloohomeMetadata) GetBridgeId() *string { + if d == nil { + return nil + } + return d.BridgeId +} + +func (d *DevicePropertiesIgloohomeMetadata) GetBridgeName() *string { + if d == nil { + return nil + } + return d.BridgeName +} + +func (d *DevicePropertiesIgloohomeMetadata) GetKeypadId() *string { + if d == nil { + return nil + } + return d.KeypadId +} + +func (d *DevicePropertiesIgloohomeMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesIgloohomeMetadata) UnmarshalJSON(data []byte) error { @@ -2967,17 +11647,22 @@ func (d *DevicePropertiesIgloohomeMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesIgloohomeMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesIgloohomeMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -2986,7 +11671,19 @@ func (d *DevicePropertiesIgloohomeMetadata) String() string { type DevicePropertiesKeypadBattery struct { Level float64 `json:"level" url:"level"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesKeypadBattery) GetLevel() float64 { + if d == nil { + return 0 + } + return d.Level +} + +func (d *DevicePropertiesKeypadBattery) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesKeypadBattery) UnmarshalJSON(data []byte) error { @@ -2996,17 +11693,22 @@ func (d *DevicePropertiesKeypadBattery) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesKeypadBattery(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesKeypadBattery) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3017,7 +11719,33 @@ type DevicePropertiesKwiksetMetadata struct { DeviceName string `json:"device_name" url:"device_name"` ModelNumber string `json:"model_number" url:"model_number"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesKwiksetMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesKwiksetMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesKwiksetMetadata) GetModelNumber() string { + if d == nil { + return "" + } + return d.ModelNumber +} + +func (d *DevicePropertiesKwiksetMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesKwiksetMetadata) UnmarshalJSON(data []byte) error { @@ -3027,17 +11755,22 @@ func (d *DevicePropertiesKwiksetMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesKwiksetMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesKwiksetMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3048,7 +11781,33 @@ type DevicePropertiesLocklyMetadata struct { DeviceName string `json:"device_name" url:"device_name"` Model *string `json:"model,omitempty" url:"model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesLocklyMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesLocklyMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesLocklyMetadata) GetModel() *string { + if d == nil { + return nil + } + return d.Model +} + +func (d *DevicePropertiesLocklyMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesLocklyMetadata) UnmarshalJSON(data []byte) error { @@ -3058,17 +11817,22 @@ func (d *DevicePropertiesLocklyMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesLocklyMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesLocklyMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3079,7 +11843,33 @@ type DevicePropertiesMinutMetadata struct { DeviceName string `json:"device_name" url:"device_name"` LatestSensorValues *DevicePropertiesMinutMetadataLatestSensorValues `json:"latest_sensor_values,omitempty" url:"latest_sensor_values,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesMinutMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesMinutMetadata) GetLatestSensorValues() *DevicePropertiesMinutMetadataLatestSensorValues { + if d == nil { + return nil + } + return d.LatestSensorValues +} + +func (d *DevicePropertiesMinutMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadata) UnmarshalJSON(data []byte) error { @@ -3089,17 +11879,22 @@ func (d *DevicePropertiesMinutMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesMinutMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3112,7 +11907,47 @@ type DevicePropertiesMinutMetadataLatestSensorValues struct { Pressure *DevicePropertiesMinutMetadataLatestSensorValuesPressure `json:"pressure,omitempty" url:"pressure,omitempty"` AccelerometerZ *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ `json:"accelerometer_z,omitempty" url:"accelerometer_z,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValues) GetTemperature() *DevicePropertiesMinutMetadataLatestSensorValuesTemperature { + if d == nil { + return nil + } + return d.Temperature +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValues) GetSound() *DevicePropertiesMinutMetadataLatestSensorValuesSound { + if d == nil { + return nil + } + return d.Sound +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValues) GetHumidity() *DevicePropertiesMinutMetadataLatestSensorValuesHumidity { + if d == nil { + return nil + } + return d.Humidity +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValues) GetPressure() *DevicePropertiesMinutMetadataLatestSensorValuesPressure { + if d == nil { + return nil + } + return d.Pressure +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValues) GetAccelerometerZ() *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ { + if d == nil { + return nil + } + return d.AccelerometerZ +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValues) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadataLatestSensorValues) UnmarshalJSON(data []byte) error { @@ -3122,17 +11957,22 @@ func (d *DevicePropertiesMinutMetadataLatestSensorValues) UnmarshalJSON(data []b return err } *d = DevicePropertiesMinutMetadataLatestSensorValues(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadataLatestSensorValues) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3142,7 +11982,26 @@ type DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ struct { Time string `json:"time" url:"time"` Value float64 `json:"value" url:"value"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ) GetTime() string { + if d == nil { + return "" + } + return d.Time +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ) GetValue() float64 { + if d == nil { + return 0 + } + return d.Value +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ) UnmarshalJSON(data []byte) error { @@ -3152,17 +12011,22 @@ func (d *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ) Unmarsha return err } *d = DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadataLatestSensorValuesAccelerometerZ) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3172,7 +12036,26 @@ type DevicePropertiesMinutMetadataLatestSensorValuesHumidity struct { Time string `json:"time" url:"time"` Value float64 `json:"value" url:"value"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesHumidity) GetTime() string { + if d == nil { + return "" + } + return d.Time +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesHumidity) GetValue() float64 { + if d == nil { + return 0 + } + return d.Value +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesHumidity) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadataLatestSensorValuesHumidity) UnmarshalJSON(data []byte) error { @@ -3182,17 +12065,22 @@ func (d *DevicePropertiesMinutMetadataLatestSensorValuesHumidity) UnmarshalJSON( return err } *d = DevicePropertiesMinutMetadataLatestSensorValuesHumidity(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadataLatestSensorValuesHumidity) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3202,7 +12090,26 @@ type DevicePropertiesMinutMetadataLatestSensorValuesPressure struct { Time string `json:"time" url:"time"` Value float64 `json:"value" url:"value"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesPressure) GetTime() string { + if d == nil { + return "" + } + return d.Time +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesPressure) GetValue() float64 { + if d == nil { + return 0 + } + return d.Value +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesPressure) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadataLatestSensorValuesPressure) UnmarshalJSON(data []byte) error { @@ -3212,17 +12119,22 @@ func (d *DevicePropertiesMinutMetadataLatestSensorValuesPressure) UnmarshalJSON( return err } *d = DevicePropertiesMinutMetadataLatestSensorValuesPressure(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadataLatestSensorValuesPressure) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3232,7 +12144,26 @@ type DevicePropertiesMinutMetadataLatestSensorValuesSound struct { Time string `json:"time" url:"time"` Value float64 `json:"value" url:"value"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesSound) GetTime() string { + if d == nil { + return "" + } + return d.Time +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesSound) GetValue() float64 { + if d == nil { + return 0 + } + return d.Value +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesSound) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadataLatestSensorValuesSound) UnmarshalJSON(data []byte) error { @@ -3242,17 +12173,22 @@ func (d *DevicePropertiesMinutMetadataLatestSensorValuesSound) UnmarshalJSON(dat return err } *d = DevicePropertiesMinutMetadataLatestSensorValuesSound(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadataLatestSensorValuesSound) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3262,7 +12198,26 @@ type DevicePropertiesMinutMetadataLatestSensorValuesTemperature struct { Time string `json:"time" url:"time"` Value float64 `json:"value" url:"value"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesTemperature) GetTime() string { + if d == nil { + return "" + } + return d.Time +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesTemperature) GetValue() float64 { + if d == nil { + return 0 + } + return d.Value +} + +func (d *DevicePropertiesMinutMetadataLatestSensorValuesTemperature) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesMinutMetadataLatestSensorValuesTemperature) UnmarshalJSON(data []byte) error { @@ -3272,17 +12227,22 @@ func (d *DevicePropertiesMinutMetadataLatestSensorValuesTemperature) UnmarshalJS return err } *d = DevicePropertiesMinutMetadataLatestSensorValuesTemperature(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesMinutMetadataLatestSensorValuesTemperature) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3301,10 +12261,63 @@ type DevicePropertiesModel struct { OfflineAccessCodesSupported *bool `json:"offline_access_codes_supported,omitempty" url:"offline_access_codes_supported,omitempty"` // Indicates whether the device supports online access codes. OnlineAccessCodesSupported *bool `json:"online_access_codes_supported,omitempty" url:"online_access_codes_supported,omitempty"` - // Indicates whether the device supports an accessory keypad. - AccessoryKeypadSupported *bool `json:"accessory_keypad_supported,omitempty" url:"accessory_keypad_supported,omitempty"` + AccessoryKeypadSupported *bool `json:"accessory_keypad_supported,omitempty" url:"accessory_keypad_supported,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesModel) GetCanConnectAccessoryKeypad() *bool { + if d == nil { + return nil + } + return d.CanConnectAccessoryKeypad +} + +func (d *DevicePropertiesModel) GetDisplayName() string { + if d == nil { + return "" + } + return d.DisplayName +} + +func (d *DevicePropertiesModel) GetManufacturerDisplayName() string { + if d == nil { + return "" + } + return d.ManufacturerDisplayName +} + +func (d *DevicePropertiesModel) GetHasBuiltInKeypad() *bool { + if d == nil { + return nil + } + return d.HasBuiltInKeypad +} + +func (d *DevicePropertiesModel) GetOfflineAccessCodesSupported() *bool { + if d == nil { + return nil + } + return d.OfflineAccessCodesSupported +} + +func (d *DevicePropertiesModel) GetOnlineAccessCodesSupported() *bool { + if d == nil { + return nil + } + return d.OnlineAccessCodesSupported +} + +func (d *DevicePropertiesModel) GetAccessoryKeypadSupported() *bool { + if d == nil { + return nil + } + return d.AccessoryKeypadSupported +} - _rawJSON json.RawMessage +func (d *DevicePropertiesModel) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesModel) UnmarshalJSON(data []byte) error { @@ -3314,17 +12327,22 @@ func (d *DevicePropertiesModel) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesModel(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesModel) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3335,7 +12353,33 @@ type DevicePropertiesNestMetadata struct { DeviceName string `json:"device_name" url:"device_name"` CustomName string `json:"custom_name" url:"custom_name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesNestMetadata) GetNestDeviceId() string { + if d == nil { + return "" + } + return d.NestDeviceId +} + +func (d *DevicePropertiesNestMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesNestMetadata) GetCustomName() string { + if d == nil { + return "" + } + return d.CustomName +} + +func (d *DevicePropertiesNestMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesNestMetadata) UnmarshalJSON(data []byte) error { @@ -3345,30 +12389,75 @@ func (d *DevicePropertiesNestMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesNestMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesNestMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) } type DevicePropertiesNoiseawareMetadata struct { - DeviceModel DevicePropertiesNoiseawareMetadataDeviceModel `json:"device_model,omitempty" url:"device_model,omitempty"` + DeviceModel DevicePropertiesNoiseawareMetadataDeviceModel `json:"device_model" url:"device_model"` NoiseLevelNrs float64 `json:"noise_level_nrs" url:"noise_level_nrs"` NoiseLevelDecibel float64 `json:"noise_level_decibel" url:"noise_level_decibel"` DeviceName string `json:"device_name" url:"device_name"` DeviceId string `json:"device_id" url:"device_id"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesNoiseawareMetadata) GetDeviceModel() DevicePropertiesNoiseawareMetadataDeviceModel { + if d == nil { + return "" + } + return d.DeviceModel +} + +func (d *DevicePropertiesNoiseawareMetadata) GetNoiseLevelNrs() float64 { + if d == nil { + return 0 + } + return d.NoiseLevelNrs +} + +func (d *DevicePropertiesNoiseawareMetadata) GetNoiseLevelDecibel() float64 { + if d == nil { + return 0 + } + return d.NoiseLevelDecibel +} + +func (d *DevicePropertiesNoiseawareMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesNoiseawareMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesNoiseawareMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesNoiseawareMetadata) UnmarshalJSON(data []byte) error { @@ -3378,17 +12467,22 @@ func (d *DevicePropertiesNoiseawareMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesNoiseawareMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesNoiseawareMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3423,7 +12517,47 @@ type DevicePropertiesNukiMetadata struct { KeypadPaired *bool `json:"keypad_paired,omitempty" url:"keypad_paired,omitempty"` Keypad2Paired *bool `json:"keypad_2_paired,omitempty" url:"keypad_2_paired,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesNukiMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesNukiMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesNukiMetadata) GetKeypadBatteryCritical() *bool { + if d == nil { + return nil + } + return d.KeypadBatteryCritical +} + +func (d *DevicePropertiesNukiMetadata) GetKeypadPaired() *bool { + if d == nil { + return nil + } + return d.KeypadPaired +} + +func (d *DevicePropertiesNukiMetadata) GetKeypad2Paired() *bool { + if d == nil { + return nil + } + return d.Keypad2Paired +} + +func (d *DevicePropertiesNukiMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesNukiMetadata) UnmarshalJSON(data []byte) error { @@ -3433,17 +12567,22 @@ func (d *DevicePropertiesNukiMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesNukiMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesNukiMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3457,7 +12596,54 @@ type DevicePropertiesSaltoMetadata struct { LockedState string `json:"locked_state" url:"locked_state"` Model *string `json:"model,omitempty" url:"model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesSaltoMetadata) GetLockId() string { + if d == nil { + return "" + } + return d.LockId +} + +func (d *DevicePropertiesSaltoMetadata) GetCustomerReference() string { + if d == nil { + return "" + } + return d.CustomerReference +} + +func (d *DevicePropertiesSaltoMetadata) GetLockType() string { + if d == nil { + return "" + } + return d.LockType +} + +func (d *DevicePropertiesSaltoMetadata) GetBatteryLevel() string { + if d == nil { + return "" + } + return d.BatteryLevel +} + +func (d *DevicePropertiesSaltoMetadata) GetLockedState() string { + if d == nil { + return "" + } + return d.LockedState +} + +func (d *DevicePropertiesSaltoMetadata) GetModel() *string { + if d == nil { + return nil + } + return d.Model +} + +func (d *DevicePropertiesSaltoMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesSaltoMetadata) UnmarshalJSON(data []byte) error { @@ -3467,17 +12653,22 @@ func (d *DevicePropertiesSaltoMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesSaltoMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesSaltoMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3489,7 +12680,40 @@ type DevicePropertiesSchlageMetadata struct { AccessCodeLength *float64 `json:"access_code_length,omitempty" url:"access_code_length,omitempty"` Model *string `json:"model,omitempty" url:"model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesSchlageMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesSchlageMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesSchlageMetadata) GetAccessCodeLength() *float64 { + if d == nil { + return nil + } + return d.AccessCodeLength +} + +func (d *DevicePropertiesSchlageMetadata) GetModel() *string { + if d == nil { + return nil + } + return d.Model +} + +func (d *DevicePropertiesSchlageMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesSchlageMetadata) UnmarshalJSON(data []byte) error { @@ -3499,17 +12723,22 @@ func (d *DevicePropertiesSchlageMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesSchlageMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesSchlageMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3520,7 +12749,33 @@ type DevicePropertiesSeamBridgeMetadata struct { DeviceNum float64 `json:"device_num" url:"device_num"` Name string `json:"name" url:"name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesSeamBridgeMetadata) GetUnlockMethod() *DevicePropertiesSeamBridgeMetadataUnlockMethod { + if d == nil { + return nil + } + return d.UnlockMethod +} + +func (d *DevicePropertiesSeamBridgeMetadata) GetDeviceNum() float64 { + if d == nil { + return 0 + } + return d.DeviceNum +} + +func (d *DevicePropertiesSeamBridgeMetadata) GetName() string { + if d == nil { + return "" + } + return d.Name +} + +func (d *DevicePropertiesSeamBridgeMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesSeamBridgeMetadata) UnmarshalJSON(data []byte) error { @@ -3530,17 +12785,22 @@ func (d *DevicePropertiesSeamBridgeMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesSeamBridgeMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesSeamBridgeMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3574,7 +12834,40 @@ type DevicePropertiesSmartthingsMetadata struct { Model *string `json:"model,omitempty" url:"model,omitempty"` LocationId *string `json:"location_id,omitempty" url:"location_id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesSmartthingsMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId +} + +func (d *DevicePropertiesSmartthingsMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesSmartthingsMetadata) GetModel() *string { + if d == nil { + return nil + } + return d.Model +} + +func (d *DevicePropertiesSmartthingsMetadata) GetLocationId() *string { + if d == nil { + return nil + } + return d.LocationId +} + +func (d *DevicePropertiesSmartthingsMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesSmartthingsMetadata) UnmarshalJSON(data []byte) error { @@ -3584,17 +12877,22 @@ func (d *DevicePropertiesSmartthingsMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesSmartthingsMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesSmartthingsMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3609,7 +12907,61 @@ type DevicePropertiesTedeeMetadata struct { BridgeName string `json:"bridge_name" url:"bridge_name"` KeypadId *float64 `json:"keypad_id,omitempty" url:"keypad_id,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesTedeeMetadata) GetDeviceId() float64 { + if d == nil { + return 0 + } + return d.DeviceId +} + +func (d *DevicePropertiesTedeeMetadata) GetSerialNumber() string { + if d == nil { + return "" + } + return d.SerialNumber +} + +func (d *DevicePropertiesTedeeMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesTedeeMetadata) GetDeviceModel() string { + if d == nil { + return "" + } + return d.DeviceModel +} + +func (d *DevicePropertiesTedeeMetadata) GetBridgeId() float64 { + if d == nil { + return 0 + } + return d.BridgeId +} + +func (d *DevicePropertiesTedeeMetadata) GetBridgeName() string { + if d == nil { + return "" + } + return d.BridgeName +} + +func (d *DevicePropertiesTedeeMetadata) GetKeypadId() *float64 { + if d == nil { + return nil + } + return d.KeypadId +} + +func (d *DevicePropertiesTedeeMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesTedeeMetadata) UnmarshalJSON(data []byte) error { @@ -3619,27 +12971,59 @@ func (d *DevicePropertiesTedeeMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesTedeeMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesTedeeMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) } type DevicePropertiesTtlockMetadata struct { - LockId float64 `json:"lock_id" url:"lock_id"` - LockAlias string `json:"lock_alias" url:"lock_alias"` + LockId float64 `json:"lock_id" url:"lock_id"` + LockAlias string `json:"lock_alias" url:"lock_alias"` + FeatureValue string `json:"feature_value" url:"feature_value"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesTtlockMetadata) GetLockId() float64 { + if d == nil { + return 0 + } + return d.LockId +} + +func (d *DevicePropertiesTtlockMetadata) GetLockAlias() string { + if d == nil { + return "" + } + return d.LockAlias +} + +func (d *DevicePropertiesTtlockMetadata) GetFeatureValue() string { + if d == nil { + return "" + } + return d.FeatureValue +} - _rawJSON json.RawMessage +func (d *DevicePropertiesTtlockMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesTtlockMetadata) UnmarshalJSON(data []byte) error { @@ -3649,17 +13033,22 @@ func (d *DevicePropertiesTtlockMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesTtlockMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesTtlockMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3669,7 +13058,26 @@ type DevicePropertiesTwoNMetadata struct { DeviceId float64 `json:"device_id" url:"device_id"` DeviceName string `json:"device_name" url:"device_name"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DevicePropertiesTwoNMetadata) GetDeviceId() float64 { + if d == nil { + return 0 + } + return d.DeviceId +} + +func (d *DevicePropertiesTwoNMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} + +func (d *DevicePropertiesTwoNMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DevicePropertiesTwoNMetadata) UnmarshalJSON(data []byte) error { @@ -3679,17 +13087,22 @@ func (d *DevicePropertiesTwoNMetadata) UnmarshalJSON(data []byte) error { return err } *d = DevicePropertiesTwoNMetadata(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DevicePropertiesTwoNMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -3705,220 +13118,96 @@ type DevicePropertiesWyzeMetadata struct { KeypadUuid *string `json:"keypad_uuid,omitempty" url:"keypad_uuid,omitempty"` LockerStatusHardlock *float64 `json:"locker_status_hardlock,omitempty" url:"locker_status_hardlock,omitempty"` - _rawJSON json.RawMessage -} - -func (d *DevicePropertiesWyzeMetadata) UnmarshalJSON(data []byte) error { - type unmarshaler DevicePropertiesWyzeMetadata - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *d = DevicePropertiesWyzeMetadata(value) - d._rawJSON = json.RawMessage(data) - return nil -} - -func (d *DevicePropertiesWyzeMetadata) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(d); err == nil { - return value - } - return fmt.Sprintf("%#v", d) -} - -type DeviceProvider struct { - DeviceProviderName DeviceProviderDeviceProviderName `json:"device_provider_name,omitempty" url:"device_provider_name,omitempty"` - DisplayName string `json:"display_name" url:"display_name"` - ImageUrl string `json:"image_url" url:"image_url"` - ProviderCategories []DeviceProviderProviderCategoriesItem `json:"provider_categories,omitempty" url:"provider_categories,omitempty"` - - _rawJSON json.RawMessage -} - -func (d *DeviceProvider) UnmarshalJSON(data []byte) error { - type unmarshaler DeviceProvider - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *d = DeviceProvider(value) - d._rawJSON = json.RawMessage(data) - return nil -} - -func (d *DeviceProvider) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(d); err == nil { - return value - } - return fmt.Sprintf("%#v", d) -} - -type DeviceProviderDeviceProviderName string - -const ( - DeviceProviderDeviceProviderNameAkuvox DeviceProviderDeviceProviderName = "akuvox" - DeviceProviderDeviceProviderNameAugust DeviceProviderDeviceProviderName = "august" - DeviceProviderDeviceProviderNameAvigilonAlta DeviceProviderDeviceProviderName = "avigilon_alta" - DeviceProviderDeviceProviderNameBrivo DeviceProviderDeviceProviderName = "brivo" - DeviceProviderDeviceProviderNameButterflymx DeviceProviderDeviceProviderName = "butterflymx" - DeviceProviderDeviceProviderNameSchlage DeviceProviderDeviceProviderName = "schlage" - DeviceProviderDeviceProviderNameSmartthings DeviceProviderDeviceProviderName = "smartthings" - DeviceProviderDeviceProviderNameYale DeviceProviderDeviceProviderName = "yale" - DeviceProviderDeviceProviderNameGenie DeviceProviderDeviceProviderName = "genie" - DeviceProviderDeviceProviderNameDoorking DeviceProviderDeviceProviderName = "doorking" - DeviceProviderDeviceProviderNameSalto DeviceProviderDeviceProviderName = "salto" - DeviceProviderDeviceProviderNameLockly DeviceProviderDeviceProviderName = "lockly" - DeviceProviderDeviceProviderNameTtlock DeviceProviderDeviceProviderName = "ttlock" - DeviceProviderDeviceProviderNameLinear DeviceProviderDeviceProviderName = "linear" - DeviceProviderDeviceProviderNameNoiseaware DeviceProviderDeviceProviderName = "noiseaware" - DeviceProviderDeviceProviderNameNuki DeviceProviderDeviceProviderName = "nuki" - DeviceProviderDeviceProviderNameSeamRelayAdmin DeviceProviderDeviceProviderName = "seam_relay_admin" - DeviceProviderDeviceProviderNameIgloo DeviceProviderDeviceProviderName = "igloo" - DeviceProviderDeviceProviderNameKwikset DeviceProviderDeviceProviderName = "kwikset" - DeviceProviderDeviceProviderNameMinut DeviceProviderDeviceProviderName = "minut" - DeviceProviderDeviceProviderNameMy2N DeviceProviderDeviceProviderName = "my_2n" - DeviceProviderDeviceProviderNameControlbyweb DeviceProviderDeviceProviderName = "controlbyweb" - DeviceProviderDeviceProviderNameNest DeviceProviderDeviceProviderName = "nest" - DeviceProviderDeviceProviderNameIgloohome DeviceProviderDeviceProviderName = "igloohome" - DeviceProviderDeviceProviderNameEcobee DeviceProviderDeviceProviderName = "ecobee" - DeviceProviderDeviceProviderNameHubitat DeviceProviderDeviceProviderName = "hubitat" - DeviceProviderDeviceProviderNameFourSuites DeviceProviderDeviceProviderName = "four_suites" - DeviceProviderDeviceProviderNameDormakabaOracode DeviceProviderDeviceProviderName = "dormakaba_oracode" - DeviceProviderDeviceProviderNamePti DeviceProviderDeviceProviderName = "pti" - DeviceProviderDeviceProviderNameWyze DeviceProviderDeviceProviderName = "wyze" - DeviceProviderDeviceProviderNameSeamPassport DeviceProviderDeviceProviderName = "seam_passport" - DeviceProviderDeviceProviderNameVisionline DeviceProviderDeviceProviderName = "visionline" - DeviceProviderDeviceProviderNameAssaAbloyCredentialService DeviceProviderDeviceProviderName = "assa_abloy_credential_service" - DeviceProviderDeviceProviderNameSeamBridge DeviceProviderDeviceProviderName = "seam_bridge" - DeviceProviderDeviceProviderNameTedee DeviceProviderDeviceProviderName = "tedee" - DeviceProviderDeviceProviderNameHoneywellResideo DeviceProviderDeviceProviderName = "honeywell_resideo" - DeviceProviderDeviceProviderNameLatch DeviceProviderDeviceProviderName = "latch" -) - -func NewDeviceProviderDeviceProviderNameFromString(s string) (DeviceProviderDeviceProviderName, error) { - switch s { - case "akuvox": - return DeviceProviderDeviceProviderNameAkuvox, nil - case "august": - return DeviceProviderDeviceProviderNameAugust, nil - case "avigilon_alta": - return DeviceProviderDeviceProviderNameAvigilonAlta, nil - case "brivo": - return DeviceProviderDeviceProviderNameBrivo, nil - case "butterflymx": - return DeviceProviderDeviceProviderNameButterflymx, nil - case "schlage": - return DeviceProviderDeviceProviderNameSchlage, nil - case "smartthings": - return DeviceProviderDeviceProviderNameSmartthings, nil - case "yale": - return DeviceProviderDeviceProviderNameYale, nil - case "genie": - return DeviceProviderDeviceProviderNameGenie, nil - case "doorking": - return DeviceProviderDeviceProviderNameDoorking, nil - case "salto": - return DeviceProviderDeviceProviderNameSalto, nil - case "lockly": - return DeviceProviderDeviceProviderNameLockly, nil - case "ttlock": - return DeviceProviderDeviceProviderNameTtlock, nil - case "linear": - return DeviceProviderDeviceProviderNameLinear, nil - case "noiseaware": - return DeviceProviderDeviceProviderNameNoiseaware, nil - case "nuki": - return DeviceProviderDeviceProviderNameNuki, nil - case "seam_relay_admin": - return DeviceProviderDeviceProviderNameSeamRelayAdmin, nil - case "igloo": - return DeviceProviderDeviceProviderNameIgloo, nil - case "kwikset": - return DeviceProviderDeviceProviderNameKwikset, nil - case "minut": - return DeviceProviderDeviceProviderNameMinut, nil - case "my_2n": - return DeviceProviderDeviceProviderNameMy2N, nil - case "controlbyweb": - return DeviceProviderDeviceProviderNameControlbyweb, nil - case "nest": - return DeviceProviderDeviceProviderNameNest, nil - case "igloohome": - return DeviceProviderDeviceProviderNameIgloohome, nil - case "ecobee": - return DeviceProviderDeviceProviderNameEcobee, nil - case "hubitat": - return DeviceProviderDeviceProviderNameHubitat, nil - case "four_suites": - return DeviceProviderDeviceProviderNameFourSuites, nil - case "dormakaba_oracode": - return DeviceProviderDeviceProviderNameDormakabaOracode, nil - case "pti": - return DeviceProviderDeviceProviderNamePti, nil - case "wyze": - return DeviceProviderDeviceProviderNameWyze, nil - case "seam_passport": - return DeviceProviderDeviceProviderNameSeamPassport, nil - case "visionline": - return DeviceProviderDeviceProviderNameVisionline, nil - case "assa_abloy_credential_service": - return DeviceProviderDeviceProviderNameAssaAbloyCredentialService, nil - case "seam_bridge": - return DeviceProviderDeviceProviderNameSeamBridge, nil - case "tedee": - return DeviceProviderDeviceProviderNameTedee, nil - case "honeywell_resideo": - return DeviceProviderDeviceProviderNameHoneywellResideo, nil - case "latch": - return DeviceProviderDeviceProviderNameLatch, nil - } - var t DeviceProviderDeviceProviderName - return "", fmt.Errorf("%s is not a valid %T", s, t) + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (d DeviceProviderDeviceProviderName) Ptr() *DeviceProviderDeviceProviderName { - return &d +func (d *DevicePropertiesWyzeMetadata) GetDeviceId() string { + if d == nil { + return "" + } + return d.DeviceId } -type DeviceProviderProviderCategoriesItem string +func (d *DevicePropertiesWyzeMetadata) GetDeviceName() string { + if d == nil { + return "" + } + return d.DeviceName +} -const ( - DeviceProviderProviderCategoriesItemStable DeviceProviderProviderCategoriesItem = "stable" - DeviceProviderProviderCategoriesItemConsumerSmartlocks DeviceProviderProviderCategoriesItem = "consumer_smartlocks" - DeviceProviderProviderCategoriesItemThermostats DeviceProviderProviderCategoriesItem = "thermostats" - DeviceProviderProviderCategoriesItemNoiseSensors DeviceProviderProviderCategoriesItem = "noise_sensors" - DeviceProviderProviderCategoriesItemAccessControlSystems DeviceProviderProviderCategoriesItem = "access_control_systems" -) +func (d *DevicePropertiesWyzeMetadata) GetProductName() string { + if d == nil { + return "" + } + return d.ProductName +} -func NewDeviceProviderProviderCategoriesItemFromString(s string) (DeviceProviderProviderCategoriesItem, error) { - switch s { - case "stable": - return DeviceProviderProviderCategoriesItemStable, nil - case "consumer_smartlocks": - return DeviceProviderProviderCategoriesItemConsumerSmartlocks, nil - case "thermostats": - return DeviceProviderProviderCategoriesItemThermostats, nil - case "noise_sensors": - return DeviceProviderProviderCategoriesItemNoiseSensors, nil - case "access_control_systems": - return DeviceProviderProviderCategoriesItemAccessControlSystems, nil - } - var t DeviceProviderProviderCategoriesItem - return "", fmt.Errorf("%s is not a valid %T", s, t) +func (d *DevicePropertiesWyzeMetadata) GetProductType() string { + if d == nil { + return "" + } + return d.ProductType } -func (d DeviceProviderProviderCategoriesItem) Ptr() *DeviceProviderProviderCategoriesItem { - return &d +func (d *DevicePropertiesWyzeMetadata) GetProductModel() string { + if d == nil { + return "" + } + return d.ProductModel +} + +func (d *DevicePropertiesWyzeMetadata) GetDeviceInfoModel() string { + if d == nil { + return "" + } + return d.DeviceInfoModel +} + +func (d *DevicePropertiesWyzeMetadata) GetKeypadUuid() *string { + if d == nil { + return nil + } + return d.KeypadUuid +} + +func (d *DevicePropertiesWyzeMetadata) GetLockerStatusHardlock() *float64 { + if d == nil { + return nil + } + return d.LockerStatusHardlock +} + +func (d *DevicePropertiesWyzeMetadata) GetExtraProperties() map[string]interface{} { + return d.extraProperties +} + +func (d *DevicePropertiesWyzeMetadata) UnmarshalJSON(data []byte) error { + type unmarshaler DevicePropertiesWyzeMetadata + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *d = DevicePropertiesWyzeMetadata(value) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) + return nil +} + +func (d *DevicePropertiesWyzeMetadata) String() string { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(d); err == nil { + return value + } + return fmt.Sprintf("%#v", d) } type DeviceType string @@ -4034,7 +13323,26 @@ type DeviceWarningsItem struct { WarningCode string `json:"warning_code" url:"warning_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (d *DeviceWarningsItem) GetWarningCode() string { + if d == nil { + return "" + } + return d.WarningCode +} + +func (d *DeviceWarningsItem) GetMessage() string { + if d == nil { + return "" + } + return d.Message +} + +func (d *DeviceWarningsItem) GetExtraProperties() map[string]interface{} { + return d.extraProperties } func (d *DeviceWarningsItem) UnmarshalJSON(data []byte) error { @@ -4044,17 +13352,22 @@ func (d *DeviceWarningsItem) UnmarshalJSON(data []byte) error { return err } *d = DeviceWarningsItem(value) - d._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *d) + if err != nil { + return err + } + d.extraProperties = extraProperties + d.rawJSON = json.RawMessage(data) return nil } func (d *DeviceWarningsItem) String() string { - if len(d._rawJSON) > 0 { - if value, err := core.StringifyJSON(d._rawJSON); err == nil { + if len(d.rawJSON) > 0 { + if value, err := internal.StringifyJSON(d.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(d); err == nil { + if value, err := internal.StringifyJSON(d); err == nil { return value } return fmt.Sprintf("%#v", d) @@ -4067,297 +13380,95 @@ type EnrollmentAutomation struct { WorkspaceId string `json:"workspace_id" url:"workspace_id"` EnrollmentAutomationId string `json:"enrollment_automation_id" url:"enrollment_automation_id"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (e *EnrollmentAutomation) UnmarshalJSON(data []byte) error { - type embed EnrollmentAutomation - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*e), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err +func (e *EnrollmentAutomation) GetCredentialManagerAcsSystemId() string { + if e == nil { + return "" } - *e = EnrollmentAutomation(unmarshaler.embed) - e.CreatedAt = unmarshaler.CreatedAt.Time() - e._rawJSON = json.RawMessage(data) - return nil + return e.CredentialManagerAcsSystemId } -func (e *EnrollmentAutomation) MarshalJSON() ([]byte, error) { - type embed EnrollmentAutomation - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*e), - CreatedAt: core.NewDateTime(e.CreatedAt), +func (e *EnrollmentAutomation) GetUserIdentityId() string { + if e == nil { + return "" } - return json.Marshal(marshaler) + return e.UserIdentityId } -func (e *EnrollmentAutomation) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { - return value - } +func (e *EnrollmentAutomation) GetCreatedAt() time.Time { + if e == nil { + return time.Time{} } - if value, err := core.StringifyJSON(e); err == nil { - return value + return e.CreatedAt +} + +func (e *EnrollmentAutomation) GetWorkspaceId() string { + if e == nil { + return "" } - return fmt.Sprintf("%#v", e) + return e.WorkspaceId } -type Event struct { - EventId string `json:"event_id" url:"event_id"` - DeviceId *string `json:"device_id,omitempty" url:"device_id,omitempty"` - ActionAttemptId *string `json:"action_attempt_id,omitempty" url:"action_attempt_id,omitempty"` - AcsCredentialId *string `json:"acs_credential_id,omitempty" url:"acs_credential_id,omitempty"` - AcsUserId *string `json:"acs_user_id,omitempty" url:"acs_user_id,omitempty"` - AcsSystemId *string `json:"acs_system_id,omitempty" url:"acs_system_id,omitempty"` - ClientSessionId *string `json:"client_session_id,omitempty" url:"client_session_id,omitempty"` - EnrollmentAutomationId *string `json:"enrollment_automation_id,omitempty" url:"enrollment_automation_id,omitempty"` - EventType string `json:"event_type" url:"event_type"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - OccurredAt time.Time `json:"occurred_at" url:"occurred_at"` +func (e *EnrollmentAutomation) GetEnrollmentAutomationId() string { + if e == nil { + return "" + } + return e.EnrollmentAutomationId +} - _rawJSON json.RawMessage +func (e *EnrollmentAutomation) GetExtraProperties() map[string]interface{} { + return e.extraProperties } -func (e *Event) UnmarshalJSON(data []byte) error { - type embed Event +func (e *EnrollmentAutomation) UnmarshalJSON(data []byte) error { + type embed EnrollmentAutomation var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` - OccurredAt *core.DateTime `json:"occurred_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*e), } if err := json.Unmarshal(data, &unmarshaler); err != nil { return err } - *e = Event(unmarshaler.embed) + *e = EnrollmentAutomation(unmarshaler.embed) e.CreatedAt = unmarshaler.CreatedAt.Time() - e.OccurredAt = unmarshaler.OccurredAt.Time() - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } -func (e *Event) MarshalJSON() ([]byte, error) { - type embed Event +func (e *EnrollmentAutomation) MarshalJSON() ([]byte, error) { + type embed EnrollmentAutomation var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` - OccurredAt *core.DateTime `json:"occurred_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ - embed: embed(*e), - CreatedAt: core.NewDateTime(e.CreatedAt), - OccurredAt: core.NewDateTime(e.OccurredAt), + embed: embed(*e), + CreatedAt: internal.NewDateTime(e.CreatedAt), } return json.Marshal(marshaler) } -func (e *Event) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { +func (e *EnrollmentAutomation) String() string { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) } -type EventType string - -const ( - EventTypeDeviceConnected EventType = "device.connected" - EventTypeDeviceUnmanagedConnected EventType = "device.unmanaged.connected" - EventTypeDeviceDisconnected EventType = "device.disconnected" - EventTypeDeviceUnmanagedDisconnected EventType = "device.unmanaged.disconnected" - EventTypeDeviceConvertedToUnmanaged EventType = "device.converted_to_unmanaged" - EventTypeDeviceUnmanagedConvertedToManaged EventType = "device.unmanaged.converted_to_managed" - EventTypeDeviceRemoved EventType = "device.removed" - EventTypeDeviceTampered EventType = "device.tampered" - EventTypeDeviceLowBattery EventType = "device.low_battery" - EventTypeDeviceBatteryStatusChanged EventType = "device.battery_status_changed" - EventTypeDeviceThirdPartyIntegrationDetected EventType = "device.third_party_integration_detected" - EventTypeDeviceThirdPartyIntegrationNoLongerDetected EventType = "device.third_party_integration_no_longer_detected" - EventTypeDeviceSaltoPrivacyModeActivated EventType = "device.salto.privacy_mode_activated" - EventTypeDeviceSaltoPrivacyModeDeactivated EventType = "device.salto.privacy_mode_deactivated" - EventTypeDeviceConnectionBecameFlaky EventType = "device.connection_became_flaky" - EventTypeDeviceConnectionStabilized EventType = "device.connection_stabilized" - EventTypeDeviceErrorSubscriptionRequired EventType = "device.error.subscription_required" - EventTypeDeviceErrorSubscriptionRequiredResolved EventType = "device.error.subscription_required.resolved" - EventTypeAccessCodeCreated EventType = "access_code.created" - EventTypeAccessCodeChanged EventType = "access_code.changed" - EventTypeAccessCodeScheduledOnDevice EventType = "access_code.scheduled_on_device" - EventTypeAccessCodeSetOnDevice EventType = "access_code.set_on_device" - EventTypeAccessCodeDeleted EventType = "access_code.deleted" - EventTypeAccessCodeRemovedFromDevice EventType = "access_code.removed_from_device" - EventTypeAccessCodeFailedToSetOnDevice EventType = "access_code.failed_to_set_on_device" - EventTypeAccessCodeDelayInSettingOnDevice EventType = "access_code.delay_in_setting_on_device" - EventTypeAccessCodeFailedToRemoveFromDevice EventType = "access_code.failed_to_remove_from_device" - EventTypeAccessCodeDelayInRemovingFromDevice EventType = "access_code.delay_in_removing_from_device" - EventTypeAccessCodeDeletedExternalToSeam EventType = "access_code.deleted_external_to_seam" - EventTypeAccessCodeModifiedExternalToSeam EventType = "access_code.modified_external_to_seam" - EventTypeAccessCodeUnmanagedConvertedToManaged EventType = "access_code.unmanaged.converted_to_managed" - EventTypeAccessCodeUnmanagedFailedToConvertToManaged EventType = "access_code.unmanaged.failed_to_convert_to_managed" - EventTypeAccessCodeUnmanagedCreated EventType = "access_code.unmanaged.created" - EventTypeAccessCodeUnmanagedRemoved EventType = "access_code.unmanaged.removed" - EventTypeLockLocked EventType = "lock.locked" - EventTypeLockUnlocked EventType = "lock.unlocked" - EventTypeConnectedAccountConnected EventType = "connected_account.connected" - EventTypeConnectedAccountSuccessfulLogin EventType = "connected_account.successful_login" - EventTypeConnectedAccountCreated EventType = "connected_account.created" - EventTypeConnectedAccountDeleted EventType = "connected_account.deleted" - EventTypeConnectedAccountDisconnected EventType = "connected_account.disconnected" - EventTypeConnectedAccountCompletedFirstSync EventType = "connected_account.completed_first_sync" - EventTypeNoiseSensorNoiseThresholdTriggered EventType = "noise_sensor.noise_threshold_triggered" - EventTypeAccessCodeBackupAccessCodePulled EventType = "access_code.backup_access_code_pulled" - EventTypeEnrollmentAutomationDeleted EventType = "enrollment_automation.deleted" - EventTypeAcsUserDeleted EventType = "acs_user.deleted" - EventTypeAcsCredentialDeleted EventType = "acs_credential.deleted" - EventTypePhoneDeactivated EventType = "phone.deactivated" - EventTypeClientSessionDeleted EventType = "client_session.deleted" -) - -func NewEventTypeFromString(s string) (EventType, error) { - switch s { - case "device.connected": - return EventTypeDeviceConnected, nil - case "device.unmanaged.connected": - return EventTypeDeviceUnmanagedConnected, nil - case "device.disconnected": - return EventTypeDeviceDisconnected, nil - case "device.unmanaged.disconnected": - return EventTypeDeviceUnmanagedDisconnected, nil - case "device.converted_to_unmanaged": - return EventTypeDeviceConvertedToUnmanaged, nil - case "device.unmanaged.converted_to_managed": - return EventTypeDeviceUnmanagedConvertedToManaged, nil - case "device.removed": - return EventTypeDeviceRemoved, nil - case "device.tampered": - return EventTypeDeviceTampered, nil - case "device.low_battery": - return EventTypeDeviceLowBattery, nil - case "device.battery_status_changed": - return EventTypeDeviceBatteryStatusChanged, nil - case "device.third_party_integration_detected": - return EventTypeDeviceThirdPartyIntegrationDetected, nil - case "device.third_party_integration_no_longer_detected": - return EventTypeDeviceThirdPartyIntegrationNoLongerDetected, nil - case "device.salto.privacy_mode_activated": - return EventTypeDeviceSaltoPrivacyModeActivated, nil - case "device.salto.privacy_mode_deactivated": - return EventTypeDeviceSaltoPrivacyModeDeactivated, nil - case "device.connection_became_flaky": - return EventTypeDeviceConnectionBecameFlaky, nil - case "device.connection_stabilized": - return EventTypeDeviceConnectionStabilized, nil - case "device.error.subscription_required": - return EventTypeDeviceErrorSubscriptionRequired, nil - case "device.error.subscription_required.resolved": - return EventTypeDeviceErrorSubscriptionRequiredResolved, nil - case "access_code.created": - return EventTypeAccessCodeCreated, nil - case "access_code.changed": - return EventTypeAccessCodeChanged, nil - case "access_code.scheduled_on_device": - return EventTypeAccessCodeScheduledOnDevice, nil - case "access_code.set_on_device": - return EventTypeAccessCodeSetOnDevice, nil - case "access_code.deleted": - return EventTypeAccessCodeDeleted, nil - case "access_code.removed_from_device": - return EventTypeAccessCodeRemovedFromDevice, nil - case "access_code.failed_to_set_on_device": - return EventTypeAccessCodeFailedToSetOnDevice, nil - case "access_code.delay_in_setting_on_device": - return EventTypeAccessCodeDelayInSettingOnDevice, nil - case "access_code.failed_to_remove_from_device": - return EventTypeAccessCodeFailedToRemoveFromDevice, nil - case "access_code.delay_in_removing_from_device": - return EventTypeAccessCodeDelayInRemovingFromDevice, nil - case "access_code.deleted_external_to_seam": - return EventTypeAccessCodeDeletedExternalToSeam, nil - case "access_code.modified_external_to_seam": - return EventTypeAccessCodeModifiedExternalToSeam, nil - case "access_code.unmanaged.converted_to_managed": - return EventTypeAccessCodeUnmanagedConvertedToManaged, nil - case "access_code.unmanaged.failed_to_convert_to_managed": - return EventTypeAccessCodeUnmanagedFailedToConvertToManaged, nil - case "access_code.unmanaged.created": - return EventTypeAccessCodeUnmanagedCreated, nil - case "access_code.unmanaged.removed": - return EventTypeAccessCodeUnmanagedRemoved, nil - case "lock.locked": - return EventTypeLockLocked, nil - case "lock.unlocked": - return EventTypeLockUnlocked, nil - case "connected_account.connected": - return EventTypeConnectedAccountConnected, nil - case "connected_account.successful_login": - return EventTypeConnectedAccountSuccessfulLogin, nil - case "connected_account.created": - return EventTypeConnectedAccountCreated, nil - case "connected_account.deleted": - return EventTypeConnectedAccountDeleted, nil - case "connected_account.disconnected": - return EventTypeConnectedAccountDisconnected, nil - case "connected_account.completed_first_sync": - return EventTypeConnectedAccountCompletedFirstSync, nil - case "noise_sensor.noise_threshold_triggered": - return EventTypeNoiseSensorNoiseThresholdTriggered, nil - case "access_code.backup_access_code_pulled": - return EventTypeAccessCodeBackupAccessCodePulled, nil - case "enrollment_automation.deleted": - return EventTypeEnrollmentAutomationDeleted, nil - case "acs_user.deleted": - return EventTypeAcsUserDeleted, nil - case "acs_credential.deleted": - return EventTypeAcsCredentialDeleted, nil - case "phone.deactivated": - return EventTypePhoneDeactivated, nil - case "client_session.deleted": - return EventTypeClientSessionDeleted, nil - } - var t EventType - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (e EventType) Ptr() *EventType { - return &e -} - -type FanMode string - -const ( - FanModeAuto FanMode = "auto" - FanModeOn FanMode = "on" -) - -func NewFanModeFromString(s string) (FanMode, error) { - switch s { - case "auto": - return FanModeAuto, nil - case "on": - return FanModeOn, nil - } - var t FanMode - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (f FanMode) Ptr() *FanMode { - return &f -} - type FanModeSetting string const ( @@ -4520,157 +13631,285 @@ func (m Manufacturer) Ptr() *Manufacturer { return &m } -type MaxTimeRounding string +type NoiseThreshold struct { + NoiseThresholdId string `json:"noise_threshold_id" url:"noise_threshold_id"` + DeviceId string `json:"device_id" url:"device_id"` + Name string `json:"name" url:"name"` + NoiseThresholdNrs *float64 `json:"noise_threshold_nrs,omitempty" url:"noise_threshold_nrs,omitempty"` + StartsDailyAt string `json:"starts_daily_at" url:"starts_daily_at"` + EndsDailyAt string `json:"ends_daily_at" url:"ends_daily_at"` + NoiseThresholdDecibels float64 `json:"noise_threshold_decibels" url:"noise_threshold_decibels"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (n *NoiseThreshold) GetNoiseThresholdId() string { + if n == nil { + return "" + } + return n.NoiseThresholdId +} -const ( - MaxTimeRoundingOneHour MaxTimeRounding = "1hour" - MaxTimeRoundingOneDay MaxTimeRounding = "1day" - MaxTimeRoundingOneH MaxTimeRounding = "1h" - MaxTimeRoundingOneD MaxTimeRounding = "1d" -) +func (n *NoiseThreshold) GetDeviceId() string { + if n == nil { + return "" + } + return n.DeviceId +} -func NewMaxTimeRoundingFromString(s string) (MaxTimeRounding, error) { - switch s { - case "1hour": - return MaxTimeRoundingOneHour, nil - case "1day": - return MaxTimeRoundingOneDay, nil - case "1h": - return MaxTimeRoundingOneH, nil - case "1d": - return MaxTimeRoundingOneD, nil - } - var t MaxTimeRounding - return "", fmt.Errorf("%s is not a valid %T", s, t) +func (n *NoiseThreshold) GetName() string { + if n == nil { + return "" + } + return n.Name } -func (m MaxTimeRounding) Ptr() *MaxTimeRounding { - return &m +func (n *NoiseThreshold) GetNoiseThresholdNrs() *float64 { + if n == nil { + return nil + } + return n.NoiseThresholdNrs +} + +func (n *NoiseThreshold) GetStartsDailyAt() string { + if n == nil { + return "" + } + return n.StartsDailyAt } -type Network struct { - NetworkId string `json:"network_id" url:"network_id"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - DisplayName string `json:"display_name" url:"display_name"` - CreatedAt time.Time `json:"created_at" url:"created_at"` +func (n *NoiseThreshold) GetEndsDailyAt() string { + if n == nil { + return "" + } + return n.EndsDailyAt +} - _rawJSON json.RawMessage +func (n *NoiseThreshold) GetNoiseThresholdDecibels() float64 { + if n == nil { + return 0 + } + return n.NoiseThresholdDecibels } -func (n *Network) UnmarshalJSON(data []byte) error { - type embed Network - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*n), +func (n *NoiseThreshold) GetExtraProperties() map[string]interface{} { + return n.extraProperties +} + +func (n *NoiseThreshold) UnmarshalJSON(data []byte) error { + type unmarshaler NoiseThreshold + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err } - if err := json.Unmarshal(data, &unmarshaler); err != nil { + *n = NoiseThreshold(value) + extraProperties, err := internal.ExtractExtraProperties(data, *n) + if err != nil { return err } - *n = Network(unmarshaler.embed) - n.CreatedAt = unmarshaler.CreatedAt.Time() - n._rawJSON = json.RawMessage(data) - return nil + n.extraProperties = extraProperties + n.rawJSON = json.RawMessage(data) + return nil +} + +func (n *NoiseThreshold) String() string { + if len(n.rawJSON) > 0 { + if value, err := internal.StringifyJSON(n.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(n); err == nil { + return value + } + return fmt.Sprintf("%#v", n) +} + +type Phone struct { + // Unique identifier for the device. + DeviceId string `json:"device_id" url:"device_id"` + DeviceType PhoneDeviceType `json:"device_type" url:"device_type"` + // Optional nickname to describe the device, settable through Seam + Nickname *string `json:"nickname,omitempty" url:"nickname,omitempty"` + // Display name of the device, defaults to nickname (if it is set) or properties.appearance.name otherwise. Enables administrators and users to identify the device easily, especially when there are numerous devices. + DisplayName string `json:"display_name" url:"display_name"` + // Collection of capabilities that the device supports when connected to Seam. Values are "access_code," which indicates that the device can manage and utilize digital PIN codes for secure access; "lock," which indicates that the device controls a door locking mechanism, enabling the remote opening and closing of doors and other entry points; "noise_detection," which indicates that the device supports monitoring and responding to ambient noise levels; "thermostat," which indicates that the device can regulate and adjust indoor temperatures; and "battery," which indicates that the device can manage battery life and health. + CapabilitiesSupported []PhoneCapabilitiesSupportedItem `json:"capabilities_supported,omitempty" url:"capabilities_supported,omitempty"` + Properties *PhoneProperties `json:"properties,omitempty" url:"properties,omitempty"` + // Location information for the device. + Location *PhoneLocation `json:"location,omitempty" url:"location,omitempty"` + // Unique identifier for the Seam workspace associated with the device. + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + // Array of errors associated with the device. Each error object within the array contains two fields: "error_code" and "message." "error_code" is a string that uniquely identifies the type of error, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the error, offering insights into the issue and potentially how to rectify it. + Errors []*PhoneErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` + // Array of warnings associated with the device. Each warning object within the array contains two fields: "warning_code" and "message." "warning_code" is a string that uniquely identifies the type of warning, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the warning, offering insights into the issue and potentially how to rectify it. + Warnings []*PhoneWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` + // Date and time at which the device object was created. + CreatedAt time.Time `json:"created_at" url:"created_at"` + // Indicates whether Seam manages the device. + IsManaged bool `json:"is_managed" url:"is_managed"` + CustomMetadata map[string]*PhoneCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` + CanRemotelyUnlock *bool `json:"can_remotely_unlock,omitempty" url:"can_remotely_unlock,omitempty"` + CanRemotelyLock *bool `json:"can_remotely_lock,omitempty" url:"can_remotely_lock,omitempty"` + CanProgramOfflineAccessCodes *bool `json:"can_program_offline_access_codes,omitempty" url:"can_program_offline_access_codes,omitempty"` + CanProgramOnlineAccessCodes *bool `json:"can_program_online_access_codes,omitempty" url:"can_program_online_access_codes,omitempty"` + CanSimulateRemoval *bool `json:"can_simulate_removal,omitempty" url:"can_simulate_removal,omitempty"` + CanSimulateConnection *bool `json:"can_simulate_connection,omitempty" url:"can_simulate_connection,omitempty"` + CanSimulateDisconnection *bool `json:"can_simulate_disconnection,omitempty" url:"can_simulate_disconnection,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *Phone) GetDeviceId() string { + if p == nil { + return "" + } + return p.DeviceId +} + +func (p *Phone) GetDeviceType() PhoneDeviceType { + if p == nil { + return "" + } + return p.DeviceType +} + +func (p *Phone) GetNickname() *string { + if p == nil { + return nil + } + return p.Nickname +} + +func (p *Phone) GetDisplayName() string { + if p == nil { + return "" + } + return p.DisplayName +} + +func (p *Phone) GetCapabilitiesSupported() []PhoneCapabilitiesSupportedItem { + if p == nil { + return nil + } + return p.CapabilitiesSupported +} + +func (p *Phone) GetProperties() *PhoneProperties { + if p == nil { + return nil + } + return p.Properties +} + +func (p *Phone) GetLocation() *PhoneLocation { + if p == nil { + return nil + } + return p.Location +} + +func (p *Phone) GetWorkspaceId() string { + if p == nil { + return "" + } + return p.WorkspaceId +} + +func (p *Phone) GetErrors() []*PhoneErrorsItem { + if p == nil { + return nil + } + return p.Errors +} + +func (p *Phone) GetWarnings() []*PhoneWarningsItem { + if p == nil { + return nil + } + return p.Warnings +} + +func (p *Phone) GetCreatedAt() time.Time { + if p == nil { + return time.Time{} + } + return p.CreatedAt +} + +func (p *Phone) GetIsManaged() bool { + if p == nil { + return false + } + return p.IsManaged +} + +func (p *Phone) GetCustomMetadata() map[string]*PhoneCustomMetadataValue { + if p == nil { + return nil + } + return p.CustomMetadata +} + +func (p *Phone) GetCanRemotelyUnlock() *bool { + if p == nil { + return nil + } + return p.CanRemotelyUnlock +} + +func (p *Phone) GetCanRemotelyLock() *bool { + if p == nil { + return nil + } + return p.CanRemotelyLock } -func (n *Network) MarshalJSON() ([]byte, error) { - type embed Network - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*n), - CreatedAt: core.NewDateTime(n.CreatedAt), +func (p *Phone) GetCanProgramOfflineAccessCodes() *bool { + if p == nil { + return nil } - return json.Marshal(marshaler) + return p.CanProgramOfflineAccessCodes } -func (n *Network) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(n); err == nil { - return value +func (p *Phone) GetCanProgramOnlineAccessCodes() *bool { + if p == nil { + return nil } - return fmt.Sprintf("%#v", n) + return p.CanProgramOnlineAccessCodes } -type NoiseThreshold struct { - NoiseThresholdId string `json:"noise_threshold_id" url:"noise_threshold_id"` - DeviceId string `json:"device_id" url:"device_id"` - Name string `json:"name" url:"name"` - NoiseThresholdNrs *float64 `json:"noise_threshold_nrs,omitempty" url:"noise_threshold_nrs,omitempty"` - StartsDailyAt string `json:"starts_daily_at" url:"starts_daily_at"` - EndsDailyAt string `json:"ends_daily_at" url:"ends_daily_at"` - NoiseThresholdDecibels float64 `json:"noise_threshold_decibels" url:"noise_threshold_decibels"` - - _rawJSON json.RawMessage +func (p *Phone) GetCanSimulateRemoval() *bool { + if p == nil { + return nil + } + return p.CanSimulateRemoval } -func (n *NoiseThreshold) UnmarshalJSON(data []byte) error { - type unmarshaler NoiseThreshold - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func (p *Phone) GetCanSimulateConnection() *bool { + if p == nil { + return nil } - *n = NoiseThreshold(value) - n._rawJSON = json.RawMessage(data) - return nil + return p.CanSimulateConnection } -func (n *NoiseThreshold) String() string { - if len(n._rawJSON) > 0 { - if value, err := core.StringifyJSON(n._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(n); err == nil { - return value +func (p *Phone) GetCanSimulateDisconnection() *bool { + if p == nil { + return nil } - return fmt.Sprintf("%#v", n) + return p.CanSimulateDisconnection } -type Phone struct { - // Unique identifier for the device. - DeviceId string `json:"device_id" url:"device_id"` - DeviceType PhoneDeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` - // Optional nickname to describe the device, settable through Seam - Nickname *string `json:"nickname,omitempty" url:"nickname,omitempty"` - // Display name of the device, defaults to nickname (if it is set) or properties.appearance.name otherwise. Enables administrators and users to identify the device easily, especially when there are numerous devices. - DisplayName string `json:"display_name" url:"display_name"` - // Collection of capabilities that the device supports when connected to Seam. Values are "access_code," which indicates that the device can manage and utilize digital PIN codes for secure access; "lock," which indicates that the device controls a door locking mechanism, enabling the remote opening and closing of doors and other entry points; "noise_detection," which indicates that the device supports monitoring and responding to ambient noise levels; "thermostat," which indicates that the device can regulate and adjust indoor temperatures; and "battery," which indicates that the device can manage battery life and health. - CapabilitiesSupported []PhoneCapabilitiesSupportedItem `json:"capabilities_supported,omitempty" url:"capabilities_supported,omitempty"` - Properties *PhoneProperties `json:"properties,omitempty" url:"properties,omitempty"` - // Location information for the device. - Location *PhoneLocation `json:"location,omitempty" url:"location,omitempty"` - // Unique identifier for the Seam workspace associated with the device. - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - // Array of errors associated with the device. Each error object within the array contains two fields: "error_code" and "message." "error_code" is a string that uniquely identifies the type of error, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the error, offering insights into the issue and potentially how to rectify it. - Errors []*PhoneErrorsItem `json:"errors,omitempty" url:"errors,omitempty"` - // Array of warnings associated with the device. Each warning object within the array contains two fields: "warning_code" and "message." "warning_code" is a string that uniquely identifies the type of warning, enabling quick recognition and categorization of the issue. "message" provides a more detailed description of the warning, offering insights into the issue and potentially how to rectify it. - Warnings []*PhoneWarningsItem `json:"warnings,omitempty" url:"warnings,omitempty"` - // Date and time at which the device object was created. - CreatedAt time.Time `json:"created_at" url:"created_at"` - // Indicates whether Seam manages the device. - IsManaged bool `json:"is_managed" url:"is_managed"` - CustomMetadata map[string]*PhoneCustomMetadataValue `json:"custom_metadata,omitempty" url:"custom_metadata,omitempty"` - CanRemotelyUnlock *bool `json:"can_remotely_unlock,omitempty" url:"can_remotely_unlock,omitempty"` - CanRemotelyLock *bool `json:"can_remotely_lock,omitempty" url:"can_remotely_lock,omitempty"` - CanProgramOfflineAccessCodes *bool `json:"can_program_offline_access_codes,omitempty" url:"can_program_offline_access_codes,omitempty"` - CanProgramOnlineAccessCodes *bool `json:"can_program_online_access_codes,omitempty" url:"can_program_online_access_codes,omitempty"` - CanSimulateRemoval *bool `json:"can_simulate_removal,omitempty" url:"can_simulate_removal,omitempty"` - - _rawJSON json.RawMessage +func (p *Phone) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *Phone) UnmarshalJSON(data []byte) error { type embed Phone var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*p), } @@ -4679,7 +13918,12 @@ func (p *Phone) UnmarshalJSON(data []byte) error { } *p = Phone(unmarshaler.embed) p.CreatedAt = unmarshaler.CreatedAt.Time() - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } @@ -4687,21 +13931,21 @@ func (p *Phone) MarshalJSON() ([]byte, error) { type embed Phone var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*p), - CreatedAt: core.NewDateTime(p.CreatedAt), + CreatedAt: internal.NewDateTime(p.CreatedAt), } return json.Marshal(marshaler) } func (p *Phone) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -4742,29 +13986,44 @@ func (p PhoneCapabilitiesSupportedItem) Ptr() *PhoneCapabilitiesSupportedItem { } type PhoneCustomMetadataValue struct { - typeName string - String string - Boolean bool + String string + Boolean bool + + typ string } func NewPhoneCustomMetadataValueFromString(value string) *PhoneCustomMetadataValue { - return &PhoneCustomMetadataValue{typeName: "string", String: value} + return &PhoneCustomMetadataValue{typ: "String", String: value} } func NewPhoneCustomMetadataValueFromBoolean(value bool) *PhoneCustomMetadataValue { - return &PhoneCustomMetadataValue{typeName: "boolean", Boolean: value} + return &PhoneCustomMetadataValue{typ: "Boolean", Boolean: value} +} + +func (p *PhoneCustomMetadataValue) GetString() string { + if p == nil { + return "" + } + return p.String +} + +func (p *PhoneCustomMetadataValue) GetBoolean() bool { + if p == nil { + return false + } + return p.Boolean } func (p *PhoneCustomMetadataValue) UnmarshalJSON(data []byte) error { var valueString string if err := json.Unmarshal(data, &valueString); err == nil { - p.typeName = "string" + p.typ = "String" p.String = valueString return nil } var valueBoolean bool if err := json.Unmarshal(data, &valueBoolean); err == nil { - p.typeName = "boolean" + p.typ = "Boolean" p.Boolean = valueBoolean return nil } @@ -4772,14 +14031,13 @@ func (p *PhoneCustomMetadataValue) UnmarshalJSON(data []byte) error { } func (p PhoneCustomMetadataValue) MarshalJSON() ([]byte, error) { - switch p.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", p.typeName, p) - case "string": + if p.typ == "String" || p.String != "" { return json.Marshal(p.String) - case "boolean": + } + if p.typ == "Boolean" || p.Boolean != false { return json.Marshal(p.Boolean) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", p) } type PhoneCustomMetadataValueVisitor interface { @@ -4788,14 +14046,13 @@ type PhoneCustomMetadataValueVisitor interface { } func (p *PhoneCustomMetadataValue) Accept(visitor PhoneCustomMetadataValueVisitor) error { - switch p.typeName { - default: - return fmt.Errorf("invalid type %s in %T", p.typeName, p) - case "string": + if p.typ == "String" || p.String != "" { return visitor.VisitString(p.String) - case "boolean": + } + if p.typ == "Boolean" || p.Boolean != false { return visitor.VisitBoolean(p.Boolean) } + return fmt.Errorf("type %T does not include a non-empty union type", p) } type PhoneDeviceType string @@ -4824,7 +14081,26 @@ type PhoneErrorsItem struct { ErrorCode string `json:"error_code" url:"error_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhoneErrorsItem) GetErrorCode() string { + if p == nil { + return "" + } + return p.ErrorCode +} + +func (p *PhoneErrorsItem) GetMessage() string { + if p == nil { + return "" + } + return p.Message +} + +func (p *PhoneErrorsItem) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhoneErrorsItem) UnmarshalJSON(data []byte) error { @@ -4834,17 +14110,22 @@ func (p *PhoneErrorsItem) UnmarshalJSON(data []byte) error { return err } *p = PhoneErrorsItem(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhoneErrorsItem) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -4857,7 +14138,26 @@ type PhoneLocation struct { // Time zone of the device location. Timezone *string `json:"timezone,omitempty" url:"timezone,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhoneLocation) GetLocationName() *string { + if p == nil { + return nil + } + return p.LocationName +} + +func (p *PhoneLocation) GetTimezone() *string { + if p == nil { + return nil + } + return p.Timezone +} + +func (p *PhoneLocation) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhoneLocation) UnmarshalJSON(data []byte) error { @@ -4867,17 +14167,22 @@ func (p *PhoneLocation) UnmarshalJSON(data []byte) error { return err } *p = PhoneLocation(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhoneLocation) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -4908,7 +14213,19 @@ func (p PhoneOperatingSystem) Ptr() *PhoneOperatingSystem { type PhoneProperties struct { AssaAbloyCredentialServiceMetadata *PhonePropertiesAssaAbloyCredentialServiceMetadata `json:"assa_abloy_credential_service_metadata,omitempty" url:"assa_abloy_credential_service_metadata,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhoneProperties) GetAssaAbloyCredentialServiceMetadata() *PhonePropertiesAssaAbloyCredentialServiceMetadata { + if p == nil { + return nil + } + return p.AssaAbloyCredentialServiceMetadata +} + +func (p *PhoneProperties) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhoneProperties) UnmarshalJSON(data []byte) error { @@ -4918,17 +14235,22 @@ func (p *PhoneProperties) UnmarshalJSON(data []byte) error { return err } *p = PhoneProperties(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhoneProperties) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -4938,7 +14260,26 @@ type PhonePropertiesAssaAbloyCredentialServiceMetadata struct { HasActiveEndpoint bool `json:"has_active_endpoint" url:"has_active_endpoint"` Endpoints []*PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem `json:"endpoints,omitempty" url:"endpoints,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhonePropertiesAssaAbloyCredentialServiceMetadata) GetHasActiveEndpoint() bool { + if p == nil { + return false + } + return p.HasActiveEndpoint +} + +func (p *PhonePropertiesAssaAbloyCredentialServiceMetadata) GetEndpoints() []*PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem { + if p == nil { + return nil + } + return p.Endpoints +} + +func (p *PhonePropertiesAssaAbloyCredentialServiceMetadata) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhonePropertiesAssaAbloyCredentialServiceMetadata) UnmarshalJSON(data []byte) error { @@ -4948,17 +14289,22 @@ func (p *PhonePropertiesAssaAbloyCredentialServiceMetadata) UnmarshalJSON(data [ return err } *p = PhonePropertiesAssaAbloyCredentialServiceMetadata(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhonePropertiesAssaAbloyCredentialServiceMetadata) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -4968,7 +14314,26 @@ type PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem struct { EndpointId string `json:"endpoint_id" url:"endpoint_id"` IsActive bool `json:"is_active" url:"is_active"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) GetEndpointId() string { + if p == nil { + return "" + } + return p.EndpointId +} + +func (p *PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) GetIsActive() bool { + if p == nil { + return false + } + return p.IsActive +} + +func (p *PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) UnmarshalJSON(data []byte) error { @@ -4978,17 +14343,22 @@ func (p *PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) Unmarsh return err } *p = PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhonePropertiesAssaAbloyCredentialServiceMetadataEndpointsItem) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -4998,7 +14368,26 @@ type PhoneWarningsItem struct { WarningCode string `json:"warning_code" url:"warning_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (p *PhoneWarningsItem) GetWarningCode() string { + if p == nil { + return "" + } + return p.WarningCode +} + +func (p *PhoneWarningsItem) GetMessage() string { + if p == nil { + return "" + } + return p.Message +} + +func (p *PhoneWarningsItem) GetExtraProperties() map[string]interface{} { + return p.extraProperties } func (p *PhoneWarningsItem) UnmarshalJSON(data []byte) error { @@ -5008,17 +14397,22 @@ func (p *PhoneWarningsItem) UnmarshalJSON(data []byte) error { return err } *p = PhoneWarningsItem(value) - p._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *p) + if err != nil { + return err + } + p.extraProperties = extraProperties + p.rawJSON = json.RawMessage(data) return nil } func (p *PhoneWarningsItem) String() string { - if len(p._rawJSON) > 0 { - if value, err := core.StringifyJSON(p._rawJSON); err == nil { + if len(p.rawJSON) > 0 { + if value, err := internal.StringifyJSON(p.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(p); err == nil { + if value, err := internal.StringifyJSON(p); err == nil { return value } return fmt.Sprintf("%#v", p) @@ -5046,37 +14440,38 @@ func (p ProviderCategory) Ptr() *ProviderCategory { return &p } -type SelectionMode string +type ServiceHealth struct { + Service string `json:"service" url:"service"` + Status ServiceHealthStatus `json:"status" url:"status"` + Description string `json:"description" url:"description"` -const ( - SelectionModeNone SelectionMode = "none" - SelectionModeSingle SelectionMode = "single" - SelectionModeMultiple SelectionMode = "multiple" -) + extraProperties map[string]interface{} + rawJSON json.RawMessage +} -func NewSelectionModeFromString(s string) (SelectionMode, error) { - switch s { - case "none": - return SelectionModeNone, nil - case "single": - return SelectionModeSingle, nil - case "multiple": - return SelectionModeMultiple, nil - } - var t SelectionMode - return "", fmt.Errorf("%s is not a valid %T", s, t) +func (s *ServiceHealth) GetService() string { + if s == nil { + return "" + } + return s.Service } -func (s SelectionMode) Ptr() *SelectionMode { - return &s +func (s *ServiceHealth) GetStatus() ServiceHealthStatus { + if s == nil { + return "" + } + return s.Status } -type ServiceHealth struct { - Service string `json:"service" url:"service"` - Status ServiceHealthStatus `json:"status,omitempty" url:"status,omitempty"` - Description string `json:"description" url:"description"` +func (s *ServiceHealth) GetDescription() string { + if s == nil { + return "" + } + return s.Description +} - _rawJSON json.RawMessage +func (s *ServiceHealth) GetExtraProperties() map[string]interface{} { + return s.extraProperties } func (s *ServiceHealth) UnmarshalJSON(data []byte) error { @@ -5086,17 +14481,22 @@ func (s *ServiceHealth) UnmarshalJSON(data []byte) error { return err } *s = ServiceHealth(value) - s._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *s) + if err != nil { + return err + } + s.extraProperties = extraProperties + s.rawJSON = json.RawMessage(data) return nil } func (s *ServiceHealth) String() string { - if len(s._rawJSON) > 0 { - if value, err := core.StringifyJSON(s._rawJSON); err == nil { + if len(s.rawJSON) > 0 { + if value, err := internal.StringifyJSON(s.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(s); err == nil { + if value, err := internal.StringifyJSON(s); err == nil { return value } return fmt.Sprintf("%#v", s) @@ -5129,7 +14529,7 @@ func (s ServiceHealthStatus) Ptr() *ServiceHealthStatus { type UnmanagedAccessCode struct { // Nature of the access code. Values are "ongoing" for access codes that are active continuously until deactivated manually or "time_bound" for access codes that have a specific duration. - Type UnmanagedAccessCodeType `json:"type,omitempty" url:"type,omitempty"` + Type UnmanagedAccessCodeType `json:"type" url:"type"` // Unique identifier for the access code. AccessCodeId string `json:"access_code_id" url:"access_code_id"` // Unique identifier for the device associated with the access code. @@ -5149,20 +14549,103 @@ type UnmanagedAccessCode struct { EndsAt *time.Time `json:"ends_at,omitempty" url:"ends_at,omitempty"` status string - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedAccessCode) GetType() UnmanagedAccessCodeType { + if u == nil { + return "" + } + return u.Type +} + +func (u *UnmanagedAccessCode) GetAccessCodeId() string { + if u == nil { + return "" + } + return u.AccessCodeId +} + +func (u *UnmanagedAccessCode) GetDeviceId() string { + if u == nil { + return "" + } + return u.DeviceId +} + +func (u *UnmanagedAccessCode) GetName() *string { + if u == nil { + return nil + } + return u.Name +} + +func (u *UnmanagedAccessCode) GetCode() *string { + if u == nil { + return nil + } + return u.Code +} + +func (u *UnmanagedAccessCode) GetCreatedAt() time.Time { + if u == nil { + return time.Time{} + } + return u.CreatedAt +} + +func (u *UnmanagedAccessCode) GetErrors() interface{} { + if u == nil { + return nil + } + return u.Errors +} + +func (u *UnmanagedAccessCode) GetWarnings() interface{} { + if u == nil { + return nil + } + return u.Warnings +} + +func (u *UnmanagedAccessCode) GetIsManaged() bool { + if u == nil { + return false + } + return u.IsManaged +} + +func (u *UnmanagedAccessCode) GetStartsAt() *time.Time { + if u == nil { + return nil + } + return u.StartsAt +} + +func (u *UnmanagedAccessCode) GetEndsAt() *time.Time { + if u == nil { + return nil + } + return u.EndsAt } func (u *UnmanagedAccessCode) Status() string { return u.status } +func (u *UnmanagedAccessCode) GetExtraProperties() map[string]interface{} { + return u.extraProperties +} + func (u *UnmanagedAccessCode) UnmarshalJSON(data []byte) error { type embed UnmanagedAccessCode var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` - StartsAt *core.DateTime `json:"starts_at,omitempty"` - EndsAt *core.DateTime `json:"ends_at,omitempty"` + CreatedAt *internal.DateTime `json:"created_at"` + StartsAt *internal.DateTime `json:"starts_at,omitempty"` + EndsAt *internal.DateTime `json:"ends_at,omitempty"` + Status string `json:"status"` }{ embed: embed(*u), } @@ -5173,8 +14656,16 @@ func (u *UnmanagedAccessCode) UnmarshalJSON(data []byte) error { u.CreatedAt = unmarshaler.CreatedAt.Time() u.StartsAt = unmarshaler.StartsAt.TimePtr() u.EndsAt = unmarshaler.EndsAt.TimePtr() - u.status = "set" - u._rawJSON = json.RawMessage(data) + if unmarshaler.Status != "set" { + return fmt.Errorf("unexpected value for literal on type %T; expected %v got %v", u, "set", unmarshaler.Status) + } + u.status = unmarshaler.Status + extraProperties, err := internal.ExtractExtraProperties(data, *u, "status") + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } @@ -5182,27 +14673,27 @@ func (u *UnmanagedAccessCode) MarshalJSON() ([]byte, error) { type embed UnmanagedAccessCode var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` - StartsAt *core.DateTime `json:"starts_at,omitempty"` - EndsAt *core.DateTime `json:"ends_at,omitempty"` - Status string `json:"status"` + CreatedAt *internal.DateTime `json:"created_at"` + StartsAt *internal.DateTime `json:"starts_at,omitempty"` + EndsAt *internal.DateTime `json:"ends_at,omitempty"` + Status string `json:"status"` }{ embed: embed(*u), - CreatedAt: core.NewDateTime(u.CreatedAt), - StartsAt: core.NewOptionalDateTime(u.StartsAt), - EndsAt: core.NewOptionalDateTime(u.EndsAt), + CreatedAt: internal.NewDateTime(u.CreatedAt), + StartsAt: internal.NewOptionalDateTime(u.StartsAt), + EndsAt: internal.NewOptionalDateTime(u.EndsAt), Status: "set", } return json.Marshal(marshaler) } func (u *UnmanagedAccessCode) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5235,7 +14726,7 @@ type UnmanagedDevice struct { // Unique identifier for the device. DeviceId string `json:"device_id" url:"device_id"` // Type of the device. - DeviceType DeviceType `json:"device_type,omitempty" url:"device_type,omitempty"` + DeviceType DeviceType `json:"device_type" url:"device_type"` // Unique identifier for the account associated with the device. ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` // Collection of capabilities that the device supports when connected to Seam. Values are "access_code," which indicates that the device can manage and utilize digital PIN codes for secure access; "lock," which indicates that the device controls a door locking mechanism, enabling the remote opening and closing of doors and other entry points; "noise_detection," which indicates that the device supports monitoring and responding to ambient noise levels; "thermostat," which indicates that the device can regulate and adjust indoor temperatures; and "battery," which indicates that the device can manage battery life and health. @@ -5255,16 +14746,149 @@ type UnmanagedDevice struct { CanProgramOfflineAccessCodes *bool `json:"can_program_offline_access_codes,omitempty" url:"can_program_offline_access_codes,omitempty"` CanProgramOnlineAccessCodes *bool `json:"can_program_online_access_codes,omitempty" url:"can_program_online_access_codes,omitempty"` CanSimulateRemoval *bool `json:"can_simulate_removal,omitempty" url:"can_simulate_removal,omitempty"` + CanSimulateConnection *bool `json:"can_simulate_connection,omitempty" url:"can_simulate_connection,omitempty"` + CanSimulateDisconnection *bool `json:"can_simulate_disconnection,omitempty" url:"can_simulate_disconnection,omitempty"` DeviceProvider *UnmanagedDeviceDeviceProvider `json:"device_provider,omitempty" url:"device_provider,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDevice) GetDeviceId() string { + if u == nil { + return "" + } + return u.DeviceId +} + +func (u *UnmanagedDevice) GetDeviceType() DeviceType { + if u == nil { + return "" + } + return u.DeviceType +} + +func (u *UnmanagedDevice) GetConnectedAccountId() string { + if u == nil { + return "" + } + return u.ConnectedAccountId +} + +func (u *UnmanagedDevice) GetCapabilitiesSupported() []UnmanagedDeviceCapabilitiesSupportedItem { + if u == nil { + return nil + } + return u.CapabilitiesSupported +} + +func (u *UnmanagedDevice) GetWorkspaceId() string { + if u == nil { + return "" + } + return u.WorkspaceId +} + +func (u *UnmanagedDevice) GetErrors() []*UnmanagedDeviceErrorsItem { + if u == nil { + return nil + } + return u.Errors +} + +func (u *UnmanagedDevice) GetWarnings() []*UnmanagedDeviceWarningsItem { + if u == nil { + return nil + } + return u.Warnings +} + +func (u *UnmanagedDevice) GetCreatedAt() time.Time { + if u == nil { + return time.Time{} + } + return u.CreatedAt +} + +func (u *UnmanagedDevice) GetIsManaged() bool { + if u == nil { + return false + } + return u.IsManaged +} + +func (u *UnmanagedDevice) GetProperties() *UnmanagedDeviceProperties { + if u == nil { + return nil + } + return u.Properties +} + +func (u *UnmanagedDevice) GetCanRemotelyUnlock() *bool { + if u == nil { + return nil + } + return u.CanRemotelyUnlock +} + +func (u *UnmanagedDevice) GetCanRemotelyLock() *bool { + if u == nil { + return nil + } + return u.CanRemotelyLock +} + +func (u *UnmanagedDevice) GetCanProgramOfflineAccessCodes() *bool { + if u == nil { + return nil + } + return u.CanProgramOfflineAccessCodes +} + +func (u *UnmanagedDevice) GetCanProgramOnlineAccessCodes() *bool { + if u == nil { + return nil + } + return u.CanProgramOnlineAccessCodes +} + +func (u *UnmanagedDevice) GetCanSimulateRemoval() *bool { + if u == nil { + return nil + } + return u.CanSimulateRemoval +} + +func (u *UnmanagedDevice) GetCanSimulateConnection() *bool { + if u == nil { + return nil + } + return u.CanSimulateConnection +} + +func (u *UnmanagedDevice) GetCanSimulateDisconnection() *bool { + if u == nil { + return nil + } + return u.CanSimulateDisconnection +} + +func (u *UnmanagedDevice) GetDeviceProvider() *UnmanagedDeviceDeviceProvider { + if u == nil { + return nil + } + return u.DeviceProvider +} + +func (u *UnmanagedDevice) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDevice) UnmarshalJSON(data []byte) error { type embed UnmanagedDevice var unmarshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*u), } @@ -5273,7 +14897,12 @@ func (u *UnmanagedDevice) UnmarshalJSON(data []byte) error { } *u = UnmanagedDevice(unmarshaler.embed) u.CreatedAt = unmarshaler.CreatedAt.Time() - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } @@ -5281,21 +14910,21 @@ func (u *UnmanagedDevice) MarshalJSON() ([]byte, error) { type embed UnmanagedDevice var marshaler = struct { embed - CreatedAt *core.DateTime `json:"created_at"` + CreatedAt *internal.DateTime `json:"created_at"` }{ embed: embed(*u), - CreatedAt: core.NewDateTime(u.CreatedAt), + CreatedAt: internal.NewDateTime(u.CreatedAt), } return json.Marshal(marshaler) } func (u *UnmanagedDevice) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5338,7 +14967,19 @@ func (u UnmanagedDeviceCapabilitiesSupportedItem) Ptr() *UnmanagedDeviceCapabili type UnmanagedDeviceDeviceProvider struct { ProviderCategories interface{} `json:"provider_categories,omitempty" url:"provider_categories,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDeviceDeviceProvider) GetProviderCategories() interface{} { + if u == nil { + return nil + } + return u.ProviderCategories +} + +func (u *UnmanagedDeviceDeviceProvider) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDeviceDeviceProvider) UnmarshalJSON(data []byte) error { @@ -5348,17 +14989,22 @@ func (u *UnmanagedDeviceDeviceProvider) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedDeviceDeviceProvider(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDeviceDeviceProvider) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5368,7 +15014,26 @@ type UnmanagedDeviceErrorsItem struct { ErrorCode string `json:"error_code" url:"error_code"` Message string `json:"message" url:"message"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDeviceErrorsItem) GetErrorCode() string { + if u == nil { + return "" + } + return u.ErrorCode +} + +func (u *UnmanagedDeviceErrorsItem) GetMessage() string { + if u == nil { + return "" + } + return u.Message +} + +func (u *UnmanagedDeviceErrorsItem) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDeviceErrorsItem) UnmarshalJSON(data []byte) error { @@ -5378,17 +15043,22 @@ func (u *UnmanagedDeviceErrorsItem) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedDeviceErrorsItem(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDeviceErrorsItem) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5397,9 +15067,6 @@ func (u *UnmanagedDeviceErrorsItem) String() string { type UnmanagedDeviceProperties struct { // Represents the accessory keypad state. AccessoryKeypad *UnmanagedDevicePropertiesAccessoryKeypad `json:"accessory_keypad,omitempty" url:"accessory_keypad,omitempty"` - // --- - // deprecated: use device.display_name instead - // --- // Name of the device. Name string `json:"name" url:"name"` // Indicates whether the device is online. @@ -5420,7 +15087,89 @@ type UnmanagedDeviceProperties struct { OfflineAccessCodesEnabled *bool `json:"offline_access_codes_enabled,omitempty" url:"offline_access_codes_enabled,omitempty"` Model *UnmanagedDevicePropertiesModel `json:"model,omitempty" url:"model,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDeviceProperties) GetAccessoryKeypad() *UnmanagedDevicePropertiesAccessoryKeypad { + if u == nil { + return nil + } + return u.AccessoryKeypad +} + +func (u *UnmanagedDeviceProperties) GetName() string { + if u == nil { + return "" + } + return u.Name +} + +func (u *UnmanagedDeviceProperties) GetOnline() bool { + if u == nil { + return false + } + return u.Online +} + +func (u *UnmanagedDeviceProperties) GetManufacturer() *string { + if u == nil { + return nil + } + return u.Manufacturer +} + +func (u *UnmanagedDeviceProperties) GetImageUrl() *string { + if u == nil { + return nil + } + return u.ImageUrl +} + +func (u *UnmanagedDeviceProperties) GetImageAltText() *string { + if u == nil { + return nil + } + return u.ImageAltText +} + +func (u *UnmanagedDeviceProperties) GetBatteryLevel() *float64 { + if u == nil { + return nil + } + return u.BatteryLevel +} + +func (u *UnmanagedDeviceProperties) GetBattery() *UnmanagedDevicePropertiesBattery { + if u == nil { + return nil + } + return u.Battery +} + +func (u *UnmanagedDeviceProperties) GetOnlineAccessCodesEnabled() *bool { + if u == nil { + return nil + } + return u.OnlineAccessCodesEnabled +} + +func (u *UnmanagedDeviceProperties) GetOfflineAccessCodesEnabled() *bool { + if u == nil { + return nil + } + return u.OfflineAccessCodesEnabled +} + +func (u *UnmanagedDeviceProperties) GetModel() *UnmanagedDevicePropertiesModel { + if u == nil { + return nil + } + return u.Model +} + +func (u *UnmanagedDeviceProperties) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDeviceProperties) UnmarshalJSON(data []byte) error { @@ -5430,17 +15179,22 @@ func (u *UnmanagedDeviceProperties) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedDeviceProperties(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDeviceProperties) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5453,7 +15207,26 @@ type UnmanagedDevicePropertiesAccessoryKeypad struct { // Indicates if the keypad battery properties. Battery *UnmanagedDevicePropertiesAccessoryKeypadBattery `json:"battery,omitempty" url:"battery,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDevicePropertiesAccessoryKeypad) GetIsConnected() bool { + if u == nil { + return false + } + return u.IsConnected +} + +func (u *UnmanagedDevicePropertiesAccessoryKeypad) GetBattery() *UnmanagedDevicePropertiesAccessoryKeypadBattery { + if u == nil { + return nil + } + return u.Battery +} + +func (u *UnmanagedDevicePropertiesAccessoryKeypad) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDevicePropertiesAccessoryKeypad) UnmarshalJSON(data []byte) error { @@ -5463,17 +15236,22 @@ func (u *UnmanagedDevicePropertiesAccessoryKeypad) UnmarshalJSON(data []byte) er return err } *u = UnmanagedDevicePropertiesAccessoryKeypad(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDevicePropertiesAccessoryKeypad) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5483,7 +15261,19 @@ func (u *UnmanagedDevicePropertiesAccessoryKeypad) String() string { type UnmanagedDevicePropertiesAccessoryKeypadBattery struct { Level float64 `json:"level" url:"level"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDevicePropertiesAccessoryKeypadBattery) GetLevel() float64 { + if u == nil { + return 0 + } + return u.Level +} + +func (u *UnmanagedDevicePropertiesAccessoryKeypadBattery) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDevicePropertiesAccessoryKeypadBattery) UnmarshalJSON(data []byte) error { @@ -5493,17 +15283,22 @@ func (u *UnmanagedDevicePropertiesAccessoryKeypadBattery) UnmarshalJSON(data []b return err } *u = UnmanagedDevicePropertiesAccessoryKeypadBattery(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDevicePropertiesAccessoryKeypadBattery) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5512,9 +15307,28 @@ func (u *UnmanagedDevicePropertiesAccessoryKeypadBattery) String() string { // Represents the current status of the battery charge level. Values are "critical," which indicates an extremely low level, suggesting imminent shutdown or an urgent need for charging; "low," which signifies that the battery is under the preferred threshold and should be charged soon; "good," which denotes a satisfactory charge level, adequate for normal use without the immediate need for recharging; and "full," which represents a battery that is fully charged, providing the maximum duration of usage. type UnmanagedDevicePropertiesBattery struct { Level float64 `json:"level" url:"level"` - Status UnmanagedDevicePropertiesBatteryStatus `json:"status,omitempty" url:"status,omitempty"` + Status UnmanagedDevicePropertiesBatteryStatus `json:"status" url:"status"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UnmanagedDevicePropertiesBattery) GetLevel() float64 { + if u == nil { + return 0 + } + return u.Level +} - _rawJSON json.RawMessage +func (u *UnmanagedDevicePropertiesBattery) GetStatus() UnmanagedDevicePropertiesBatteryStatus { + if u == nil { + return "" + } + return u.Status +} + +func (u *UnmanagedDevicePropertiesBattery) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UnmanagedDevicePropertiesBattery) UnmarshalJSON(data []byte) error { @@ -5524,17 +15338,22 @@ func (u *UnmanagedDevicePropertiesBattery) UnmarshalJSON(data []byte) error { return err } *u = UnmanagedDevicePropertiesBattery(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UnmanagedDevicePropertiesBattery) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -5581,322 +15400,142 @@ type UnmanagedDevicePropertiesModel struct { OfflineAccessCodesSupported *bool `json:"offline_access_codes_supported,omitempty" url:"offline_access_codes_supported,omitempty"` // Indicates whether the device supports online access codes. OnlineAccessCodesSupported *bool `json:"online_access_codes_supported,omitempty" url:"online_access_codes_supported,omitempty"` - // Indicates whether the device supports an accessory keypad. - AccessoryKeypadSupported *bool `json:"accessory_keypad_supported,omitempty" url:"accessory_keypad_supported,omitempty"` - - _rawJSON json.RawMessage -} - -func (u *UnmanagedDevicePropertiesModel) UnmarshalJSON(data []byte) error { - type unmarshaler UnmanagedDevicePropertiesModel - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *u = UnmanagedDevicePropertiesModel(value) - u._rawJSON = json.RawMessage(data) - return nil -} - -func (u *UnmanagedDevicePropertiesModel) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(u); err == nil { - return value - } - return fmt.Sprintf("%#v", u) -} - -type UnmanagedDeviceWarningsItem struct { - WarningCode string `json:"warning_code" url:"warning_code"` - Message string `json:"message" url:"message"` + AccessoryKeypadSupported *bool `json:"accessory_keypad_supported,omitempty" url:"accessory_keypad_supported,omitempty"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (u *UnmanagedDeviceWarningsItem) UnmarshalJSON(data []byte) error { - type unmarshaler UnmanagedDeviceWarningsItem - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func (u *UnmanagedDevicePropertiesModel) GetCanConnectAccessoryKeypad() *bool { + if u == nil { + return nil } - *u = UnmanagedDeviceWarningsItem(value) - u._rawJSON = json.RawMessage(data) - return nil + return u.CanConnectAccessoryKeypad } -func (u *UnmanagedDeviceWarningsItem) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(u); err == nil { - return value +func (u *UnmanagedDevicePropertiesModel) GetDisplayName() string { + if u == nil { + return "" } - return fmt.Sprintf("%#v", u) + return u.DisplayName } -type UserIdentity struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - UserIdentityKey *string `json:"user_identity_key,omitempty" url:"user_identity_key,omitempty"` - EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` - PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` - DisplayName string `json:"display_name" url:"display_name"` - FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - - _rawJSON json.RawMessage -} - -func (u *UserIdentity) UnmarshalJSON(data []byte) error { - type embed UserIdentity - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*u), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err +func (u *UnmanagedDevicePropertiesModel) GetManufacturerDisplayName() string { + if u == nil { + return "" } - *u = UserIdentity(unmarshaler.embed) - u.CreatedAt = unmarshaler.CreatedAt.Time() - u._rawJSON = json.RawMessage(data) - return nil + return u.ManufacturerDisplayName } -func (u *UserIdentity) MarshalJSON() ([]byte, error) { - type embed UserIdentity - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*u), - CreatedAt: core.NewDateTime(u.CreatedAt), +func (u *UnmanagedDevicePropertiesModel) GetHasBuiltInKeypad() *bool { + if u == nil { + return nil } - return json.Marshal(marshaler) + return u.HasBuiltInKeypad } -func (u *UserIdentity) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(u); err == nil { - return value +func (u *UnmanagedDevicePropertiesModel) GetOfflineAccessCodesSupported() *bool { + if u == nil { + return nil } - return fmt.Sprintf("%#v", u) + return u.OfflineAccessCodesSupported } -type Webhook struct { - WebhookId string `json:"webhook_id" url:"webhook_id"` - Url string `json:"url" url:"url"` - EventTypes []string `json:"event_types,omitempty" url:"event_types,omitempty"` - Secret *string `json:"secret,omitempty" url:"secret,omitempty"` - - _rawJSON json.RawMessage -} - -func (w *Webhook) UnmarshalJSON(data []byte) error { - type unmarshaler Webhook - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err +func (u *UnmanagedDevicePropertiesModel) GetOnlineAccessCodesSupported() *bool { + if u == nil { + return nil } - *w = Webhook(value) - w._rawJSON = json.RawMessage(data) - return nil + return u.OnlineAccessCodesSupported } -func (w *Webhook) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(w); err == nil { - return value +func (u *UnmanagedDevicePropertiesModel) GetAccessoryKeypadSupported() *bool { + if u == nil { + return nil } - return fmt.Sprintf("%#v", w) + return u.AccessoryKeypadSupported } -type Workspace struct { - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - Name string `json:"name" url:"name"` - IsSandbox bool `json:"is_sandbox" url:"is_sandbox"` - ConnectPartnerName *string `json:"connect_partner_name,omitempty" url:"connect_partner_name,omitempty"` - - _rawJSON json.RawMessage +func (u *UnmanagedDevicePropertiesModel) GetExtraProperties() map[string]interface{} { + return u.extraProperties } -func (w *Workspace) UnmarshalJSON(data []byte) error { - type unmarshaler Workspace +func (u *UnmanagedDevicePropertiesModel) UnmarshalJSON(data []byte) error { + type unmarshaler UnmanagedDevicePropertiesModel var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *w = Workspace(value) - w._rawJSON = json.RawMessage(data) - return nil -} - -func (w *Workspace) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(w); err == nil { - return value - } - return fmt.Sprintf("%#v", w) -} - -type ConnectedAccountsGetRequestConnectedAccountId struct { - ConnectedAccountId string `json:"connected_account_id" url:"connected_account_id"` - - _rawJSON json.RawMessage -} - -func (c *ConnectedAccountsGetRequestConnectedAccountId) UnmarshalJSON(data []byte) error { - type unmarshaler ConnectedAccountsGetRequestConnectedAccountId - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { + *u = UnmanagedDevicePropertiesModel(value) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { return err } - *c = ConnectedAccountsGetRequestConnectedAccountId(value) - c._rawJSON = json.RawMessage(data) + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } -func (c *ConnectedAccountsGetRequestConnectedAccountId) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { +func (u *UnmanagedDevicePropertiesModel) String() string { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(c); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } - return fmt.Sprintf("%#v", c) + return fmt.Sprintf("%#v", u) } -type ConnectedAccountsGetRequestEmail struct { - Email string `json:"email" url:"email"` - - _rawJSON json.RawMessage -} +type UnmanagedDeviceWarningsItem struct { + WarningCode string `json:"warning_code" url:"warning_code"` + Message string `json:"message" url:"message"` -func (c *ConnectedAccountsGetRequestEmail) UnmarshalJSON(data []byte) error { - type unmarshaler ConnectedAccountsGetRequestEmail - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { - return err - } - *c = ConnectedAccountsGetRequestEmail(value) - c._rawJSON = json.RawMessage(data) - return nil + extraProperties map[string]interface{} + rawJSON json.RawMessage } -func (c *ConnectedAccountsGetRequestEmail) String() string { - if len(c._rawJSON) > 0 { - if value, err := core.StringifyJSON(c._rawJSON); err == nil { - return value - } +func (u *UnmanagedDeviceWarningsItem) GetWarningCode() string { + if u == nil { + return "" } - if value, err := core.StringifyJSON(c); err == nil { - return value - } - return fmt.Sprintf("%#v", c) + return u.WarningCode } -type ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting string - -const ( - ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingOff ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "off" - ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeat ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "heat" - ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingCool ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "cool" - ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeatCool ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting = "heat_cool" -) - -func NewThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingFromString(s string) (ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting, error) { - switch s { - case "off": - return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingOff, nil - case "heat": - return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeat, nil - case "cool": - return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingCool, nil - case "heat_cool": - return ThermostatsUpdateRequestDefaultClimateSettingHvacModeSettingHeatCool, nil +func (u *UnmanagedDeviceWarningsItem) GetMessage() string { + if u == nil { + return "" } - var t ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting - return "", fmt.Errorf("%s is not a valid %T", s, t) -} - -func (t ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting) Ptr() *ThermostatsUpdateRequestDefaultClimateSettingHvacModeSetting { - return &t + return u.Message } -type UserIdentitiesGetRequestUserIdentityId struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - - _rawJSON json.RawMessage +func (u *UnmanagedDeviceWarningsItem) GetExtraProperties() map[string]interface{} { + return u.extraProperties } -func (u *UserIdentitiesGetRequestUserIdentityId) UnmarshalJSON(data []byte) error { - type unmarshaler UserIdentitiesGetRequestUserIdentityId +func (u *UnmanagedDeviceWarningsItem) UnmarshalJSON(data []byte) error { + type unmarshaler UnmanagedDeviceWarningsItem var value unmarshaler if err := json.Unmarshal(data, &value); err != nil { return err } - *u = UserIdentitiesGetRequestUserIdentityId(value) - u._rawJSON = json.RawMessage(data) - return nil -} - -func (u *UserIdentitiesGetRequestUserIdentityId) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(u); err == nil { - return value - } - return fmt.Sprintf("%#v", u) -} - -type UserIdentitiesGetRequestUserIdentityKey struct { - UserIdentityKey string `json:"user_identity_key" url:"user_identity_key"` - - _rawJSON json.RawMessage -} - -func (u *UserIdentitiesGetRequestUserIdentityKey) UnmarshalJSON(data []byte) error { - type unmarshaler UserIdentitiesGetRequestUserIdentityKey - var value unmarshaler - if err := json.Unmarshal(data, &value); err != nil { + *u = UnmanagedDeviceWarningsItem(value) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { return err } - *u = UserIdentitiesGetRequestUserIdentityKey(value) - u._rawJSON = json.RawMessage(data) + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } -func (u *UserIdentitiesGetRequestUserIdentityKey) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { +func (u *UnmanagedDeviceWarningsItem) String() string { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) diff --git a/user_identities.go b/user_identities.go index 34a55be..b3926d9 100644 --- a/user_identities.go +++ b/user_identities.go @@ -5,60 +5,193 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" + time "time" ) type UserIdentitiesAddAcsUserRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UserIdentitiesCreateRequest struct { - UserIdentityKey *string `json:"user_identity_key,omitempty" url:"user_identity_key,omitempty"` - EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` - PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` - FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` + UserIdentityKey *string `json:"user_identity_key,omitempty" url:"-"` + EmailAddress *string `json:"email_address,omitempty" url:"-"` + PhoneNumber *string `json:"phone_number,omitempty" url:"-"` + FullName *string `json:"full_name,omitempty" url:"-"` } type UserIdentitiesDeleteRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` } type UserIdentitiesGrantAccessToDeviceRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - DeviceId string `json:"device_id" url:"device_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` + DeviceId string `json:"device_id" url:"-"` } type UserIdentitiesListRequest struct { - CredentialManagerAcsSystemId *string `json:"credential_manager_acs_system_id,omitempty" url:"credential_manager_acs_system_id,omitempty"` + CredentialManagerAcsSystemId *string `json:"credential_manager_acs_system_id,omitempty" url:"-"` } type UserIdentitiesListAccessibleDevicesRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` } type UserIdentitiesListAcsSystemsRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` } type UserIdentitiesListAcsUsersRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` } type UserIdentitiesRemoveAcsUserRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - AcsUserId string `json:"acs_user_id" url:"acs_user_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` + AcsUserId string `json:"acs_user_id" url:"-"` } type UserIdentitiesRevokeAccessToDeviceRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - DeviceId string `json:"device_id" url:"device_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` + DeviceId string `json:"device_id" url:"-"` +} + +type UserIdentity struct { + UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + UserIdentityKey *string `json:"user_identity_key,omitempty" url:"user_identity_key,omitempty"` + EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` + PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` + DisplayName string `json:"display_name" url:"display_name"` + FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentity) GetUserIdentityId() string { + if u == nil { + return "" + } + return u.UserIdentityId +} + +func (u *UserIdentity) GetUserIdentityKey() *string { + if u == nil { + return nil + } + return u.UserIdentityKey +} + +func (u *UserIdentity) GetEmailAddress() *string { + if u == nil { + return nil + } + return u.EmailAddress +} + +func (u *UserIdentity) GetPhoneNumber() *string { + if u == nil { + return nil + } + return u.PhoneNumber +} + +func (u *UserIdentity) GetDisplayName() string { + if u == nil { + return "" + } + return u.DisplayName +} + +func (u *UserIdentity) GetFullName() *string { + if u == nil { + return nil + } + return u.FullName +} + +func (u *UserIdentity) GetCreatedAt() time.Time { + if u == nil { + return time.Time{} + } + return u.CreatedAt +} + +func (u *UserIdentity) GetWorkspaceId() string { + if u == nil { + return "" + } + return u.WorkspaceId +} + +func (u *UserIdentity) GetExtraProperties() map[string]interface{} { + return u.extraProperties +} + +func (u *UserIdentity) UnmarshalJSON(data []byte) error { + type embed UserIdentity + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*u), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *u = UserIdentity(unmarshaler.embed) + u.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) + return nil +} + +func (u *UserIdentity) MarshalJSON() ([]byte, error) { + type embed UserIdentity + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*u), + CreatedAt: internal.NewDateTime(u.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (u *UserIdentity) String() string { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(u); err == nil { + return value + } + return fmt.Sprintf("%#v", u) } type UserIdentitiesAddAcsUserResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesAddAcsUserResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesAddAcsUserResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesAddAcsUserResponse) UnmarshalJSON(data []byte) error { @@ -68,17 +201,22 @@ func (u *UserIdentitiesAddAcsUserResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesAddAcsUserResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesAddAcsUserResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -88,7 +226,26 @@ type UserIdentitiesCreateResponse struct { UserIdentity *UserIdentity `json:"user_identity,omitempty" url:"user_identity,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesCreateResponse) GetUserIdentity() *UserIdentity { + if u == nil { + return nil + } + return u.UserIdentity +} + +func (u *UserIdentitiesCreateResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesCreateResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesCreateResponse) UnmarshalJSON(data []byte) error { @@ -98,17 +255,22 @@ func (u *UserIdentitiesCreateResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesCreateResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesCreateResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -117,7 +279,19 @@ func (u *UserIdentitiesCreateResponse) String() string { type UserIdentitiesDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesDeleteResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesDeleteResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesDeleteResponse) UnmarshalJSON(data []byte) error { @@ -127,46 +301,66 @@ func (u *UserIdentitiesDeleteResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesDeleteResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesDeleteResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UserIdentitiesGetRequest struct { - typeName string UserIdentitiesGetRequestUserIdentityId *UserIdentitiesGetRequestUserIdentityId UserIdentitiesGetRequestUserIdentityKey *UserIdentitiesGetRequestUserIdentityKey + + typ string } func NewUserIdentitiesGetRequestFromUserIdentitiesGetRequestUserIdentityId(value *UserIdentitiesGetRequestUserIdentityId) *UserIdentitiesGetRequest { - return &UserIdentitiesGetRequest{typeName: "userIdentitiesGetRequestUserIdentityId", UserIdentitiesGetRequestUserIdentityId: value} + return &UserIdentitiesGetRequest{typ: "UserIdentitiesGetRequestUserIdentityId", UserIdentitiesGetRequestUserIdentityId: value} } func NewUserIdentitiesGetRequestFromUserIdentitiesGetRequestUserIdentityKey(value *UserIdentitiesGetRequestUserIdentityKey) *UserIdentitiesGetRequest { - return &UserIdentitiesGetRequest{typeName: "userIdentitiesGetRequestUserIdentityKey", UserIdentitiesGetRequestUserIdentityKey: value} + return &UserIdentitiesGetRequest{typ: "UserIdentitiesGetRequestUserIdentityKey", UserIdentitiesGetRequestUserIdentityKey: value} +} + +func (u *UserIdentitiesGetRequest) GetUserIdentitiesGetRequestUserIdentityId() *UserIdentitiesGetRequestUserIdentityId { + if u == nil { + return nil + } + return u.UserIdentitiesGetRequestUserIdentityId +} + +func (u *UserIdentitiesGetRequest) GetUserIdentitiesGetRequestUserIdentityKey() *UserIdentitiesGetRequestUserIdentityKey { + if u == nil { + return nil + } + return u.UserIdentitiesGetRequestUserIdentityKey } func (u *UserIdentitiesGetRequest) UnmarshalJSON(data []byte) error { valueUserIdentitiesGetRequestUserIdentityId := new(UserIdentitiesGetRequestUserIdentityId) if err := json.Unmarshal(data, &valueUserIdentitiesGetRequestUserIdentityId); err == nil { - u.typeName = "userIdentitiesGetRequestUserIdentityId" + u.typ = "UserIdentitiesGetRequestUserIdentityId" u.UserIdentitiesGetRequestUserIdentityId = valueUserIdentitiesGetRequestUserIdentityId return nil } valueUserIdentitiesGetRequestUserIdentityKey := new(UserIdentitiesGetRequestUserIdentityKey) if err := json.Unmarshal(data, &valueUserIdentitiesGetRequestUserIdentityKey); err == nil { - u.typeName = "userIdentitiesGetRequestUserIdentityKey" + u.typ = "UserIdentitiesGetRequestUserIdentityKey" u.UserIdentitiesGetRequestUserIdentityKey = valueUserIdentitiesGetRequestUserIdentityKey return nil } @@ -174,14 +368,13 @@ func (u *UserIdentitiesGetRequest) UnmarshalJSON(data []byte) error { } func (u UserIdentitiesGetRequest) MarshalJSON() ([]byte, error) { - switch u.typeName { - default: - return nil, fmt.Errorf("invalid type %s in %T", u.typeName, u) - case "userIdentitiesGetRequestUserIdentityId": + if u.typ == "UserIdentitiesGetRequestUserIdentityId" || u.UserIdentitiesGetRequestUserIdentityId != nil { return json.Marshal(u.UserIdentitiesGetRequestUserIdentityId) - case "userIdentitiesGetRequestUserIdentityKey": + } + if u.typ == "UserIdentitiesGetRequestUserIdentityKey" || u.UserIdentitiesGetRequestUserIdentityKey != nil { return json.Marshal(u.UserIdentitiesGetRequestUserIdentityKey) } + return nil, fmt.Errorf("type %T does not include a non-empty union type", u) } type UserIdentitiesGetRequestVisitor interface { @@ -190,21 +383,131 @@ type UserIdentitiesGetRequestVisitor interface { } func (u *UserIdentitiesGetRequest) Accept(visitor UserIdentitiesGetRequestVisitor) error { - switch u.typeName { - default: - return fmt.Errorf("invalid type %s in %T", u.typeName, u) - case "userIdentitiesGetRequestUserIdentityId": + if u.typ == "UserIdentitiesGetRequestUserIdentityId" || u.UserIdentitiesGetRequestUserIdentityId != nil { return visitor.VisitUserIdentitiesGetRequestUserIdentityId(u.UserIdentitiesGetRequestUserIdentityId) - case "userIdentitiesGetRequestUserIdentityKey": + } + if u.typ == "UserIdentitiesGetRequestUserIdentityKey" || u.UserIdentitiesGetRequestUserIdentityKey != nil { return visitor.VisitUserIdentitiesGetRequestUserIdentityKey(u.UserIdentitiesGetRequestUserIdentityKey) } + return fmt.Errorf("type %T does not include a non-empty union type", u) +} + +type UserIdentitiesGetRequestUserIdentityId struct { + UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesGetRequestUserIdentityId) GetUserIdentityId() string { + if u == nil { + return "" + } + return u.UserIdentityId +} + +func (u *UserIdentitiesGetRequestUserIdentityId) GetExtraProperties() map[string]interface{} { + return u.extraProperties +} + +func (u *UserIdentitiesGetRequestUserIdentityId) UnmarshalJSON(data []byte) error { + type unmarshaler UserIdentitiesGetRequestUserIdentityId + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *u = UserIdentitiesGetRequestUserIdentityId(value) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) + return nil +} + +func (u *UserIdentitiesGetRequestUserIdentityId) String() string { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(u); err == nil { + return value + } + return fmt.Sprintf("%#v", u) +} + +type UserIdentitiesGetRequestUserIdentityKey struct { + UserIdentityKey string `json:"user_identity_key" url:"user_identity_key"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesGetRequestUserIdentityKey) GetUserIdentityKey() string { + if u == nil { + return "" + } + return u.UserIdentityKey +} + +func (u *UserIdentitiesGetRequestUserIdentityKey) GetExtraProperties() map[string]interface{} { + return u.extraProperties +} + +func (u *UserIdentitiesGetRequestUserIdentityKey) UnmarshalJSON(data []byte) error { + type unmarshaler UserIdentitiesGetRequestUserIdentityKey + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *u = UserIdentitiesGetRequestUserIdentityKey(value) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) + return nil +} + +func (u *UserIdentitiesGetRequestUserIdentityKey) String() string { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(u); err == nil { + return value + } + return fmt.Sprintf("%#v", u) } type UserIdentitiesGetResponse struct { UserIdentity *UserIdentity `json:"user_identity,omitempty" url:"user_identity,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesGetResponse) GetUserIdentity() *UserIdentity { + if u == nil { + return nil + } + return u.UserIdentity +} + +func (u *UserIdentitiesGetResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesGetResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesGetResponse) UnmarshalJSON(data []byte) error { @@ -214,17 +517,22 @@ func (u *UserIdentitiesGetResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesGetResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesGetResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -233,7 +541,19 @@ func (u *UserIdentitiesGetResponse) String() string { type UserIdentitiesGrantAccessToDeviceResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesGrantAccessToDeviceResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesGrantAccessToDeviceResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesGrantAccessToDeviceResponse) UnmarshalJSON(data []byte) error { @@ -243,31 +563,59 @@ func (u *UserIdentitiesGrantAccessToDeviceResponse) UnmarshalJSON(data []byte) e return err } *u = UserIdentitiesGrantAccessToDeviceResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesGrantAccessToDeviceResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UserIdentitiesListAccessibleDevicesResponse struct { - Devices []*Device `json:"devices,omitempty" url:"devices,omitempty"` - // --- - // deprecated: use devices. - // --- + Devices []*Device `json:"devices,omitempty" url:"devices,omitempty"` AccessibleDevices []*Device `json:"accessible_devices,omitempty" url:"accessible_devices,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesListAccessibleDevicesResponse) GetDevices() []*Device { + if u == nil { + return nil + } + return u.Devices +} + +func (u *UserIdentitiesListAccessibleDevicesResponse) GetAccessibleDevices() []*Device { + if u == nil { + return nil + } + return u.AccessibleDevices +} + +func (u *UserIdentitiesListAccessibleDevicesResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesListAccessibleDevicesResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesListAccessibleDevicesResponse) UnmarshalJSON(data []byte) error { @@ -277,17 +625,22 @@ func (u *UserIdentitiesListAccessibleDevicesResponse) UnmarshalJSON(data []byte) return err } *u = UserIdentitiesListAccessibleDevicesResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesListAccessibleDevicesResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -297,7 +650,26 @@ type UserIdentitiesListAcsSystemsResponse struct { AcsSystems []*AcsSystem `json:"acs_systems,omitempty" url:"acs_systems,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesListAcsSystemsResponse) GetAcsSystems() []*AcsSystem { + if u == nil { + return nil + } + return u.AcsSystems +} + +func (u *UserIdentitiesListAcsSystemsResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesListAcsSystemsResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesListAcsSystemsResponse) UnmarshalJSON(data []byte) error { @@ -307,17 +679,22 @@ func (u *UserIdentitiesListAcsSystemsResponse) UnmarshalJSON(data []byte) error return err } *u = UserIdentitiesListAcsSystemsResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesListAcsSystemsResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -327,7 +704,26 @@ type UserIdentitiesListAcsUsersResponse struct { AcsUsers []*AcsUser `json:"acs_users,omitempty" url:"acs_users,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesListAcsUsersResponse) GetAcsUsers() []*AcsUser { + if u == nil { + return nil + } + return u.AcsUsers +} + +func (u *UserIdentitiesListAcsUsersResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesListAcsUsersResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesListAcsUsersResponse) UnmarshalJSON(data []byte) error { @@ -337,17 +733,22 @@ func (u *UserIdentitiesListAcsUsersResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesListAcsUsersResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesListAcsUsersResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -357,7 +758,26 @@ type UserIdentitiesListResponse struct { UserIdentities []*UserIdentity `json:"user_identities,omitempty" url:"user_identities,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesListResponse) GetUserIdentities() []*UserIdentity { + if u == nil { + return nil + } + return u.UserIdentities +} + +func (u *UserIdentitiesListResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesListResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesListResponse) UnmarshalJSON(data []byte) error { @@ -367,17 +787,22 @@ func (u *UserIdentitiesListResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesListResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesListResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -386,7 +811,19 @@ func (u *UserIdentitiesListResponse) String() string { type UserIdentitiesRemoveAcsUserResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesRemoveAcsUserResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesRemoveAcsUserResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesRemoveAcsUserResponse) UnmarshalJSON(data []byte) error { @@ -396,17 +833,22 @@ func (u *UserIdentitiesRemoveAcsUserResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesRemoveAcsUserResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesRemoveAcsUserResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -415,7 +857,19 @@ func (u *UserIdentitiesRemoveAcsUserResponse) String() string { type UserIdentitiesRevokeAccessToDeviceResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesRevokeAccessToDeviceResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesRevokeAccessToDeviceResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesRevokeAccessToDeviceResponse) UnmarshalJSON(data []byte) error { @@ -425,17 +879,22 @@ func (u *UserIdentitiesRevokeAccessToDeviceResponse) UnmarshalJSON(data []byte) return err } *u = UserIdentitiesRevokeAccessToDeviceResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesRevokeAccessToDeviceResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) @@ -444,7 +903,19 @@ func (u *UserIdentitiesRevokeAccessToDeviceResponse) String() string { type UserIdentitiesUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (u *UserIdentitiesUpdateResponse) GetOk() bool { + if u == nil { + return false + } + return u.Ok +} + +func (u *UserIdentitiesUpdateResponse) GetExtraProperties() map[string]interface{} { + return u.extraProperties } func (u *UserIdentitiesUpdateResponse) UnmarshalJSON(data []byte) error { @@ -454,26 +925,31 @@ func (u *UserIdentitiesUpdateResponse) UnmarshalJSON(data []byte) error { return err } *u = UserIdentitiesUpdateResponse(value) - u._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *u) + if err != nil { + return err + } + u.extraProperties = extraProperties + u.rawJSON = json.RawMessage(data) return nil } func (u *UserIdentitiesUpdateResponse) String() string { - if len(u._rawJSON) > 0 { - if value, err := core.StringifyJSON(u._rawJSON); err == nil { + if len(u.rawJSON) > 0 { + if value, err := internal.StringifyJSON(u.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(u); err == nil { + if value, err := internal.StringifyJSON(u); err == nil { return value } return fmt.Sprintf("%#v", u) } type UserIdentitiesUpdateRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - UserIdentityKey *string `json:"user_identity_key,omitempty" url:"user_identity_key,omitempty"` - EmailAddress *string `json:"email_address,omitempty" url:"email_address,omitempty"` - PhoneNumber *string `json:"phone_number,omitempty" url:"phone_number,omitempty"` - FullName *string `json:"full_name,omitempty" url:"full_name,omitempty"` + UserIdentityId string `json:"user_identity_id" url:"-"` + UserIdentityKey *string `json:"user_identity_key,omitempty" url:"-"` + EmailAddress *string `json:"email_address,omitempty" url:"-"` + PhoneNumber *string `json:"phone_number,omitempty" url:"-"` + FullName *string `json:"full_name,omitempty" url:"-"` } diff --git a/useridentities/client/client.go b/useridentities/client/client.go index 817fc2c..ed0b566 100644 --- a/useridentities/client/client.go +++ b/useridentities/client/client.go @@ -3,21 +3,18 @@ package client import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" enrollmentautomations "github.com/seamapi/go/useridentities/enrollmentautomations" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header EnrollmentAutomations *enrollmentautomations.Client @@ -27,8 +24,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -44,56 +41,44 @@ func (c *Client) AddAcsUser( opts ...option.RequestOption, ) (*seamapigo.UserIdentitiesAddAcsUserResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/add_acs_user" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/add_acs_user" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesAddAcsUserResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -107,56 +92,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.UserIdentity, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -170,56 +143,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.UserIdentitiesDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -233,56 +194,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.UserIdentity, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -296,56 +245,44 @@ func (c *Client) GrantAccessToDevice( opts ...option.RequestOption, ) (*seamapigo.UserIdentitiesGrantAccessToDeviceResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/grant_access_to_device" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/grant_access_to_device" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesGrantAccessToDeviceResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -359,56 +296,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.UserIdentity, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -422,56 +347,44 @@ func (c *Client) ListAccessibleDevices( opts ...option.RequestOption, ) ([]*seamapigo.Device, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/list_accessible_devices" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/list_accessible_devices" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesListAccessibleDevicesResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -485,56 +398,44 @@ func (c *Client) ListAcsSystems( opts ...option.RequestOption, ) ([]*seamapigo.AcsSystem, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/list_acs_systems" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/list_acs_systems" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesListAcsSystemsResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -548,56 +449,44 @@ func (c *Client) ListAcsUsers( opts ...option.RequestOption, ) ([]*seamapigo.AcsUser, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/list_acs_users" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/list_acs_users" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesListAcsUsersResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -611,56 +500,44 @@ func (c *Client) RemoveAcsUser( opts ...option.RequestOption, ) (*seamapigo.UserIdentitiesRemoveAcsUserResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/remove_acs_user" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/remove_acs_user" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesRemoveAcsUserResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -674,56 +551,44 @@ func (c *Client) RevokeAccessToDevice( opts ...option.RequestOption, ) (*seamapigo.UserIdentitiesRevokeAccessToDeviceResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/revoke_access_to_device" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/revoke_access_to_device" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesRevokeAccessToDeviceResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -737,56 +602,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*seamapigo.UserIdentitiesUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.UserIdentitiesUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/useridentities/enrollment_automations.go b/useridentities/enrollment_automations.go index 47ae147..78d03c8 100644 --- a/useridentities/enrollment_automations.go +++ b/useridentities/enrollment_automations.go @@ -6,33 +6,46 @@ import ( json "encoding/json" fmt "fmt" seamapigo "github.com/seamapi/go" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" + time "time" ) type EnrollmentAutomationsDeleteRequest struct { - EnrollmentAutomationId string `json:"enrollment_automation_id" url:"enrollment_automation_id"` + EnrollmentAutomationId string `json:"enrollment_automation_id" url:"-"` } type EnrollmentAutomationsGetRequest struct { - EnrollmentAutomationId string `json:"enrollment_automation_id" url:"enrollment_automation_id"` + EnrollmentAutomationId string `json:"enrollment_automation_id" url:"-"` } type EnrollmentAutomationsLaunchRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - CredentialManagerAcsSystemId string `json:"credential_manager_acs_system_id" url:"credential_manager_acs_system_id"` - AcsCredentialPoolId *string `json:"acs_credential_pool_id,omitempty" url:"acs_credential_pool_id,omitempty"` - CreateCredentialManagerUser *bool `json:"create_credential_manager_user,omitempty" url:"create_credential_manager_user,omitempty"` - CredentialManagerAcsUserId *string `json:"credential_manager_acs_user_id,omitempty" url:"credential_manager_acs_user_id,omitempty"` + UserIdentityId string `json:"user_identity_id" url:"-"` + CredentialManagerAcsSystemId string `json:"credential_manager_acs_system_id" url:"-"` + AcsCredentialPoolId *string `json:"acs_credential_pool_id,omitempty" url:"-"` + CreateCredentialManagerUser *bool `json:"create_credential_manager_user,omitempty" url:"-"` + CredentialManagerAcsUserId *string `json:"credential_manager_acs_user_id,omitempty" url:"-"` } type EnrollmentAutomationsListRequest struct { - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + UserIdentityId string `json:"user_identity_id" url:"-"` } type EnrollmentAutomationsDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EnrollmentAutomationsDeleteResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EnrollmentAutomationsDeleteResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EnrollmentAutomationsDeleteResponse) UnmarshalJSON(data []byte) error { @@ -42,17 +55,22 @@ func (e *EnrollmentAutomationsDeleteResponse) UnmarshalJSON(data []byte) error { return err } *e = EnrollmentAutomationsDeleteResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EnrollmentAutomationsDeleteResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) @@ -62,7 +80,26 @@ type EnrollmentAutomationsGetResponse struct { EnrollmentAutomation *seamapigo.EnrollmentAutomation `json:"enrollment_automation,omitempty" url:"enrollment_automation,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EnrollmentAutomationsGetResponse) GetEnrollmentAutomation() *seamapigo.EnrollmentAutomation { + if e == nil { + return nil + } + return e.EnrollmentAutomation +} + +func (e *EnrollmentAutomationsGetResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EnrollmentAutomationsGetResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EnrollmentAutomationsGetResponse) UnmarshalJSON(data []byte) error { @@ -72,17 +109,22 @@ func (e *EnrollmentAutomationsGetResponse) UnmarshalJSON(data []byte) error { return err } *e = EnrollmentAutomationsGetResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EnrollmentAutomationsGetResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) @@ -92,7 +134,26 @@ type EnrollmentAutomationsLaunchResponse struct { EnrollmentAutomation *EnrollmentAutomationsLaunchResponseEnrollmentAutomation `json:"enrollment_automation,omitempty" url:"enrollment_automation,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EnrollmentAutomationsLaunchResponse) GetEnrollmentAutomation() *EnrollmentAutomationsLaunchResponseEnrollmentAutomation { + if e == nil { + return nil + } + return e.EnrollmentAutomation +} + +func (e *EnrollmentAutomationsLaunchResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EnrollmentAutomationsLaunchResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EnrollmentAutomationsLaunchResponse) UnmarshalJSON(data []byte) error { @@ -102,17 +163,126 @@ func (e *EnrollmentAutomationsLaunchResponse) UnmarshalJSON(data []byte) error { return err } *e = EnrollmentAutomationsLaunchResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EnrollmentAutomationsLaunchResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { + return value + } + return fmt.Sprintf("%#v", e) +} + +type EnrollmentAutomationsLaunchResponseEnrollmentAutomation struct { + AcsCredentialProvisioningAutomationId string `json:"acs_credential_provisioning_automation_id" url:"acs_credential_provisioning_automation_id"` + CredentialManagerAcsSystemId string `json:"credential_manager_acs_system_id" url:"credential_manager_acs_system_id"` + UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` + CreatedAt time.Time `json:"created_at" url:"created_at"` + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + EnrollmentAutomationId string `json:"enrollment_automation_id" url:"enrollment_automation_id"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetAcsCredentialProvisioningAutomationId() string { + if e == nil { + return "" + } + return e.AcsCredentialProvisioningAutomationId +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetCredentialManagerAcsSystemId() string { + if e == nil { + return "" + } + return e.CredentialManagerAcsSystemId +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetUserIdentityId() string { + if e == nil { + return "" + } + return e.UserIdentityId +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetCreatedAt() time.Time { + if e == nil { + return time.Time{} + } + return e.CreatedAt +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetWorkspaceId() string { + if e == nil { + return "" + } + return e.WorkspaceId +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetEnrollmentAutomationId() string { + if e == nil { + return "" + } + return e.EnrollmentAutomationId +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) GetExtraProperties() map[string]interface{} { + return e.extraProperties +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) UnmarshalJSON(data []byte) error { + type embed EnrollmentAutomationsLaunchResponseEnrollmentAutomation + var unmarshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*e), + } + if err := json.Unmarshal(data, &unmarshaler); err != nil { + return err + } + *e = EnrollmentAutomationsLaunchResponseEnrollmentAutomation(unmarshaler.embed) + e.CreatedAt = unmarshaler.CreatedAt.Time() + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) + return nil +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) MarshalJSON() ([]byte, error) { + type embed EnrollmentAutomationsLaunchResponseEnrollmentAutomation + var marshaler = struct { + embed + CreatedAt *internal.DateTime `json:"created_at"` + }{ + embed: embed(*e), + CreatedAt: internal.NewDateTime(e.CreatedAt), + } + return json.Marshal(marshaler) +} + +func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) String() string { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) @@ -122,7 +292,26 @@ type EnrollmentAutomationsListResponse struct { EnrollmentAutomations []*seamapigo.EnrollmentAutomation `json:"enrollment_automations,omitempty" url:"enrollment_automations,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (e *EnrollmentAutomationsListResponse) GetEnrollmentAutomations() []*seamapigo.EnrollmentAutomation { + if e == nil { + return nil + } + return e.EnrollmentAutomations +} + +func (e *EnrollmentAutomationsListResponse) GetOk() bool { + if e == nil { + return false + } + return e.Ok +} + +func (e *EnrollmentAutomationsListResponse) GetExtraProperties() map[string]interface{} { + return e.extraProperties } func (e *EnrollmentAutomationsListResponse) UnmarshalJSON(data []byte) error { @@ -132,17 +321,22 @@ func (e *EnrollmentAutomationsListResponse) UnmarshalJSON(data []byte) error { return err } *e = EnrollmentAutomationsListResponse(value) - e._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *e) + if err != nil { + return err + } + e.extraProperties = extraProperties + e.rawJSON = json.RawMessage(data) return nil } func (e *EnrollmentAutomationsListResponse) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { + if len(e.rawJSON) > 0 { + if value, err := internal.StringifyJSON(e.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(e); err == nil { + if value, err := internal.StringifyJSON(e); err == nil { return value } return fmt.Sprintf("%#v", e) diff --git a/useridentities/enrollmentautomations/client.go b/useridentities/enrollmentautomations/client.go index 3c99074..3d82f9a 100644 --- a/useridentities/enrollmentautomations/client.go +++ b/useridentities/enrollmentautomations/client.go @@ -3,21 +3,18 @@ package enrollmentautomations import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" useridentities "github.com/seamapi/go/useridentities" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -25,8 +22,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -41,56 +38,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*useridentities.EnrollmentAutomationsDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/enrollment_automations/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/enrollment_automations/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *useridentities.EnrollmentAutomationsDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -104,56 +89,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.EnrollmentAutomation, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/enrollment_automations/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/enrollment_automations/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *useridentities.EnrollmentAutomationsGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -167,56 +140,44 @@ func (c *Client) Launch( opts ...option.RequestOption, ) (*useridentities.EnrollmentAutomationsLaunchResponseEnrollmentAutomation, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/enrollment_automations/launch" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/enrollment_automations/launch" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *useridentities.EnrollmentAutomationsLaunchResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -230,56 +191,44 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.EnrollmentAutomation, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "user_identities/enrollment_automations/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/user_identities/enrollment_automations/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *useridentities.EnrollmentAutomationsListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/useridentities/types.go b/useridentities/types.go deleted file mode 100644 index 19a9f0a..0000000 --- a/useridentities/types.go +++ /dev/null @@ -1,62 +0,0 @@ -// This file was auto-generated by Fern from our API Definition. - -package useridentities - -import ( - json "encoding/json" - fmt "fmt" - core "github.com/seamapi/go/core" - time "time" -) - -type EnrollmentAutomationsLaunchResponseEnrollmentAutomation struct { - AcsCredentialProvisioningAutomationId string `json:"acs_credential_provisioning_automation_id" url:"acs_credential_provisioning_automation_id"` - CredentialManagerAcsSystemId string `json:"credential_manager_acs_system_id" url:"credential_manager_acs_system_id"` - UserIdentityId string `json:"user_identity_id" url:"user_identity_id"` - CreatedAt time.Time `json:"created_at" url:"created_at"` - WorkspaceId string `json:"workspace_id" url:"workspace_id"` - EnrollmentAutomationId string `json:"enrollment_automation_id" url:"enrollment_automation_id"` - - _rawJSON json.RawMessage -} - -func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) UnmarshalJSON(data []byte) error { - type embed EnrollmentAutomationsLaunchResponseEnrollmentAutomation - var unmarshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*e), - } - if err := json.Unmarshal(data, &unmarshaler); err != nil { - return err - } - *e = EnrollmentAutomationsLaunchResponseEnrollmentAutomation(unmarshaler.embed) - e.CreatedAt = unmarshaler.CreatedAt.Time() - e._rawJSON = json.RawMessage(data) - return nil -} - -func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) MarshalJSON() ([]byte, error) { - type embed EnrollmentAutomationsLaunchResponseEnrollmentAutomation - var marshaler = struct { - embed - CreatedAt *core.DateTime `json:"created_at"` - }{ - embed: embed(*e), - CreatedAt: core.NewDateTime(e.CreatedAt), - } - return json.Marshal(marshaler) -} - -func (e *EnrollmentAutomationsLaunchResponseEnrollmentAutomation) String() string { - if len(e._rawJSON) > 0 { - if value, err := core.StringifyJSON(e._rawJSON); err == nil { - return value - } - } - if value, err := core.StringifyJSON(e); err == nil { - return value - } - return fmt.Sprintf("%#v", e) -} diff --git a/webhooks.go b/webhooks.go index d1ad36f..53f8832 100644 --- a/webhooks.go +++ b/webhooks.go @@ -5,27 +5,116 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type WebhooksCreateRequest struct { - Url string `json:"url" url:"url"` - EventTypes []string `json:"event_types,omitempty" url:"event_types,omitempty"` + Url string `json:"url" url:"-"` + EventTypes []string `json:"event_types,omitempty" url:"-"` } type WebhooksDeleteRequest struct { - WebhookId string `json:"webhook_id" url:"webhook_id"` + WebhookId string `json:"webhook_id" url:"-"` } type WebhooksGetRequest struct { - WebhookId string `json:"webhook_id" url:"webhook_id"` + WebhookId string `json:"webhook_id" url:"-"` +} + +type Webhook struct { + WebhookId string `json:"webhook_id" url:"webhook_id"` + Url string `json:"url" url:"url"` + EventTypes []string `json:"event_types,omitempty" url:"event_types,omitempty"` + Secret *string `json:"secret,omitempty" url:"secret,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *Webhook) GetWebhookId() string { + if w == nil { + return "" + } + return w.WebhookId +} + +func (w *Webhook) GetUrl() string { + if w == nil { + return "" + } + return w.Url +} + +func (w *Webhook) GetEventTypes() []string { + if w == nil { + return nil + } + return w.EventTypes +} + +func (w *Webhook) GetSecret() *string { + if w == nil { + return nil + } + return w.Secret +} + +func (w *Webhook) GetExtraProperties() map[string]interface{} { + return w.extraProperties +} + +func (w *Webhook) UnmarshalJSON(data []byte) error { + type unmarshaler Webhook + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *w = Webhook(value) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) + return nil +} + +func (w *Webhook) String() string { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(w); err == nil { + return value + } + return fmt.Sprintf("%#v", w) } type WebhooksCreateResponse struct { Webhook *Webhook `json:"webhook,omitempty" url:"webhook,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WebhooksCreateResponse) GetWebhook() *Webhook { + if w == nil { + return nil + } + return w.Webhook +} + +func (w *WebhooksCreateResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WebhooksCreateResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WebhooksCreateResponse) UnmarshalJSON(data []byte) error { @@ -35,17 +124,22 @@ func (w *WebhooksCreateResponse) UnmarshalJSON(data []byte) error { return err } *w = WebhooksCreateResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WebhooksCreateResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -54,7 +148,19 @@ func (w *WebhooksCreateResponse) String() string { type WebhooksDeleteResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WebhooksDeleteResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WebhooksDeleteResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WebhooksDeleteResponse) UnmarshalJSON(data []byte) error { @@ -64,17 +170,22 @@ func (w *WebhooksDeleteResponse) UnmarshalJSON(data []byte) error { return err } *w = WebhooksDeleteResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WebhooksDeleteResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -84,7 +195,26 @@ type WebhooksGetResponse struct { Webhook *Webhook `json:"webhook,omitempty" url:"webhook,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WebhooksGetResponse) GetWebhook() *Webhook { + if w == nil { + return nil + } + return w.Webhook +} + +func (w *WebhooksGetResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WebhooksGetResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WebhooksGetResponse) UnmarshalJSON(data []byte) error { @@ -94,17 +224,22 @@ func (w *WebhooksGetResponse) UnmarshalJSON(data []byte) error { return err } *w = WebhooksGetResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WebhooksGetResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -114,7 +249,26 @@ type WebhooksListResponse struct { Webhooks []*Webhook `json:"webhooks,omitempty" url:"webhooks,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WebhooksListResponse) GetWebhooks() []*Webhook { + if w == nil { + return nil + } + return w.Webhooks +} + +func (w *WebhooksListResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WebhooksListResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WebhooksListResponse) UnmarshalJSON(data []byte) error { @@ -124,17 +278,22 @@ func (w *WebhooksListResponse) UnmarshalJSON(data []byte) error { return err } *w = WebhooksListResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WebhooksListResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -143,7 +302,19 @@ func (w *WebhooksListResponse) String() string { type WebhooksUpdateResponse struct { Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WebhooksUpdateResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WebhooksUpdateResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WebhooksUpdateResponse) UnmarshalJSON(data []byte) error { @@ -153,23 +324,28 @@ func (w *WebhooksUpdateResponse) UnmarshalJSON(data []byte) error { return err } *w = WebhooksUpdateResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WebhooksUpdateResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) } type WebhooksUpdateRequest struct { - WebhookId string `json:"webhook_id" url:"webhook_id"` - EventTypes []string `json:"event_types,omitempty" url:"event_types,omitempty"` + WebhookId string `json:"webhook_id" url:"-"` + EventTypes []string `json:"event_types,omitempty" url:"-"` } diff --git a/webhooks/client.go b/webhooks/client.go index f7e9eb2..bccb1c5 100644 --- a/webhooks/client.go +++ b/webhooks/client.go @@ -3,20 +3,17 @@ package webhooks import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.Webhook, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "webhooks/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/webhooks/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WebhooksCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -103,56 +88,44 @@ func (c *Client) Delete( opts ...option.RequestOption, ) (*seamapigo.WebhooksDeleteResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "webhooks/delete" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/webhooks/delete" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WebhooksDeleteResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -166,56 +139,44 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Webhook, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "webhooks/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/webhooks/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WebhooksGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -228,55 +189,42 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Webhook, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "webhooks/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/webhooks/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WebhooksListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -290,56 +238,44 @@ func (c *Client) Update( opts ...option.RequestOption, ) (*seamapigo.WebhooksUpdateResponse, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "webhooks/update" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/webhooks/update" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WebhooksUpdateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err diff --git a/workspaces.go b/workspaces.go index 0abab6a..0cbd2ef 100644 --- a/workspaces.go +++ b/workspaces.go @@ -5,23 +5,120 @@ package api import ( json "encoding/json" fmt "fmt" - core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" ) type WorkspacesCreateRequest struct { - Name string `json:"name" url:"name"` - // The name shown inside the connect webview - ConnectPartnerName string `json:"connect_partner_name" url:"connect_partner_name"` - IsSandbox *bool `json:"is_sandbox,omitempty" url:"is_sandbox,omitempty"` - WebviewPrimaryButtonColor *string `json:"webview_primary_button_color,omitempty" url:"webview_primary_button_color,omitempty"` - WebviewLogoShape *WebviewLogoShape `json:"webview_logo_shape,omitempty" url:"webview_logo_shape,omitempty"` + Name string `json:"name" url:"-"` + CompanyName *string `json:"company_name,omitempty" url:"-"` + ConnectPartnerName *string `json:"connect_partner_name,omitempty" url:"-"` + IsSandbox *bool `json:"is_sandbox,omitempty" url:"-"` + WebviewPrimaryButtonColor *string `json:"webview_primary_button_color,omitempty" url:"-"` + WebviewLogoShape *WebviewLogoShape `json:"webview_logo_shape,omitempty" url:"-"` +} + +type Workspace struct { + WorkspaceId string `json:"workspace_id" url:"workspace_id"` + Name string `json:"name" url:"name"` + CompanyName string `json:"company_name" url:"company_name"` + IsSandbox bool `json:"is_sandbox" url:"is_sandbox"` + ConnectPartnerName *string `json:"connect_partner_name,omitempty" url:"connect_partner_name,omitempty"` + + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *Workspace) GetWorkspaceId() string { + if w == nil { + return "" + } + return w.WorkspaceId +} + +func (w *Workspace) GetName() string { + if w == nil { + return "" + } + return w.Name +} + +func (w *Workspace) GetCompanyName() string { + if w == nil { + return "" + } + return w.CompanyName +} + +func (w *Workspace) GetIsSandbox() bool { + if w == nil { + return false + } + return w.IsSandbox +} + +func (w *Workspace) GetConnectPartnerName() *string { + if w == nil { + return nil + } + return w.ConnectPartnerName +} + +func (w *Workspace) GetExtraProperties() map[string]interface{} { + return w.extraProperties +} + +func (w *Workspace) UnmarshalJSON(data []byte) error { + type unmarshaler Workspace + var value unmarshaler + if err := json.Unmarshal(data, &value); err != nil { + return err + } + *w = Workspace(value) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) + return nil +} + +func (w *Workspace) String() string { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { + return value + } + } + if value, err := internal.StringifyJSON(w); err == nil { + return value + } + return fmt.Sprintf("%#v", w) } type WorkspacesCreateResponse struct { Workspace *Workspace `json:"workspace,omitempty" url:"workspace,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WorkspacesCreateResponse) GetWorkspace() *Workspace { + if w == nil { + return nil + } + return w.Workspace +} + +func (w *WorkspacesCreateResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WorkspacesCreateResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WorkspacesCreateResponse) UnmarshalJSON(data []byte) error { @@ -31,17 +128,22 @@ func (w *WorkspacesCreateResponse) UnmarshalJSON(data []byte) error { return err } *w = WorkspacesCreateResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WorkspacesCreateResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -51,7 +153,26 @@ type WorkspacesGetResponse struct { Workspace *Workspace `json:"workspace,omitempty" url:"workspace,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WorkspacesGetResponse) GetWorkspace() *Workspace { + if w == nil { + return nil + } + return w.Workspace +} + +func (w *WorkspacesGetResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WorkspacesGetResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WorkspacesGetResponse) UnmarshalJSON(data []byte) error { @@ -61,17 +182,22 @@ func (w *WorkspacesGetResponse) UnmarshalJSON(data []byte) error { return err } *w = WorkspacesGetResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WorkspacesGetResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -81,7 +207,26 @@ type WorkspacesListResponse struct { Workspaces []*Workspace `json:"workspaces,omitempty" url:"workspaces,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WorkspacesListResponse) GetWorkspaces() []*Workspace { + if w == nil { + return nil + } + return w.Workspaces +} + +func (w *WorkspacesListResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WorkspacesListResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WorkspacesListResponse) UnmarshalJSON(data []byte) error { @@ -91,17 +236,22 @@ func (w *WorkspacesListResponse) UnmarshalJSON(data []byte) error { return err } *w = WorkspacesListResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WorkspacesListResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) @@ -111,7 +261,26 @@ type WorkspacesResetSandboxResponse struct { ActionAttempt *ActionAttempt `json:"action_attempt,omitempty" url:"action_attempt,omitempty"` Ok bool `json:"ok" url:"ok"` - _rawJSON json.RawMessage + extraProperties map[string]interface{} + rawJSON json.RawMessage +} + +func (w *WorkspacesResetSandboxResponse) GetActionAttempt() *ActionAttempt { + if w == nil { + return nil + } + return w.ActionAttempt +} + +func (w *WorkspacesResetSandboxResponse) GetOk() bool { + if w == nil { + return false + } + return w.Ok +} + +func (w *WorkspacesResetSandboxResponse) GetExtraProperties() map[string]interface{} { + return w.extraProperties } func (w *WorkspacesResetSandboxResponse) UnmarshalJSON(data []byte) error { @@ -121,17 +290,22 @@ func (w *WorkspacesResetSandboxResponse) UnmarshalJSON(data []byte) error { return err } *w = WorkspacesResetSandboxResponse(value) - w._rawJSON = json.RawMessage(data) + extraProperties, err := internal.ExtractExtraProperties(data, *w) + if err != nil { + return err + } + w.extraProperties = extraProperties + w.rawJSON = json.RawMessage(data) return nil } func (w *WorkspacesResetSandboxResponse) String() string { - if len(w._rawJSON) > 0 { - if value, err := core.StringifyJSON(w._rawJSON); err == nil { + if len(w.rawJSON) > 0 { + if value, err := internal.StringifyJSON(w.rawJSON); err == nil { return value } } - if value, err := core.StringifyJSON(w); err == nil { + if value, err := internal.StringifyJSON(w); err == nil { return value } return fmt.Sprintf("%#v", w) diff --git a/workspaces/client.go b/workspaces/client.go index f74e991..ba98ce1 100644 --- a/workspaces/client.go +++ b/workspaces/client.go @@ -3,20 +3,17 @@ package workspaces import ( - bytes "bytes" context "context" - json "encoding/json" - errors "errors" seamapigo "github.com/seamapi/go" core "github.com/seamapi/go/core" + internal "github.com/seamapi/go/internal" option "github.com/seamapi/go/option" - io "io" http "net/http" ) type Client struct { baseURL string - caller *core.Caller + caller *internal.Caller header http.Header } @@ -24,8 +21,8 @@ func NewClient(opts ...option.RequestOption) *Client { options := core.NewRequestOptions(opts...) return &Client{ baseURL: options.BaseURL, - caller: core.NewCaller( - &core.CallerParams{ + caller: internal.NewCaller( + &internal.CallerParams{ Client: options.HTTPClient, MaxAttempts: options.MaxAttempts, }, @@ -40,56 +37,44 @@ func (c *Client) Create( opts ...option.RequestOption, ) (*seamapigo.Workspace, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "workspaces/create" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/workspaces/create" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + headers.Set("Content-Type", "application/json") + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WorkspacesCreateResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Request: request, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Request: request, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -102,55 +87,42 @@ func (c *Client) Get( opts ...option.RequestOption, ) (*seamapigo.Workspace, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "workspaces/get" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/workspaces/get" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WorkspacesGetResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -163,55 +135,42 @@ func (c *Client) List( opts ...option.RequestOption, ) ([]*seamapigo.Workspace, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "workspaces/list" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/workspaces/list" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WorkspacesListResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err @@ -224,55 +183,42 @@ func (c *Client) ResetSandbox( opts ...option.RequestOption, ) (*seamapigo.ActionAttempt, error) { options := core.NewRequestOptions(opts...) - - baseURL := "https://connect.getseam.com" - if c.baseURL != "" { - baseURL = c.baseURL - } - if options.BaseURL != "" { - baseURL = options.BaseURL - } - endpointURL := baseURL + "/" + "workspaces/reset_sandbox" - - headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) - - errorDecoder := func(statusCode int, body io.Reader) error { - raw, err := io.ReadAll(body) - if err != nil { - return err - } - apiError := core.NewAPIError(statusCode, errors.New(string(raw))) - decoder := json.NewDecoder(bytes.NewReader(raw)) - switch statusCode { - case 400: - value := new(seamapigo.BadRequestError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + baseURL := internal.ResolveBaseURL( + options.BaseURL, + c.baseURL, + "https://connect.getseam.com", + ) + endpointURL := baseURL + "/workspaces/reset_sandbox" + headers := internal.MergeHeaders( + c.header.Clone(), + options.ToHeader(), + ) + errorCodes := internal.ErrorCodes{ + 400: func(apiError *core.APIError) error { + return &seamapigo.BadRequestError{ + APIError: apiError, } - return value - case 401: - value := new(seamapigo.UnauthorizedError) - value.APIError = apiError - if err := decoder.Decode(value); err != nil { - return apiError + }, + 401: func(apiError *core.APIError) error { + return &seamapigo.UnauthorizedError{ + APIError: apiError, } - return value - } - return apiError + }, } var response *seamapigo.WorkspacesResetSandboxResponse if err := c.caller.Call( ctx, - &core.CallParams{ - URL: endpointURL, - Method: http.MethodPost, - MaxAttempts: options.MaxAttempts, - Headers: headers, - Client: options.HTTPClient, - Response: &response, - ErrorDecoder: errorDecoder, + &internal.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: headers, + MaxAttempts: options.MaxAttempts, + BodyProperties: options.BodyProperties, + QueryParameters: options.QueryParameters, + Client: options.HTTPClient, + Response: &response, + ErrorDecoder: internal.NewErrorDecoder(errorCodes), }, ); err != nil { return nil, err