Class: Rack::Facebook

Inherits:
Object show all
Defined in:
lib/kiss/rack/facebook.rb

Overview

Rack::Facebook formats HTTP responses to remove certain status codes and HTML entities that are invalid as FBML responses.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Facebook

Returns a new instance of Facebook.



5
6
7
# File 'lib/kiss/rack/facebook.rb', line 5

def initialize(app)
  @_app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kiss/rack/facebook.rb', line 9

def call(env)
  code, headers, body = @_app.call(env)
  
  if code >= 500 && code < 600
    code = 200
  end
  
  contents = ''
  body.each {|p| contents += p }
  
  contents.gsub!(/txmt:\/\//, 'http://textmate.local/')
  contents.gsub!('<body>', '<div class="body">')
  contents.gsub!('</body>', '</div>')
  contents.gsub!('<wbr/>', '')
  
  headers['Content-Length'] = contents.content_length.to_s
  
  [ code, headers, contents ]
end