Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Twitter::API#profile_banner

  • Loading branch information...
commit 5879ef3fcc486ac3849426ef0d44ee0288ed9599 1 parent a5dd0db
@stve stve authored
View
23 lib/twitter/api.rb
@@ -14,6 +14,7 @@
require 'twitter/list'
require 'twitter/oembed'
require 'twitter/place'
+require 'twitter/profile_banner'
require 'twitter/relationship'
require 'twitter/saved_search'
require 'twitter/search_results'
@@ -169,6 +170,28 @@ def remove_profile_banner(options={})
post("/1.1/account/remove_profile_banner.json", options)[:body]
end
+ # Returns the available size variations of the specified user's profile banner.
+ #
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
+ # @note If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
+ # @rate_limited Yes
+ # @authentication_required Requires user context
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
+ # @return [Twitter::ProfileBanner]
+ # @overload profile_banner(options={})
+ # @example Return the authenticated user's profile banner
+ # Twitter.profile_banner
+ # @overload profile_banner(user, options={})
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
+ # @example Return the specified user's profile banner
+ # Twitter.profile_banner('sferik')
+ # Twitter.profile_banner(7505382) # Same as above
+ def profile_banner(*args)
+ options = args.extract_options!
+ options.merge_user!(args.pop || screen_name)
+ object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", options)
+ 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.
#
View
18 lib/twitter/media/profile_banner.rb
@@ -0,0 +1,18 @@
+require 'twitter/base'
+require 'twitter/size'
+
+module Twitter
+ class ProfileBanner < Twitter::Base
+
+ # Returns an array of photo sizes
+ #
+ # @return [Array<Twitter::Size>]
+ def sizes
+ @sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
+ object[key] = Twitter::Size.fetch_or_new(value)
+ object
+ end
+ end
+
+ end
+end
View
18 lib/twitter/profile_banner.rb
@@ -0,0 +1,18 @@
+require 'twitter/base'
+require 'twitter/size'
+
+module Twitter
+ class ProfileBanner < Twitter::Base
+
+ # Returns an array of photo sizes
+ #
+ # @return [Array<Twitter::Size>]
+ def sizes
+ @sizes ||= Array(@attrs[:sizes]).inject({}) do |object, (key, value)|
+ object[key] = Twitter::Size.fetch_or_new(value)
+ object
+ end
+ end
+
+ end
+end
View
1  spec/fixtures/profile_banner.json
@@ -0,0 +1 @@
+{"sizes":{"mobile_retina":{"h":320,"w":640,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/mobile_retina"},"ipad":{"h":313,"w":626,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/ipad"},"mobile":{"h":160,"w":320,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/mobile"},"ipad_retina":{"h":626,"w":1252,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/ipad_retina"},"web_retina":{"h":520,"w":1040,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/web_retina"},"web":{"h":260,"w":520,"url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693\/web"}}}
View
35 spec/twitter/api/users_spec.rb
@@ -325,4 +325,39 @@
end
end
+ describe '#profile_banner' do
+ context "with a screen_name passed" do
+ before do
+ stub_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("profile_banner.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "requests the correct resource" do
+ @client.profile_banner('sferik')
+ expect(a_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"})).to have_been_made
+ end
+ it "returns a user's profile banner" do
+ banner = @client.profile_banner('sferik')
+ expect(banner).to be_an Twitter::ProfileBanner
+ expect(banner.sizes).to be_a Hash
+ expect(banner.sizes[:mobile].height).to eq 160
+ end
+ end
+ context "without arguments passed" do
+ before do
+ stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ stub_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("profile_banner.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "requests the correct resource" do
+ @client.profile_banner
+ expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made
+ expect(a_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"})).to have_been_made
+ end
+ it "returns an array of numeric IDs for every user following the specified user" do
+ banner = @client.profile_banner
+ expect(banner).to be_an Twitter::ProfileBanner
+ expect(banner.sizes).to be_a Hash
+ expect(banner.sizes[:mobile].height).to eq 160
+ end
+ end
+ end
+
end
View
13 spec/twitter/profile_banner_spec.rb
@@ -0,0 +1,13 @@
+require 'helper'
+
+describe Twitter::ProfileBanner do
+
+ describe "#sizes" do
+ it "returns a hash of Sizes when sizes is set" do
+ sizes = Twitter::ProfileBanner.new(:sizes => {:small => {:h => 226, :w => 340, :resize => 'fit'}, :large => {:h => 466, :w => 700, :resize => 'fit'}, :medium => {:h => 399, :w => 600, :resize => 'fit'}, :thumb => {:h => 150, :w => 150, :resize => 'crop'}}).sizes
+ expect(sizes).to be_a Hash
+ expect(sizes[:small]).to be_a Twitter::Size
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.