Class: NameChecker::FacebookChecker

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Logging
Defined in:
lib/name_checker/facebook_checker.rb

Constant Summary collapse

MIN_NAME_LENGTH =
5

Class Method Summary collapse

Methods included from Logging

infer_level, logger, #logger

Class Method Details

.check(name, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/name_checker/facebook_checker.rb', line 9

def self.check(name, options = {})
  # just return false if the name is too short to be valid.
  if name.length < MIN_NAME_LENGTH
    return Availability.new(@service_name, false)
  end

  res = get("/#{name}")
# So Facebook is bolloxed and sends back just the word 'false'
# as the (invalid) json for certain queries. This causes a
# MultiJson::DecodeError inside HTTParty which we need to catch.
# INFO: http://stackoverflow.com/q/7357493/574190
rescue MultiJson::DecodeError
  Availability.new(@service_name, false)
else
  status = handle_response(res, name)
  Availability.new(@service_name, status)
end