Class: Dailycred::Middleware
- Inherits:
-
Object
- Object
- Dailycred::Middleware
- Defined in:
- lib/dailycred/middleware.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, client_id, opts = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, client_id, opts = {}) ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 8 9 10 11 12 13 |
# File 'lib/dailycred/middleware.rb', line 5 def initialize(app, client_id, opts={}) @opts = opts @opts[:url] ||= "https://www.dailycred.com" @opts[:modal] ||= false @opts[:sdk] ||= false @opts[:triggers] ||= [] @app = app @client_id = client_id end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
3 4 5 |
# File 'lib/dailycred/middleware.rb', line 3 def client_id @client_id end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dailycred/middleware.rb', line 15 def call(env) @env = env @status, @headers, @response = @app.call(env) if @headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/ body = "" @response.each { |part| body << part } index = body.rindex("</body>") if index body.insert(index, render_dailycred_scripts) @headers["Content-Length"] = body.length.to_s @response = [body] end end @env['rack.session']['omniauth.state'] ||= SecureRandom.hex(24) [@status, @headers, @response] end |