Class: SimpleFacebookConnect::Parser
- Inherits:
-
Object
- Object
- SimpleFacebookConnect::Parser
show all
- Defined in:
- lib/simple_facebook_connect/parser.rb
Defined Under Namespace
Modules: REXMLElementExtensions
Classes: CreateToken, Errors, GetLoggedInUser, GetSession, ProfileInfo, RegisterUsers, RevokeAuthorization, UserInfo, UserStandardInfo
Constant Summary
collapse
- PARSERS =
{
'facebook.auth.revokeAuthorization' => RevokeAuthorization,
'facebook.auth.createToken' => CreateToken,
'facebook.auth.getSession' => GetSession,
'facebook.connect.registerUsers' => RegisterUsers,
'facebook.users.getInfo' => UserInfo,
'facebook.users.getStandardInfo' => UserStandardInfo,
'facebook.profile.getInfo' => ProfileInfo
}
Class Method Summary
collapse
Class Method Details
.anonymous_field_from(child, hash) ⇒ Object
87
88
89
90
91
|
# File 'lib/simple_facebook_connect/parser.rb', line 87
def self.anonymous_field_from(child, hash)
if child.name == 'anon'
(hash[child.name] || []) << child.text_value
end
end
|
.array_of(response_element, element_name) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/simple_facebook_connect/parser.rb', line 25
def self.array_of(response_element, element_name)
values_to_return = []
response_element.elements.each(element_name) do |element|
values_to_return << yield(element)
end
values_to_return
end
|
.array_of_hashes(response_element, element_name) ⇒ Object
39
40
41
42
43
|
# File 'lib/simple_facebook_connect/parser.rb', line 39
def self.array_of_hashes(response_element, element_name)
array_of(response_element, element_name) do |element|
hashinate(element)
end
end
|
.array_of_text_values(response_element, element_name) ⇒ Object
33
34
35
36
37
|
# File 'lib/simple_facebook_connect/parser.rb', line 33
def self.array_of_text_values(response_element, element_name)
array_of(response_element, element_name) do |element|
element.text_value
end
end
|
.booleanize(response) ⇒ Object
83
84
85
|
# File 'lib/simple_facebook_connect/parser.rb', line 83
def self.booleanize(response)
response == "1" ? true : false
end
|
.element(name, data) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/simple_facebook_connect/parser.rb', line 45
def self.element(name, data)
data = data.body rescue data doc = REXML::Document.new(data)
doc.elements.each(name) do |element|
return element
end
raise "Element #{name} not found in #{data}"
end
|
.hash_or_value_for(element) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/simple_facebook_connect/parser.rb', line 54
def self.hash_or_value_for(element)
if element.children.size == 1 && element.children.first.kind_of?(REXML::Text)
element.text_value
else
hashinate(element)
end
end
|
.hashinate(response_element) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/simple_facebook_connect/parser.rb', line 62
def self.hashinate(response_element)
response_element.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |hash, child|
hash[child.name] =
if (child.attributes['nil'] == 'true')
nil
elsif (child.children.size == 1 && child.children.first.kind_of?(REXML::Text)) || (child.children.size == 0 && child.attributes['list'] != 'true')
anonymous_field_from(child, hash) || child.text_value
elsif child.attributes['list'] == 'true'
child.children.reject{|c| c.kind_of? REXML::Text}.map { |subchild| hash_or_value_for(subchild)}
else
child.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |subhash, subchild|
subhash[subchild.name] = hash_or_value_for(subchild)
subhash
end
end hash
end end
|
.parse(method, data) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/simple_facebook_connect/parser.rb', line 17
def self.parse(method, data)
Errors.process(data)
parser = PARSERS[method]
parser.process(
data
)
end
|