mini_fb 0.1.2 → 0.1.3

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/README.markdown CHANGED
@@ -3,6 +3,13 @@ MiniFB - the simple miniature facebook library
3
3
 
4
4
  MiniFB is a small, lightweight Ruby library for interacting with the [Facebook API](http://wiki.developers.facebook.com/index.php/API).
5
5
 
6
+ Installation
7
+ -------------
8
+
9
+ We're using gemcutter so be sure to have gemcutter as a source, then:
10
+
11
+ gem install mini_fb
12
+
6
13
  General Usage
7
14
  -------------
8
15
 
@@ -35,4 +42,8 @@ Or if you want other photos, try:
35
42
 
36
43
  photos = @fb.photos("pids"=>[12343243,920382343,9208348])
37
44
 
45
+ Support
46
+ --------
47
+
48
+ Join our Discussion Group at: http://groups.google.com/group/mini_fb
38
49
 
data/lib/mini_fb.rb CHANGED
@@ -12,6 +12,7 @@ module MiniFB
12
12
  def enable_logging
13
13
  @@logging = true
14
14
  end
15
+
15
16
  def disable_logging
16
17
  @@logging = false
17
18
  end
@@ -130,6 +131,10 @@ module MiniFB
130
131
 
131
132
  puts 'kwargs=' + kwargs.inspect
132
133
 
134
+ if secret.is_a? String
135
+ secret = FaceBookSecret.new(secret)
136
+ end
137
+
133
138
  # Prepare arguments for call
134
139
  call_id = kwargs.fetch("call_id", true)
135
140
  if call_id == true then
@@ -146,6 +151,7 @@ module MiniFB
146
151
 
147
152
  # Hash with secret
148
153
  arg_string = String.new
154
+ # todo: convert symbols to strings, symbols break the next line
149
155
  kwargs.sort.each { |kv| arg_string << kv[0] << "=" << kv[1].to_s }
150
156
  kwargs["sig"] = Digest::MD5.hexdigest( arg_string + secret.value.call )
151
157
 
@@ -167,6 +173,35 @@ module MiniFB
167
173
  return data
168
174
  end
169
175
 
176
+ # Returns true is signature is valid, false otherwise.
177
+ def MiniFB.verify_signature( secret, arguments )
178
+ signature = arguments.delete( "fb_sig" )
179
+ return false if signature.nil?
180
+
181
+ unsigned = Hash.new
182
+ signed = Hash.new
183
+
184
+ arguments.each do |k, v|
185
+ if k =~ /^fb_sig_(.*)/ then
186
+ signed[$1] = v
187
+ else
188
+ unsigned[k] = v
189
+ end
190
+ end
191
+
192
+ arg_string = String.new
193
+ signed.sort.each { |kv| arg_string << kv[0] << "=" << kv[1] }
194
+ if Digest::MD5.hexdigest( arg_string + secret ) == signature
195
+ return true
196
+ end
197
+ return false
198
+ end
199
+
200
+ def self.login_url(api_key, go_next=nil)
201
+ login_url = "http://api.facebook.com/login.php"
202
+ next_param = go_next.blank? ? "" : "&next=#{go_next}"
203
+ return "#{login_url}?api_key=#{api_key}#{next_param}"
204
+ end
170
205
 
171
206
  # This function expects arguments as a hash, so
172
207
  # it is agnostic to different POST handling variants in ruby.
@@ -185,6 +220,7 @@ module MiniFB
185
220
  # The secret argument should be an instance of FacebookSecret
186
221
  # to hide value from simple introspection.
187
222
  #
223
+ # DEPRECATED, use verify_signature instead
188
224
  def MiniFB.validate( secret, arguments )
189
225
 
190
226
  signature = arguments.delete( "fb_sig" )
@@ -203,7 +239,7 @@ module MiniFB
203
239
 
204
240
  arg_string = String.new
205
241
  signed.sort.each { |kv| arg_string << kv[0] << "=" << kv[1] }
206
- if Digest::MD5.hexdigest( arg_string + secret ) != signature then
242
+ if Digest::MD5.hexdigest( arg_string + secret ) != signature
207
243
  unsigned # Hash is incorrect, return only unsigned fields.
208
244
  else
209
245
  unsigned.merge signed
@@ -6,6 +6,9 @@ class MiniFBTests < Test::Unit::TestCase
6
6
  end
7
7
  def teardown
8
8
 
9
+ end
10
+ def test_signature
11
+
9
12
  end
10
13
 
11
14
  def test_basic_calls
@@ -19,4 +22,5 @@ class MiniFBTests < Test::Unit::TestCase
19
22
  def test_photos
20
23
 
21
24
  end
25
+
22
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_fb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 -07:00
12
+ date: 2009-11-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15