Class: Wco::Api::NewspartialsController
- Inherits:
-
Wco::ApiController
- Object
- Wco::ApiController
- Wco::Api::NewspartialsController
- Defined in:
- app/controllers/wco/api/newspartials_controller.rb
Instance Method Summary collapse
-
#add_config ⇒ Object
PUT config, actually.
- #create ⇒ Object
-
#generate_speech ⇒ Object
syncronous, everyone waits.
- #show_config ⇒ Object
Instance Method Details
#add_config ⇒ Object
PUT config, actually
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/wco/api/newspartials_controller.rb', line 9 def add_config puts! params, 'api newspartials#add_config params' @newspartial = Wco::Newspartial.find params[:id] :create, @newspartial raw_payload = request.raw_post # parsed_payload = JSON.parse(raw_payload) @newspartial.config_json = raw_payload if @newspartial.save puts! @newspartial, 'added config to a newspartial.' flash[:notice] = 'Success' render json: { status: :ok, message: 'added config to a newspartial.' } else flash[:alert] = 'No luck' render json: { status: :not_ok, message: "Could not add config to newspartial: #{@newspartial.errors..join(', ')}." } end end |
#create ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/wco/api/newspartials_controller.rb', line 30 def create puts! params, 'api newspartials#create params' @newspartial = Wco::Newspartial.new params[:newspartial].permit! @newspartial. = Wco::Profile.find_by email: current_user.email :create, @newspartial if @newspartial.save puts! @newspartial, 'Created a newspartial.' flash[:notice] = 'Success' render json: { status: :ok, message: @newspartial.attributes } else flash[:alert] = 'No luck' render json: { status: :not_ok, message: "Could not create a newspartial: #{@newspartial.errors..join(', ')}." } end end |
#generate_speech ⇒ Object
syncronous, everyone waits.
48 49 50 51 52 |
# File 'app/controllers/wco/api/newspartials_controller.rb', line 48 def generate_speech @newspartial = Wco::Newspartial.unscoped.find params[:id] @newspartial.generate_speech render json: { status: :ok } end |
#show_config ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/controllers/wco/api/newspartials_controller.rb', line 54 def show_config @newspartial = Wco::Newspartial.find params[:id] config = JSON.parse @newspartial.speech_json config[:w_px] = @newspartial.newsvideo.w_px config[:h_px] = @newspartial.newsvideo.h_px config[:slug] = "#{@newspartial.newsvideo.slug}::#{@newspartial.slug}" render json: config end |