Module: Twitter::Profile

Includes:
Memoizable
Included in:
User
Defined in:
lib/twitter/profile.rb

Overview

Provides profile image and banner URL methods

Constant Summary collapse

PROFILE_IMAGE_SUFFIX_REGEX =

Regular expression for profile image suffix

/_normal(\.gif|\.jpe?g|\.png)$/i

Instance Method Summary collapse

Instance Method Details

#profile_banner_uri(size = :web) ⇒ URI::Generic Also known as: profile_banner_url

Returns the URL to the user's profile banner image

Examples:

user.profile_banner_uri(:web)

Parameters:

  • size (String, Symbol) (defaults to: :web) —

    The size of the image

Returns:

  • (URI::Generic)


18
19
20
# File 'lib/twitter/profile.rb', line 18

def profile_banner_uri(size = :web)
  parse_uri(insecure_uri([@attrs[:profile_banner_url], size].join("/"))) unless @attrs[:profile_banner_url].nil? # steep:ignore FallbackAny
end

#profile_banner_uri? ⇒ Boolean Also known as: profile_banner_url?, profile_banner_uri_https?, profile_banner_url_https?

Returns true if the user has a profile banner

Examples:

user.profile_banner_uri?

Returns:

  • (Boolean)


55
56
57
# File 'lib/twitter/profile.rb', line 55

def profile_banner_uri?
  !!@attrs[:profile_banner_url] # steep:ignore FallbackAny
end

#profile_banner_uri_https(size = :web) ⇒ URI::Generic Also known as: profile_banner_url_https

Returns the secure URL to the user's profile banner image

Examples:

user.profile_banner_uri_https(:web)

Parameters:

  • size (String, Symbol) (defaults to: :web) —

    The size of the image

Returns:

  • (URI::Generic)


37
38
39
# File 'lib/twitter/profile.rb', line 37

def profile_banner_uri_https(size = :web)
  parse_uri([@attrs[:profile_banner_url], size].join("/")) unless @attrs[:profile_banner_url].nil? # steep:ignore FallbackAny
end

#profile_image_uri(size = :normal) ⇒ URI::Generic Also known as: profile_image_url

Returns the URL to the user's profile image

Examples:

user.profile_image_uri(:normal)

Parameters:

  • size (String, Symbol) (defaults to: :normal) —

    The size of the image

Returns:

  • (URI::Generic)


70
71
72
# File 'lib/twitter/profile.rb', line 70

def profile_image_uri(size = :normal)
  parse_uri(insecure_uri(profile_image_uri_https(size))) unless @attrs[:profile_image_url_https].nil? # steep:ignore FallbackAny
end

#profile_image_uri? ⇒ Boolean Also known as: profile_image_url?, profile_image_uri_https?, profile_image_url_https?

Returns true if the user has a profile image

Examples:

user.profile_image_uri?

Returns:

  • (Boolean)


113
114
115
# File 'lib/twitter/profile.rb', line 113

def profile_image_uri?
  !!@attrs[:profile_image_url_https] # steep:ignore FallbackAny
end

#profile_image_uri_https(size = :normal) ⇒ URI::Generic Also known as: profile_image_url_https

Returns the secure URL to the user's profile image

Examples:

user.profile_image_uri_https(:normal)

Parameters:

  • size (String, Symbol) (defaults to: :normal) —

    The size of the image

Returns:

  • (URI::Generic)


89
90
91
92
93
94
95
96
97
# File 'lib/twitter/profile.rb', line 89

def profile_image_uri_https(size = :normal)
  # The profile image URL comes in looking like like this:
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_normal.png
  # It can be converted to any of the following sizes:
  # https://a0.twimg.com/profile_images/1759857427/image1326743606.png
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_mini.png
  # https://a0.twimg.com/profile_images/1759857427/image1326743606_bigger.png
  parse_uri(@attrs[:profile_image_url_https].sub(PROFILE_IMAGE_SUFFIX_REGEX, profile_image_suffix(size))) unless @attrs[:profile_image_url_https].nil? # steep:ignore FallbackAny
end