From bec69011ac3a2eb84a435ad51665ada6800eb654 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Thu, 22 Feb 2024 03:22:03 +0000 Subject: [PATCH] add status model --- internal/client/register.go | 19 ++--- internal/model/account.go | 8 -- internal/model/application.go | 11 +++ internal/model/emoji.go | 9 +++ internal/model/status.go | 146 ++++++++++++++++++++++++++++++++++ 5 files changed, 171 insertions(+), 22 deletions(-) create mode 100644 internal/model/application.go create mode 100644 internal/model/emoji.go create mode 100644 internal/model/status.go diff --git a/internal/client/register.go b/internal/client/register.go index 36d11fd..99dc14c 100644 --- a/internal/client/register.go +++ b/internal/client/register.go @@ -8,6 +8,7 @@ import ( "net/http" "codeflow.dananglin.me.uk/apollo/enbas/internal" + "codeflow.dananglin.me.uk/apollo/enbas/internal/model" ) type RegisterRequest struct { @@ -17,16 +18,6 @@ type RegisterRequest struct { Website string `json:"website"` } -type RegisterResponse struct { - ClientID string `json:"client_id"` - ClientSecret string `json:"client_secret"` - ID string `json:"id"` - Name string `json:"name"` - RedirectUri string `json:"redirect_uri"` - VapidKey string `json:"vapid_key"` - Website string `json:"website"` -} - func (g *Client) Register() error { params := RegisterRequest{ ClientName: internal.ApplicationName, @@ -53,14 +44,14 @@ func (g *Client) Register() error { return fmt.Errorf("unable to create the HTTP request; %w", err) } - var registerResponse RegisterResponse + var app model.Application - if err := g.sendRequest(request, ®isterResponse); err != nil { + if err := g.sendRequest(request, &app); err != nil { return fmt.Errorf("received an error after sending the registration request; %w", err) } - g.Authentication.ClientID = registerResponse.ClientID - g.Authentication.ClientSecret = registerResponse.ClientSecret + g.Authentication.ClientID = app.ClientID + g.Authentication.ClientSecret = app.ClientSecret return nil } diff --git a/internal/model/account.go b/internal/model/account.go index 82af04c..a86dba8 100644 --- a/internal/model/account.go +++ b/internal/model/account.go @@ -29,14 +29,6 @@ type Account struct { Username string `json:"username"` } -type Emoji struct { - Category string `json:"category"` - Shortcode string `json:"shortcode"` - StaticURL string `json:"static_url"` - URL string `json:"url"` - VisibleInPicker bool `json:"visible_in_picker"` -} - type AccountRole struct { Name string `json:"name"` } diff --git a/internal/model/application.go b/internal/model/application.go new file mode 100644 index 0000000..3b7a674 --- /dev/null +++ b/internal/model/application.go @@ -0,0 +1,11 @@ +package model + +type Application struct { + ClientID string `json:"client_id"` + ClientSecret string `json:"client_secret"` + ID string `json:"id"` + Name string `json:"name"` + RedirectUri string `json:"redirect_uri"` + VapidKey string `json:"vapid_key"` + Website string `json:"website"` +} diff --git a/internal/model/emoji.go b/internal/model/emoji.go new file mode 100644 index 0000000..a71f31c --- /dev/null +++ b/internal/model/emoji.go @@ -0,0 +1,9 @@ +package model + +type Emoji struct { + Category string `json:"category"` + Shortcode string `json:"shortcode"` + StaticURL string `json:"static_url"` + URL string `json:"url"` + VisibleInPicker bool `json:"visible_in_picker"` +} diff --git a/internal/model/status.go b/internal/model/status.go new file mode 100644 index 0000000..c2924f3 --- /dev/null +++ b/internal/model/status.go @@ -0,0 +1,146 @@ +package model + +type Status struct { + Account Account `json:"account"` + Application Application `json:"application"` + Bookmarked bool `json:"bookmarked"` + Card Card `json:"card"` + Content string `json:"content"` + CreatedAt string `json:"created_at"` + Emojis []Emoji `json:"emojis"` + Favourited bool `json:"favourited"` + FavouritesCount int `json:"favourites_count"` + ID string `json:"id"` + InReplyToAccountID string `json:"in_reply_to_account_id"` + InReplyToID string `json:"in_reply_to_id"` + Language string `json:"language"` + MediaAttachments []Attachment `json:"media_attachments"` + Mentions []Mention `json:"mentions"` + Muted bool `json:"muted"` + Pinned bool `json:"pinned"` + Poll Poll `json:"poll"` + Reblog StatusReblogged `json:"reblog"` + Reblogged bool `json:"reblogged"` + RebloggsCount int `json:"reblogs_count"` + RepliesCount int `json:"replies_count"` + Sensitive bool `json:"sensitive"` + SpolierText string `json:"spoiler_text"` + Tags []Tag `json:"tags"` + Text string `json:"text"` + URI string `json:"uri"` + URL string `json:"url"` + Visibility string `json:"visibility"` +} + +type Card struct { + AuthorName string `json:"author_name"` + AuthorURL string `json:"author_url"` + Blurhash string `json:"blurhash"` + Description string `json:"description"` + EmbedURL string `json:"embed_url"` + HTML string `json:"html"` + Image string `json:"image"` + ProviderName string `json:"provider_name"` + ProviderURL string `json:"provider_url"` + Title string `json:"title"` + Type string `json:"type"` + URL string `json:"url"` + Height int `json:"height"` + Width int `json:"width"` +} + +type Mention struct { + Acct string `json:"acct"` + ID string `json:"id"` + URL string `json:"url"` + Username string `json:"username"` +} + +type Poll struct { + Emojis []Emoji `json:"emojis"` + Expired bool `json:"expired"` + Voted bool `json:"voted"` + Multiple bool `json:"multiple"` + ExpiredAt string `json:"expires_at"` + ID string `json:"id"` + OwnVotes []int `json:"own_votes"` + VotersCount int `json:"voters_count"` + VotesCount int `json:"votes_count"` + Options []PollOption `json:"options"` +} + +type PollOption struct { + Title string `json:"title"` + VotesCount string `json:"votes_count"` +} + +type StatusReblogged struct { + Account Account `json:"account"` + Application Application `json:"application"` + Bookmarked bool `json:"bookmarked"` + Card Card `json:"card"` + Content string `json:"content"` + CreatedAt string `json:"created_at"` + Emojis []Emoji `json:"emojis"` + Favourited bool `json:"favourited"` + FavouritesCount int `json:"favourites_count"` + ID string `json:"id"` + InReplyToAccountID string `json:"in_reply_to_account_id"` + InReplyToID string `json:"in_reply_to_id"` + Language string `json:"language"` + MediaAttachments []Attachment `json:"media_attachments"` + Mentions []Mention `json:"mentions"` + Muted bool `json:"muted"` + Pinned bool `json:"pinned"` + Poll Poll `json:"poll"` + Reblogged bool `json:"reblogged"` + RebloggsCount int `json:"reblogs_count"` + RepliesCount int `json:"replies_count"` + Sensitive bool `json:"sensitive"` + SpolierText string `json:"spoiler_text"` + Tags []Tag `json:"tags"` + Text string `json:"text"` + URI string `json:"uri"` + URL string `json:"url"` + Visibility string `json:"visibility"` +} + +type Tag struct { + History []any `json:"history"` + Name string `json:"name"` + URL string `json:"url"` +} + +type Attachment struct { + Meta MediaMeta `json:"meta"` + Blurhash string `json:"blurhash"` + Description string `json:"description"` + ID string `json:"id"` + PreviewRemoteURL string `json:"preview_remote_url"` + PreviewURL string `json:"preview_url"` + RemoteURL string `json:"remote_url"` + TextURL string `json:"text_url"` + Type string `json:"type"` + URL string `json:"url"` +} + +type MediaMeta struct { + Focus MediaFocus `json:"focus"` + Original MediaDimensions `json:"original"` + Small MediaDimensions `json:"small"` +} + +type MediaFocus struct { + X float64 `json:"x"` + Y float64 `json:"y"` +} + +type MediaDimensions struct { + Aspect float64 `json:"aspect"` + Bitrate int `json:"bitrate"` + Duration float64 `json:"duration"` + FrameRate string `json:"frame_rate"` + Size string `json:"size"` + Height int `json:"height"` + Width int `json:"width"` +}