module Twitter::Profile

Constants

PREDICATE_URI_METHOD_REGEX
PROFILE_IMAGE_SUFFIX_REGEX

Private Class Methods

alias_method_sub(method, pattern, replacement) click to toggle source
# File lib/twitter/profile.rb, line 19
def alias_method_sub(method, pattern, replacement)
  alias_method(method.to_s.sub(pattern, replacement).to_sym, method)
end
alias_predicate_uri_methods(method) click to toggle source
# File lib/twitter/profile.rb, line 13
def alias_predicate_uri_methods(method)
  %w(_url? _uri_https? _url_https?).each do |replacement|
    alias_method_sub(method, PREDICATE_URI_METHOD_REGEX, replacement)
  end
end

Public Instance Methods

profile_banner_uri(size = :web) click to toggle source

Return the URL to the user's profile banner image

@param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina' @return [Addressable::URI]

# 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
Also aliased as: profile_banner_url
profile_banner_uri?() click to toggle source

@return [Boolean]

# File lib/twitter/profile.rb, line 43
def profile_banner_uri?
  !!@attrs[:profile_banner_url]
end
profile_banner_uri_https(size = :web) click to toggle source

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

@param size [String, Symbol] The size of the image. Must be one of: 'mobile', 'mobile_retina', 'web', 'web_retina', 'ipad', or 'ipad_retina' @return [Addressable::URI]

# 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
Also aliased as: profile_banner_url_https
profile_banner_url(size = :web)
Alias for: profile_banner_uri
profile_banner_url_https(size = :web)
profile_image_uri(size = :normal) click to toggle source

Return the URL to the user's profile image

@param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original' @return [Addressable::URI]

# 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
Also aliased as: profile_image_url
profile_image_uri?() click to toggle source

@return [Boolean]

# File lib/twitter/profile.rb, line 74
def profile_image_uri?
  !!@attrs[:profile_image_url_https]
end
profile_image_uri_https(size = :normal) click to toggle source

Return the secure URL to the user's profile image

@param size [String, Symbol] The size of the image. Must be one of: 'mini', 'normal', 'bigger' or 'original' @return [Addressable::URI]

# 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
Also aliased as: profile_image_url_https
profile_image_url(size = :normal)
Alias for: profile_image_uri
profile_image_url_https(size = :normal)

Private Instance Methods

insecure_uri(uri) click to toggle source
# File lib/twitter/profile.rb, line 86
def insecure_uri(uri)
  uri.to_s.sub(/^https/i, 'http')
end
parse_uri(uri) click to toggle source
# File lib/twitter/profile.rb, line 82
def parse_uri(uri)
  Addressable::URI.parse(uri)
end
profile_image_suffix(size) click to toggle source
# File lib/twitter/profile.rb, line 90
def profile_image_suffix(size)
  :original == size.to_sym ? '\1' : "_#{size}\\1"
end