Class: Faces::Providers::Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/providers/twitter.rb

Overview

Twitter class handles all Twitter based avatar methods, check the information page for more details: nickpellant.com/open-source/faces/ruby/providers/twitter

Default required methods for providers are url and/or html, exists? All other methods are at the discretion of the developer Check the provider creation guide for more details: nickpellant.com/open-source/faces/ruby/developing-providers

Instance Method Summary collapse

Instance Method Details

#exists?(username, configuration = {}) ⇒ Boolean

Checks Avatar exists

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/providers/twitter.rb', line 31

def exists?(username, configuration = {})
  url = URI.parse(url(username, configuration))
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = (url.scheme == 'https')
  request = Net::HTTP::Get.new(url.path)
  response = http.request(request)
  response.code == '200' ? true : false
end

#html(username, configuration = {}) ⇒ Object

Constructs HTML <img /> tag for Twitter



24
25
26
27
# File 'lib/providers/twitter.rb', line 24

def html(username, configuration = {})
  m_configuration = Faces::Common.merge_configurations([Faces::Configuration::TWITTER, configuration])
  Faces::Public.generate_html(url(username, configuration), m_configuration)
end

#ssl?Boolean

Doesn’t support SSL

Returns:

  • (Boolean)


29
# File 'lib/providers/twitter.rb', line 29

def ssl?; false; end

#url(username, configuration = {}) ⇒ Object

Constructs Twitter url from username/configuration



19
20
21
22
# File 'lib/providers/twitter.rb', line 19

def url(username, configuration = {})
  m_configuration = Faces::Common.merge_configurations([Faces::Configuration::TWITTER, configuration])
  'http://img.tweetimag.es/i/' + username + '_' + size(m_configuration)
end