rfacebook 0.6.9 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/facebook_session.rb +2 -2
- data/lib/facepricot.rb +146 -0
- metadata +3 -2
data/lib/facebook_session.rb
CHANGED
@@ -35,7 +35,7 @@
|
|
35
35
|
require "digest/md5"
|
36
36
|
require "net/https"
|
37
37
|
require "cgi"
|
38
|
-
require "
|
38
|
+
require "facepricot"
|
39
39
|
|
40
40
|
module RFacebook
|
41
41
|
|
@@ -179,7 +179,7 @@ class FacebookSession
|
|
179
179
|
|
180
180
|
# do the request
|
181
181
|
xmlstring = post_request(@api_server_base_url, @api_server_path, method, params, use_ssl)
|
182
|
-
xml =
|
182
|
+
xml = Facepricot.new(xmlstring)
|
183
183
|
|
184
184
|
# error checking
|
185
185
|
if xml.at("error_response")
|
data/lib/facepricot.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Copyright (c) 2007, Matt Pizzimenti (www.livelearncode.com)
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
# are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# Redistributions of source code must retain the above copyright notice,
|
8
|
+
# this list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# Neither the name of the original author nor the names of contributors
|
15
|
+
# may be used to endorse or promote products derived from this software
|
16
|
+
# without specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
21
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
22
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
#
|
29
|
+
|
30
|
+
require "hpricot"
|
31
|
+
|
32
|
+
# class HpricotHashWrapper
|
33
|
+
#
|
34
|
+
# def initialize(hpricotDoc)
|
35
|
+
# @doc = hpricotDoc
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# def to_hash
|
39
|
+
# puts "----"
|
40
|
+
# begin
|
41
|
+
# hashResult = {}
|
42
|
+
# @doc.each_child do |child|
|
43
|
+
# puts "child node: #{child}"
|
44
|
+
# hashResult[child.to_s] = HpricotHashWrapper.new(child).to_hash
|
45
|
+
# end
|
46
|
+
# return hashResult
|
47
|
+
# rescue
|
48
|
+
# return @doc.inner_html
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# end
|
53
|
+
|
54
|
+
module RFacebook
|
55
|
+
|
56
|
+
module FacepricotChaining
|
57
|
+
|
58
|
+
def make_facepricot_chain(key, doc)
|
59
|
+
|
60
|
+
if matches = /(.*)_list/.match(key)
|
61
|
+
listKey = matches[1]
|
62
|
+
end
|
63
|
+
|
64
|
+
result = nil
|
65
|
+
|
66
|
+
if !result
|
67
|
+
if listKey
|
68
|
+
result = doc.search("/#{listKey}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if !result
|
73
|
+
result = doc.at("/#{key}")
|
74
|
+
end
|
75
|
+
|
76
|
+
if !result
|
77
|
+
if listKey
|
78
|
+
result = doc.search("//#{listKey}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if !result
|
83
|
+
result = doc.at("//#{key}")
|
84
|
+
end
|
85
|
+
|
86
|
+
if result
|
87
|
+
if result.is_a?(Array)
|
88
|
+
return result.map{|r| FacepricotChain.new(r)}
|
89
|
+
else
|
90
|
+
return FacepricotChain.new(result)
|
91
|
+
end
|
92
|
+
else
|
93
|
+
return nil
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
class Facepricot
|
101
|
+
|
102
|
+
include FacepricotChaining
|
103
|
+
|
104
|
+
def initialize(xml)
|
105
|
+
@doc = Hpricot.XML(xml)
|
106
|
+
end
|
107
|
+
|
108
|
+
def method_missing(methodSymbol, *params)
|
109
|
+
begin
|
110
|
+
@doc.method(methodSymbol).call(*params) # pose as Hpricot document
|
111
|
+
rescue
|
112
|
+
return make_facepricot_chain(methodSymbol.to_s, @doc.containers[0])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def hpricot
|
117
|
+
return @doc
|
118
|
+
end
|
119
|
+
|
120
|
+
# def to_hash
|
121
|
+
# return HpricotHashWrapper.new(@doc.containers[0]).to_hash
|
122
|
+
# end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
class FacepricotChain < String
|
127
|
+
|
128
|
+
include FacepricotChaining
|
129
|
+
|
130
|
+
def initialize(hpricotDoc)
|
131
|
+
super(hpricotDoc.inner_html)
|
132
|
+
@doc = hpricotDoc
|
133
|
+
end
|
134
|
+
|
135
|
+
def method_missing(methodSymbol, *params)
|
136
|
+
return make_facepricot_chain(methodSymbol.to_s, @doc)
|
137
|
+
end
|
138
|
+
|
139
|
+
# def to_hash
|
140
|
+
# return HpricotHashWrapper.new(@doc).to_hash
|
141
|
+
# end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rfacebook
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.7.0
|
7
|
+
date: 2007-07-27 00:00:00 -07:00
|
8
8
|
summary: A Ruby interface to the Facebook API v1.0+. Supports the new features from F8.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/facebook_rails_controller_extensions.rb
|
34
34
|
- lib/facebook_session.rb
|
35
35
|
- lib/facebook_web_session.rb
|
36
|
+
- lib/facepricot.rb
|
36
37
|
- README
|
37
38
|
test_files: []
|
38
39
|
|