Skip to content

Commit 7247054

Browse files
authored
Merge pull request #4 from Fingertips/manfred-877-avatar-api
Add support for avatars
2 parents 838c4fd + dbf38ee commit 7247054

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ You can use a video id and upload id, to create a new document with the upload.
8585

8686
teletube documents create --video-id <id> --upload-id
8787

88+
# Upload a new avatar for a profile
89+
90+
teletube files upload AVATAR.JPG
91+
92+
This should print a NO_CONTENT response for every 50 megabytes uploaded. Error messages are handled as long as the command keeps running.
93+
94+
Copy-paste the characters after 📃, this is the upload id.
95+
96+
You can create a new avatar with the upload id.
97+
98+
teletube avatars create --upload-id <upload-id>
99+
88100
# Help
89101

90102
You can always end a command with `--help` to get more details. For example:

src/teletube/cli.cr

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ module Teletube
2323
case context.resource
2424
when "artworks"
2525
@client.create_artwork
26+
when "avatars"
27+
case context.command
28+
when "destroy"
29+
@client.destroy_avatars
30+
else
31+
@client.create_avatar
32+
end
2633
when "browse"
2734
case context.command
2835
when "channels"

src/teletube/client.cr

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ module Teletube
209209
handle_response(@http.post(path: "/api/v1/documents", params: @context.params))
210210
end
211211

212+
def create_avatar
213+
upload_file
214+
handle_response(@http.post(path: "/api/v1/avatars", params: @context.params))
215+
end
216+
217+
def destroy_avatars
218+
handle_response(@http.delete(path: "/api/v1/avatars"))
219+
end
220+
212221
def destroy_document
213222
handle_response(@http.delete(path: "/api/v1/documents/#{@context.params["id"]}"))
214223
end

src/teletube/option_parser.cr

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ module Teletube
1717
end
1818
end
1919

20+
parser.on("avatars", "Interact with avatars.") do
21+
context.resource = "avatars"
22+
parser.on("create", "Upload a new avatar.") do
23+
context.command = "create"
24+
parser.on(
25+
"--upload-id ID",
26+
"Upload ID of the file that should be used to create the avatar."
27+
) do |file_id|
28+
context.params["upload_id"] = JSON::Any.new(file_id)
29+
end
30+
end
31+
parser.on("destroy", "Destroy all uploaded avatars.") do
32+
context.command = "destroy"
33+
end
34+
end
35+
2036
parser.on("config", "Configure common options.") do
2137
context.resource = "config"
2238
parser.on("--token TOKEN", "Access token used to access the web service") do |token|

0 commit comments

Comments
 (0)