Skip to content

Commit

Permalink
Add Twitter::API#update_profile_banner and Twitter::API#remove_profil…
Browse files Browse the repository at this point in the history
…e_banner
  • Loading branch information
sferik committed Oct 6, 2012
1 parent fca4d17 commit 74b17f5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
41 changes: 39 additions & 2 deletions lib/twitter/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def update_profile(options={})
# @authentication_required Yes
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Twitter::User] The authenticated user.
# @param image [File, Hash] The background image for the profile. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be scaled down.
# @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.
# @param options [Hash] A customizable set of options.
# @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
# @example Update the authenticating user's profile background image
Expand Down Expand Up @@ -295,14 +295,51 @@ def update_profile_colors(options={})
# @authentication_required Yes
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Twitter::User] The authenticated user.
# @param image [File, Hash] The avatar image for the profile. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
# @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
# @param options [Hash] A customizable set of options.
# @example Update the authenticating user's profile image
# Twitter.update_profile_image(File.new("me.jpeg"))
def update_profile_image(image, options={})
object_from_response(Twitter::User, :post, "/1/account/update_profile_image.json", options.merge(:image => image))
end

# Updates the authenticating user's profile banner image
#
# @see https://dev.twitter.com/docs/api/1/post/account/update_profile_banner
# @note Uploads a profile banner on behalf of the authenticating user. For best results, upload an <5MB image that is exactly 1252px by 626px. Images will be resized for a number of display options. Users with an uploaded profile banner will have a profile_banner_url node in their Users objects. More information about sizing variations can be found in User Profile Images and Banners.
# @note Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
# @rate_limited No
# @authentication_required Requires user context
# @raise [Twitter::Error::BadRequest] Error raised when either an image was not provided or the image data could not be processed.
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @raise [Twitter::Error::UnprocessableEntity] Error raised when the image could not be resized or is too large.
# @return [nil]
# @param image [File] The Base64-encoded or raw image data being uploaded as the user's new profile banner.
# @param options [Hash] A customizable set of options.
# @option options [Integer] :width The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.
# @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.
# @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
# @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
# @example Update the authenticating user's profile banner
# Twitter.update_profile_banner(File.new("me.jpeg"))
def update_profile_banner(banner, options={})
post("/1/account/update_profile_banner.json", options.merge(:banner => banner))[:body]
end

# Removes the authenticating user's profile banner image
#
# @see https://dev.twitter.com/docs/api/1/post/account/remove_profile_banner
# @rate_limited No
# @authentication_required Requires user context
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [nil]
# @param options [Hash] A customizable set of options.
# @example Remove the authenticating user's profile banner image
# Twitter.remove_profile_banner
def remove_profile_banner(options={})
post("/1/account/remove_profile_banner.json", options)[:body]
end

# Updates the authenticating user's settings.
# Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
#
Expand Down
Empty file added spec/fixtures/empty.json
Empty file.
32 changes: 32 additions & 0 deletions spec/twitter/api/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,38 @@
end
end

describe "#update_profile_banner" do
before do
stub_post("/1/account/update_profile_banner.json").
to_return(:body => fixture("empty.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.update_profile_banner(fixture("me.jpeg"))
a_post("/1/account/update_profile_banner.json").
should have_been_made
end
it "returns a user" do
user = @client.update_profile_banner(fixture("me.jpeg"))
user.should be_nil
end
end

describe "#remove_profile_banner" do
before do
stub_post("/1/account/remove_profile_banner.json").
to_return(:body => fixture("empty.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.remove_profile_banner
a_post("/1/account/remove_profile_banner.json").
should have_been_made
end
it "returns a user" do
user = @client.remove_profile_banner
user.should be_nil
end
end

describe "#settings" do
before do
stub_get("/1/account/settings.json").
Expand Down

0 comments on commit 74b17f5

Please sign in to comment.