Module: X::AccountUploader
Overview
Uploads profile images and banners to the X API v1.1
Constant Summary collapse
- V1_BASE_URL =
Base URL for X API v1.1 account endpoints
"https://api.x.com/1.1/".freeze
- SUPPORTED_EXTENSIONS =
Supported image extensions for profile uploads
%w[gif jpg jpeg png].freeze
- MIME_TYPE_MAP =
Mapping of file extensions to MIME types
{"gif" => "image/gif", "jpg" => "image/jpeg", "jpeg" => "image/jpeg", "png" => "image/png"}.freeze
Instance Method Summary collapse
-
#update_profile_banner(client:, file_path:, width: nil, height: nil, offset_left: nil, offset_top: nil, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile banner.
-
#update_profile_image(client:, file_path:, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile image.
-
#upload_profile_banner_binary(client:, content:, width: nil, height: nil, offset_left: nil, offset_top: nil, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile banner from binary content.
-
#upload_profile_image_binary(client:, content:, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile image from binary content.
Instance Method Details
#update_profile_banner(client:, file_path:, width: nil, height: nil, offset_left: nil, offset_top: nil, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile banner
66 67 68 69 70 71 |
# File 'lib/x/account_uploader.rb', line 66 def (client:, file_path:, width: nil, height: nil, offset_left: nil, offset_top: nil, boundary: SecureRandom.hex) validate_file!(file_path) (client:, content: File.binread(file_path), width:, height:, offset_left:, offset_top:, boundary:) end |
#update_profile_image(client:, file_path:, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile image
29 30 31 32 |
# File 'lib/x/account_uploader.rb', line 29 def update_profile_image(client:, file_path:, boundary: SecureRandom.hex) validate_file!(file_path) upload_profile_image_binary(client:, content: File.binread(file_path), boundary:) end |
#upload_profile_banner_binary(client:, content:, width: nil, height: nil, offset_left: nil, offset_top: nil, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile banner from binary content
86 87 88 89 90 91 |
# File 'lib/x/account_uploader.rb', line 86 def (client:, content:, width: nil, height: nil, offset_left: nil, offset_top: nil, boundary: SecureRandom.hex) body = (content:, width:, height:, offset_left:, offset_top:, boundary:) headers = {"Content-Type" => "multipart/form-data; boundary=#{boundary}"} v1_client(client).post("account/update_profile_banner.json", body, headers:) end |
#upload_profile_image_binary(client:, content:, boundary: SecureRandom.hex) ⇒ Hash?
Update the authenticating user’s profile image from binary content
43 44 45 46 47 |
# File 'lib/x/account_uploader.rb', line 43 def upload_profile_image_binary(client:, content:, boundary: SecureRandom.hex) body = construct_multipart_body(field_name: "image", content:, boundary:) headers = {"Content-Type" => "multipart/form-data; boundary=#{boundary}"} v1_client(client).post("account/update_profile_image.json", body, headers:) end |