Module: UserProfileFormatter

Defined in:
lib/user_profile_formatter.rb,
lib/user_profile_formatter/railtie.rb,
lib/user_profile_formatter/version.rb,
lib/user_profile_formatter/social_media.rb,
lib/user_profile_formatter/login_checker.rb,
lib/user_profile_formatter/model_additions.rb

Defined Under Namespace

Modules: ModelAdditions Classes: Railtie

Constant Summary collapse

VERSION =
"0.0.1"
SOCIAL =
{
  twitter: {format: %r(\w{1,15}), url: "http://twitter.com/{{NAME}}"},
  facebook: {format: %r([a-zA-Z0-9.]{5,}), url: "https://www.facebook.com/{{NAME}}"},
  youtube: {format: %r([A-Za-z0-9]{3,20}), url: "http://www.youtube.com/user/{{NAME}}"},
  tumblr: {format: %r([a-z0-9][a-z0-9]{0,31}), url: "http://{{NAME}}.tumblr.com/"},
  goldenline: {format: %r([0-9a-zA-Z]*[-_][0-9a-zA-Z]*[-_][0-9a-zA-Z]*|[0-9a-zA-Z]*[-_][0-9a-zA-Z]*), url: "http://www.goldenline.pl/{{NAME}}"},
  blip: {format: %r([a-z][a-z0-9]{2,24}), url: "http://{{NAME}}.blip.pl/"}
}

Class Method Summary collapse

Class Method Details

.exists?(name, url) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/user_profile_formatter/login_checker.rb', line 6

def self.exists?(name, url)
  uri = URI.parse(url.gsub(/{{NAME}}/, name))
  http = Net::HTTP.new(uri.host, uri.port)
  if url.start_with? "https"
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  answer = nil
  http.start do
    answer = http.get(uri.path).code
  end
  answer == "200"
end

.format(key) ⇒ Object



19
20
21
# File 'lib/user_profile_formatter/social_media.rb', line 19

def self.format(key)
  SOCIAL[key][:format]
end

.format_user_profile(name, key) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/user_profile_formatter.rb', line 10

def self.(name, key)
  pattern = format(key)
  match_data = pattern.match(name)
  return nil if match_data.nil? or match_data[0] != name
  return nil unless exists? name, url(key)
  name
end

.keysObject

Following sites don’t return code 404: eBay, Allegro



15
16
17
# File 'lib/user_profile_formatter/social_media.rb', line 15

def self.keys
  SOCIAL.keys
end

.url(key) ⇒ Object



23
24
25
# File 'lib/user_profile_formatter/social_media.rb', line 23

def self.url(key)
  SOCIAL[key][:url]
end