WpUser additional specs
This commit is contained in:
@@ -43,6 +43,7 @@ module Typhoeus
|
||||
|
||||
body_hash != error_404_hash && body_hash != homepage_hash
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ class WpUser < WpItem
|
||||
|
||||
attr_accessor :id, :login, :display_name, :password
|
||||
|
||||
# @return [ Array<Symbol> ]
|
||||
def allowed_options; [:id, :login, :display_name, :password] end
|
||||
|
||||
# @return [ URI ] The uri to the auhor page
|
||||
@@ -32,11 +33,15 @@ class WpUser < WpItem
|
||||
end
|
||||
|
||||
# @param [ WpUser ] other
|
||||
#
|
||||
# @return [ Boolean ]
|
||||
def ==(other)
|
||||
self === other
|
||||
end
|
||||
|
||||
# @param [ WpUser ] other
|
||||
#
|
||||
# @return [ Boolean ]
|
||||
def ===(other)
|
||||
id === other.id && login === other.login
|
||||
end
|
||||
|
||||
@@ -22,13 +22,13 @@ class WpUser < WpItem
|
||||
if response.code == 301 # login in location?
|
||||
location = response.headers_hash['Location']
|
||||
|
||||
@login = WpUser::Existable.login_from_author_pattern(location)
|
||||
@display_name = WpUser::Existable.display_name_from_body(
|
||||
@login = Existable.login_from_author_pattern(location)
|
||||
@display_name = Existable.display_name_from_body(
|
||||
Browser.instance.get(location).body
|
||||
)
|
||||
elsif response.code == 200 # login in body?
|
||||
@login = WpUser::Existable.login_from_body(response.body)
|
||||
@display_name = WpUser::Existable.display_name_from_body(response.body)
|
||||
@login = Existable.login_from_body(response.body)
|
||||
@display_name = Existable.display_name_from_body(response.body)
|
||||
end
|
||||
end
|
||||
private :load_from_response
|
||||
@@ -55,16 +55,22 @@ class WpUser < WpItem
|
||||
login
|
||||
end
|
||||
|
||||
# @note Some bodies are encoded in ASCII-8BIT, and Nokogiri doesn't support it
|
||||
# So it's forced to UTF-8 when this encoding is detected
|
||||
#
|
||||
# @param [ String ] body
|
||||
#
|
||||
# @return [ String ] The display_name
|
||||
def self.display_name_from_body(body)
|
||||
if title_tag = body[%r{<title>([^<]+)</title>}i, 1]
|
||||
title_tag.force_encoding('UTF-8') if title_tag.encoding == Encoding::ASCII_8BIT
|
||||
title_tag = Nokogiri::HTML::DocumentFragment.parse(title_tag).to_s
|
||||
# & are not decoded with Nokogiri
|
||||
title_tag.sub!('&', '&')
|
||||
|
||||
return title_tag[%r{([^|«]+) }, 1]
|
||||
name = title_tag[%r{([^|«]+) }, 1]
|
||||
|
||||
return name.strip if name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user