diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-11-30 23:01:03 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-11-30 23:01:03 +0100 |
commit | 6ff93845d55eb34fc8beceb0c2dde06860c1eb47 (patch) | |
tree | 4097796e3dc6daf8678c44473ba7611e025b618c /app/controllers | |
parent | 14bd46946d25186044485aa101dd2da976b61181 (diff) |
Add basic OEmbed provider API, fix #247
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/api/oembed_controller.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/controllers/api/oembed_controller.rb b/app/controllers/api/oembed_controller.rb new file mode 100644 index 000000000..4a591dc22 --- /dev/null +++ b/app/controllers/api/oembed_controller.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class Api::OembedController < ApiController + respond_to :json + + def show + @stream_entry = stream_entry_from_url(params[:url]) + @width = [300, params[:maxwidth].to_i].min + @height = [200, params[:maxheight].to_i].min + end + + private + + def stream_entry_from_url(url) + params = Rails.application.routes.recognize_path(url) + + raise ActiveRecord::NotFound unless params[:controller] == 'stream_entries' && params[:action] == 'show' + + StreamEntry.find(params[:id]) + end +end |