Module: Twitter::Profile

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

Constant Summary collapse

PROFILE_IMAGE_SUFFIX_REGEX =
/_normal(\.gif|\.jpe?g|\.png)$/i
PREDICATE_URI_METHOD_REGEX =
/_uri\?$/

Instance Method Summary collapse

Instance Method Details

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

Return the URL to the user's profile banner image

Parameters:

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

    The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'

Returns:

  • (Addressable::URI)


28
29
30
# File 'lib/twitter/profile.rb', line 28

def profile_banner_uri(size = :web)
  parse_uri(insecure_uri([@attrs[:profile_banner_url], size].join('/'))) unless @attrs[:profile_banner_url].nil?
end

#profile_banner_uri?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/twitter/profile.rb', line 43

def profile_banner_uri?
  !!@attrs[:profile_banner_url]
end

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

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

Parameters:

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

    The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina'

Returns:

  • (Addressable::URI)


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?
end

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

Return the URL to the user's profile image

Parameters:

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

    The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'

Returns:

  • (Addressable::URI)


53
54
55
# File 'lib/twitter/profile.rb', line 53

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

#profile_image_uri?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/twitter/profile.rb', line 74

def profile_image_uri?
  !!@attrs[:profile_image_url_https]
end

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

Return the secure URL to the user's profile image

Parameters:

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

    The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original'

Returns:

  • (Addressable::URI)


62
63
64
65
66
67
68
69
70
# File 'lib/twitter/profile.rb', line 62

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?
end