Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AmazonBean ¶
type AmazonBean struct {
FileID string `json:"fileId"`
Request RequestBean `json:"request"`
}
AmazonBean represents the Amazon S3 upload response
type Chapter ¶
type Chapter struct {
ID string `json:"id"`
File string `json:"file"`
Title string `json:"title"`
Seconds float64 `json:"seconds"`
Transcoding bool `json:"transcoding"`
}
Chapter represents a chapter/track on a Creative-Tonie
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main interface for interacting with the Toniebox API. It provides methods for authentication and accessing Toniebox resources.
func NewClient ¶
func NewClient() *Client
NewClient creates a new Toniebox API client with default settings.
Example:
client := toniebox.NewClient()
err := client.Login("user@example.com", "password")
func NewClientWithProxy ¶
NewClientWithProxy creates a new Toniebox API client with a proxy. The proxyURL should be in the format "http://host:port" or "https://host:port".
Example:
client, err := toniebox.NewClientWithProxy("http://proxy.example.com:8080")
func (*Client) GetCreativeTonies ¶
func (c *Client) GetCreativeTonies(household *Household) ([]CreativeTonie, error)
GetCreativeTonies retrieves all Creative-Tonies in a specific household. Creative-Tonies are the figurines that can have custom audio content uploaded to them.
Parameters:
- household: The household to retrieve Creative-Tonies from
Returns a slice of Creative-Tonies or an error if the request fails.
Example:
households, _ := client.GetHouseholds()
tonies, err := client.GetCreativeTonies(&households[0])
if err != nil {
log.Fatal(err)
}
for _, tonie := range tonies {
fmt.Printf("Tonie: %s (Chapters: %d)\n", tonie.Name, tonie.ChaptersPresent)
}
func (*Client) GetHouseholds ¶
GetHouseholds retrieves all households that the user belongs to. A household represents a family or group that shares Tonieboxes.
Returns a slice of households or an error if the request fails.
Example:
households, err := client.GetHouseholds()
if err != nil {
log.Fatal(err)
}
for _, household := range households {
fmt.Printf("Household: %s (ID: %s)\n", household.Name, household.ID)
}
func (*Client) GetMe ¶
GetMe retrieves personal information about the authenticated user.
Returns the user's profile information or an error if the request fails.
Example:
me, err := client.GetMe()
if err != nil {
log.Fatal(err)
}
fmt.Printf("User: %s %s\n", me.FirstName, me.LastName)
func (*Client) Login ¶
Login authenticates the user with their Toniebox account credentials. This must be called before any other API methods.
Parameters:
- username: The email address for your Toniebox account
- password: The password for your Toniebox account
Returns an error if authentication fails.
Example:
err := client.Login("user@example.com", "password")
if err != nil {
log.Fatal(err)
}
Login authenticates the user with their Toniebox account credentials. This must be called before any other API methods.
Parameters:
- username: The email address for your Toniebox account
- password: The password for your Toniebox account
Returns the authentication token (including refresh token) or an error if authentication fails.
Example:
token, err := client.Login("user@example.com", "password")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Refresh Token: %s\n", token.RefreshToken)
func (*Client) SetToken ¶ added in v0.2.0
SetToken sets the authentication token directly, bypassing the login process. This is useful if you have a stored refresh token or access token.
Parameters:
- token: The JWT token to use
Example:
token := &toniebox.JWTToken{
AccessToken: "...",
RefreshToken: "...",
}
client.SetToken(token)
type CreativeTonie ¶
type CreativeTonie struct {
ID string `json:"id"`
Name string `json:"name"`
Live bool `json:"live"`
Private bool `json:"private"`
ImageURL string `json:"imageUrl"`
TranscodingErrors []string `json:"transcodingErrors"`
Transcoding bool `json:"transcoding"`
SecondsPresent float64 `json:"secondsPresent"`
SecondsRemaining float64 `json:"secondsRemaining"`
ChaptersPresent int `json:"chaptersPresent"`
ChaptersRemaining int `json:"chaptersRemaining"`
Chapters []Chapter `json:"chapters"`
HouseholdID string `json:"householdId"`
// contains filtered or unexported fields
}
CreativeTonie represents a Creative-Tonie figurine
func (*CreativeTonie) Commit ¶
func (ct *CreativeTonie) Commit() error
Commit saves all changes made to this Creative-Tonie to the Toniebox cloud. This must be called after making changes like renaming, uploading, or deleting chapters.
Returns an error if the commit fails.
Example:
tonie.Name = "New Name"
err := tonie.Commit()
if err != nil {
log.Fatal(err)
}
func (*CreativeTonie) DeleteChapter ¶
func (ct *CreativeTonie) DeleteChapter(chapter *Chapter)
DeleteChapter removes a chapter from this Creative-Tonie. Note: You must call Commit() after this to persist the changes.
Parameters:
- chapter: The chapter to delete
Example:
chapter := tonie.FindChapterByTitle("Old Track")
if chapter != nil {
tonie.DeleteChapter(chapter)
tonie.Commit()
}
func (*CreativeTonie) FindChapterByTitle ¶
func (ct *CreativeTonie) FindChapterByTitle(title string) *Chapter
FindChapterByTitle searches for a chapter with the given title on this Creative-Tonie.
Parameters:
- title: The title to search for
Returns the chapter if found, or nil if not found.
Example:
chapter := tonie.FindChapterByTitle("My Audio Track")
if chapter != nil {
fmt.Printf("Found chapter: %s\n", chapter.Title)
}
func (*CreativeTonie) Refresh ¶
func (ct *CreativeTonie) Refresh() error
Refresh reloads the current state of this Creative-Tonie from the Toniebox cloud. This is useful to see the latest changes, such as transcoding status.
Returns an error if the refresh fails.
Example:
err := tonie.Refresh()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Chapters present: %d\n", tonie.ChaptersPresent)
func (*CreativeTonie) UploadFile ¶
func (ct *CreativeTonie) UploadFile(title, filePath string) error
UploadFile uploads an audio file to this Creative-Tonie. The file will be added as a new chapter with the specified title. Note: You must call Commit() after this to persist the changes.
Parameters:
- title: The title for the new chapter
- filePath: The path to the audio file to upload
Returns an error if the upload fails.
Example:
err := tonie.UploadFile("My Story", "/path/to/audio.mp3")
if err != nil {
log.Fatal(err)
}
err = tonie.Commit()
type FieldsBean ¶
type FieldsBean struct {
Key string `json:"key"`
Policy string `json:"policy"`
XAmzAlgorithm string `json:"x-amz-algorithm"`
XAmzCredential string `json:"x-amz-credential"`
XAmzDate string `json:"x-amz-date"`
XAmzSignature string `json:"x-amz-signature"`
XAmzSecurityToken string `json:"x-amz-security-token"`
}
FieldsBean represents Amazon S3 upload form fields
type Household ¶
type Household struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
ForeignCreativeTonieContent bool `json:"foreignCreativeTonieContent"`
Access string `json:"access"`
CanLeave bool `json:"canLeave"`
OwnerName string `json:"ownerName"`
}
Household represents a Toniebox household
type JWTToken ¶
type JWTToken struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
TokenType string `json:"token_type,omitempty"`
Scope string `json:"scope,omitempty"`
}
JWTToken represents the authentication token returned by the API
type Me ¶
type Me struct {
Email string `json:"email"`
UUID string `json:"uuid"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Sex string `json:"sex"`
AcceptedTermsOfUse bool `json:"acceptedTermsOfUse"`
Tracking bool `json:"tracking"`
AuthCode string `json:"authCode"`
ProfileImage string `json:"profileImage"`
Verified bool `json:"isVerified"`
EduUser bool `json:"isEduUser"`
NotificationCount int `json:"notificationCount"`
RequiresVerificationToUpload bool `json:"requiresVerificationToUpload"`
}
Me represents personal information about the authenticated user
type RequestBean ¶
type RequestBean struct {
URL string `json:"url"`
Fields FieldsBean `json:"fields"`
}
RequestBean represents Amazon S3 upload request details