asciinema.org/app/controllers/api/asciicasts_controller.rb

54 lines
1.2 KiB
Ruby
Raw Normal View History

module Api
class AsciicastsController < BaseController
before_filter :ensure_authenticated!, only: :create
respond_to :html, only: [:show]
attr_reader :asciicast
def create
asciicast = asciicast_creator.create(asciicast_attributes)
render text: asciicast_url(asciicast), status: :created,
location: asciicast
rescue ActiveRecord::RecordInvalid => e
render text: e.record.errors.messages, status: 422
2015-03-23 16:40:11 +00:00
rescue AsciicastParams::FormatError => e
render text: e.message, status: 400
end
def show
@asciicast = Asciicast.find_by_id_or_secret_token!(params[:id])
2014-10-19 11:25:51 +00:00
respond_with(asciicast) do |format|
format.html do
allow_iframe_requests
render locals: {
page: BareAsciicastPagePresenter.build(asciicast, params)
}, layout: 'bare'
end
format.json do
render json: asciicast, v0: params[:v0]
end
end
end
private
def asciicast_attributes
AsciicastParams.build(params[:asciicast], current_user, request.user_agent)
2015-02-27 13:58:04 +00:00
end
def asciicast_creator
AsciicastCreator.new
end
def allow_iframe_requests
response.headers.delete('X-Frame-Options')
end
end
end