Class: Rack::Oembed

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/oembed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Oembed

Returns a new instance of Oembed.



5
6
7
8
9
# File 'lib/rack/oembed.rb', line 5

def initialize(app, options={})
  @app = app
  @oembed_path = options.fetch :path
  @oembed_path = "/#{oembed_path}" unless oembed_path.starts_with? "/"
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



3
4
5
# File 'lib/rack/oembed.rb', line 3

def app
  @app
end

#oembed_pathObject (readonly)

Returns the value of attribute oembed_path.



3
4
5
# File 'lib/rack/oembed.rb', line 3

def oembed_path
  @oembed_path
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rack/oembed.rb', line 11

def call(env)
  if env["REQUEST_METHOD"] == "GET" && env["PATH_INFO"] == oembed_path
    url = Rack::Request.new(env).params.fetch("url")
    path = Addressable::URI.parse(url).path
    env["PATH_INFO"] = path
    env["HTTP_ACCEPT"] = "application/json+oembed"
  end

  app.call(env)
end