Module: X::Uploader::Account
Overview
Uploads profile images and banners to the X API v1.1
Its methods can be called on the module, or on an instance of a class that includes it, which gains its public methods alone. They post to the API v1.1 endpoint with the client they are given, which keeps the connection it holds to the host open for the requests that follow, rather than with a copy of it. The endpoint is resolved against the base URL of the client, in place of the version it names, so it is reached at the host the client sends its other requests to, which its credentials are sent to, whether that is api.x.com, api.twitter.com, or a proxy of the API.
Class Method Summary collapse
-
.update_profile_banner(media, client:, width: nil, height: nil, offset_left: nil, offset_top: nil) ⇒ void
Update the authenticating user's profile banner.
-
.update_profile_image(media, client:) ⇒ void
Update the authenticating user's profile image.
Instance Method Summary collapse
-
#update_profile_banner(media, client:, width: nil, height: nil, offset_left: nil, offset_top: nil) ⇒ void
Update the authenticating user's profile banner.
-
#update_profile_image(media, client:) ⇒ void
Update the authenticating user's profile image.
Class Method Details
.update_profile_banner(media, client:, width: nil, height: nil, offset_left: nil, offset_top: nil) ⇒ void
This method returns an undefined value.
Update the authenticating user's profile banner
It returns nil, whatever the client answers with, since the endpoint answers with no content once the banner is updated.
85 86 87 88 89 90 91 |
# File 'x-uploader/lib/x/uploader/account.rb', line 85 def (media, client:, width: nil, height: nil, offset_left: nil, offset_top: nil) Validator.(width:, height:, offset_left:, offset_top:) source = Source.for(media) Validator.validate_profile_image!(source, Validator::MAX_PROFILE_BANNER_BYTES, "a profile banner") Multipart.post(client, PROFILE_BANNER_URL, "banner", source.content, width:, height:, offset_left:, offset_top:) nil end |
.update_profile_image(media, client:) ⇒ void
This method returns an undefined value.
Update the authenticating user's profile image
It returns nil, whatever the client answers with, as #update_profile_banner does: the API v1.1 answers with the user in its own shape, keyed as v1.1 keys it, which no object of these gems reads, since an X::User of x-objects reads the users of the API v2 alone. Look the user up with the API v2 to read the image it now has.
53 54 55 56 57 58 |
# File 'x-uploader/lib/x/uploader/account.rb', line 53 def update_profile_image(media, client:) source = Source.for(media) Validator.validate_profile_image!(source, Validator::MAX_PROFILE_IMAGE_BYTES, "a profile image") Multipart.post(client, PROFILE_IMAGE_URL, "image", source.content) nil end |
Instance Method Details
#update_profile_banner(media, client:, width: nil, height: nil, offset_left: nil, offset_top: nil) ⇒ void
This method returns an undefined value.
Update the authenticating user's profile banner
It returns nil, whatever the client answers with, since the endpoint answers with no content once the banner is updated.
85 86 87 88 89 90 91 |
# File 'x-uploader/lib/x/uploader/account.rb', line 85 def (media, client:, width: nil, height: nil, offset_left: nil, offset_top: nil) Validator.(width:, height:, offset_left:, offset_top:) source = Source.for(media) Validator.validate_profile_image!(source, Validator::MAX_PROFILE_BANNER_BYTES, "a profile banner") Multipart.post(client, PROFILE_BANNER_URL, "banner", source.content, width:, height:, offset_left:, offset_top:) nil end |
#update_profile_image(media, client:) ⇒ void
This method returns an undefined value.
Update the authenticating user's profile image
It returns nil, whatever the client answers with, as #update_profile_banner does: the API v1.1 answers with the user in its own shape, keyed as v1.1 keys it, which no object of these gems reads, since an X::User of x-objects reads the users of the API v2 alone. Look the user up with the API v2 to read the image it now has.
53 54 55 56 57 58 |
# File 'x-uploader/lib/x/uploader/account.rb', line 53 def update_profile_image(media, client:) source = Source.for(media) Validator.validate_profile_image!(source, Validator::MAX_PROFILE_IMAGE_BYTES, "a profile image") Multipart.post(client, PROFILE_IMAGE_URL, "image", source.content) nil end |