Refactor ejabberd API integration
This commit is contained in:
25
app/services/ejabberd_manager/get_avatar.rb
Normal file
25
app/services/ejabberd_manager/get_avatar.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module EjabberdManager
|
||||
class GetAvatar < EjabberdManagerService
|
||||
def initialize(user:)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def call
|
||||
res = get_vcard2 @user, "PHOTO", "BINVAL"
|
||||
|
||||
if res.status == 200
|
||||
# VCARD PHOTO/BINVAL prop exists
|
||||
img_base64 = JSON.parse(res.body)["content"]
|
||||
ct_res = get_vcard2 @user, "PHOTO", "TYPE"
|
||||
content_type = JSON.parse(ct_res.body)["content"]
|
||||
{ content_type:, img_base64: }
|
||||
elsif res.status == 400
|
||||
# VCARD or PHOTO/BINVAL prop does not exist
|
||||
nil
|
||||
else
|
||||
# Unexpected error, let job fail
|
||||
raise res.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user