rfacebook 0.7.0 → 0.7.1
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_desktop_session.rb +0 -5
- data/lib/facebook_rails_controller_extensions.rb +30 -2
- data/lib/facebook_session.rb +41 -9
- data/lib/facebook_web_session.rb +0 -5
- data/lib/facepricot.rb +0 -22
- metadata +2 -2
@@ -27,11 +27,6 @@
|
|
27
27
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
28
|
#
|
29
29
|
|
30
|
-
#
|
31
|
-
# Some code was inspired by techniques used in Alpha Chen's old client.
|
32
|
-
# Some code was ported from the official PHP5 client.
|
33
|
-
#
|
34
|
-
|
35
30
|
require "facebook_session"
|
36
31
|
|
37
32
|
module RFacebook
|
@@ -1,10 +1,38 @@
|
|
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
|
+
|
1
30
|
require "facebook_web_session"
|
2
31
|
|
3
32
|
module RFacebook
|
4
33
|
|
5
34
|
module RailsControllerExtensions
|
6
|
-
|
7
|
-
|
35
|
+
|
8
36
|
# SECTION: StandardErrors
|
9
37
|
|
10
38
|
class APIKeyNeededStandardError < StandardError; end
|
data/lib/facebook_session.rb
CHANGED
@@ -86,11 +86,22 @@ class FacebookSession
|
|
86
86
|
@last_error = nil
|
87
87
|
@session_expired = false
|
88
88
|
|
89
|
+
# cache object for API calls
|
90
|
+
@callcache = {}
|
91
|
+
|
89
92
|
end
|
90
93
|
|
91
94
|
def session_expired?
|
92
95
|
return (@session_expired == true)
|
93
96
|
end
|
97
|
+
|
98
|
+
def logger
|
99
|
+
return @logger
|
100
|
+
end
|
101
|
+
|
102
|
+
def logger=(externalLogger)
|
103
|
+
@logger = externalLogger
|
104
|
+
end
|
94
105
|
|
95
106
|
# SECTION: Public Abstract Interface
|
96
107
|
|
@@ -133,9 +144,30 @@ class FacebookSession
|
|
133
144
|
# this converts a call to "auth_getSession" to "auth.getSession"
|
134
145
|
# and does the proper API call using the parameter hash given.
|
135
146
|
def method_missing(methodSymbol, *params)
|
136
|
-
|
137
|
-
|
138
|
-
|
147
|
+
tokens = methodSymbol.to_s.split("_")
|
148
|
+
if tokens[0] == "cached"
|
149
|
+
tokens.shift
|
150
|
+
return cached_call_method(tokens.join("."), params.first)
|
151
|
+
else
|
152
|
+
return call_method(tokens.join("."), params.first)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def cached_call_method(method,params)
|
157
|
+
key = cache_key_for(method,params)
|
158
|
+
@logger.debug "RFacebook::FacebookSession\#cached_call_method - #{method}(#{params.inspect}) - attempting to hit cache" if @logger
|
159
|
+
return @callcache[key] ||= call_method(method,params)
|
160
|
+
end
|
161
|
+
|
162
|
+
def cache_key_for(method,params)
|
163
|
+
pairs = []
|
164
|
+
params.each do |k,v|
|
165
|
+
if v.is_a?(Array)
|
166
|
+
v = v.join(",")
|
167
|
+
end
|
168
|
+
pairs << "#{k}=#{v}"
|
169
|
+
end
|
170
|
+
return "#{method}(#{pairs.sort.join("...")})".to_sym
|
139
171
|
end
|
140
172
|
|
141
173
|
|
@@ -147,7 +179,9 @@ class FacebookSession
|
|
147
179
|
# params - hash of key,value pairs for the parameters to this method
|
148
180
|
# use_ssl - set to true if the call will be made over SSL
|
149
181
|
def call_method(method, params={}, use_ssl=false)
|
150
|
-
|
182
|
+
|
183
|
+
@logger.debug "RFacebook::FacebookSession\#call_method - #{method}(#{params.inspect}) - making remote call" if @logger
|
184
|
+
|
151
185
|
# ensure that this object has been activated somehow
|
152
186
|
if (!method.include?("auth") and !is_activated?)
|
153
187
|
raise NotActivatedStandardError, "You must activate the session before using it."
|
@@ -175,7 +209,6 @@ class FacebookSession
|
|
175
209
|
|
176
210
|
# prepare internal state
|
177
211
|
@last_call_was_successful = true
|
178
|
-
#@last_error = nil
|
179
212
|
|
180
213
|
# do the request
|
181
214
|
xmlstring = post_request(@api_server_base_url, @api_server_path, method, params, use_ssl)
|
@@ -183,6 +216,9 @@ class FacebookSession
|
|
183
216
|
|
184
217
|
# error checking
|
185
218
|
if xml.at("error_response")
|
219
|
+
|
220
|
+
@logger.debug "RFacebook::FacebookSession\#call_method - #{method}(#{params.inspect}) - remote call failed" if @logger
|
221
|
+
|
186
222
|
@last_call_was_successful = false
|
187
223
|
code = xml.at("error_code").inner_html
|
188
224
|
msg = xml.at("error_msg").inner_html
|
@@ -219,7 +255,6 @@ class FacebookSession
|
|
219
255
|
# params - hash of key/value pairs that get sent as form data to the server
|
220
256
|
# use_ssl - set to true if you want to use SSL for this request
|
221
257
|
def post_request(api_server_base_url, api_server_path, method, params, use_ssl)
|
222
|
-
|
223
258
|
# get a server handle
|
224
259
|
port = (use_ssl == true) ? 443 : 80
|
225
260
|
http_server = Net::HTTP.new(@api_server_base_url, port)
|
@@ -232,7 +267,6 @@ class FacebookSession
|
|
232
267
|
|
233
268
|
# return the text of the body
|
234
269
|
return response
|
235
|
-
|
236
270
|
end
|
237
271
|
|
238
272
|
# Function: param_signature
|
@@ -243,7 +277,6 @@ class FacebookSession
|
|
243
277
|
end
|
244
278
|
|
245
279
|
def generate_signature(hash, secret)
|
246
|
-
|
247
280
|
args = []
|
248
281
|
hash.each do |k,v|
|
249
282
|
args << "#{k}=#{v}"
|
@@ -251,7 +284,6 @@ class FacebookSession
|
|
251
284
|
sortedArray = args.sort
|
252
285
|
requestStr = sortedArray.join("")
|
253
286
|
return Digest::MD5.hexdigest("#{requestStr}#{secret}")
|
254
|
-
|
255
287
|
end
|
256
288
|
|
257
289
|
end
|
data/lib/facebook_web_session.rb
CHANGED
@@ -27,11 +27,6 @@
|
|
27
27
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
28
|
#
|
29
29
|
|
30
|
-
#
|
31
|
-
# Some code was inspired by techniques used in Alpha Chen's old client.
|
32
|
-
# Some code was ported from the official PHP5 client.
|
33
|
-
#
|
34
|
-
|
35
30
|
require "facebook_session"
|
36
31
|
|
37
32
|
module RFacebook
|
data/lib/facepricot.rb
CHANGED
@@ -29,28 +29,6 @@
|
|
29
29
|
|
30
30
|
require "hpricot"
|
31
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
32
|
module RFacebook
|
55
33
|
|
56
34
|
module FacepricotChaining
|
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.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.7.1
|
7
|
+
date: 2007-07-30 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
|