BetterVideo API

This commit is contained in:
Tyrel Souza 2014-04-29 17:05:21 -04:00
parent 87bf720236
commit 21490ba03f
5 changed files with 35 additions and 9 deletions

View File

@ -38,14 +38,25 @@ class CampaignsController < ApplicationController
end end
def update def update
notice = 'Campaign was saved for later use. It is not published yet.'
if @campaign.update(campaign_params) if @campaign.update(campaign_params)
if params[:send] if params[:send]
@campaign.update({sent: true}) client = BetterVideo.new(:url => "xxx")
bv_response = client.addVideo(campaign: @campaign)
if bv_response[:success]
notice = bv_response[:message]
@campaign.update({sent: true})
return redirect_to campaign_path(@campaign.listingcode), notice: notice
else
flash.now[:alert] = bv_response[:message]
return show_errors('edit')
end
end end
redirect_to campaign_path(@campaign.listingcode), notice: 'Campaign was successfully updated.'
else else
show_errors('edit') return show_errors('edit')
end end
redirect_to campaign_path(@campaign.listingcode), notice: notice
end end
def destroy def destroy

View File

@ -0,0 +1,12 @@
class BetterVideo
def initialize(options={})
@addvideo_url = options.fetch(:url, "http://servicestest.bettervideo.com/orders/MDS.OrdersWS.svc/addVideo")
end
def addVideo(campaign)
response = Hash.new
response[:success] = true
response[:message] = "Submitted to better video."
response
end
end

View File

@ -6,7 +6,7 @@ class Campaign < ActiveRecord::Base
validates :websiteurl, presence: true validates :websiteurl, presence: true
validates :description, presence: true validates :description, presence: true
validates :productsandservices, presence: true validates :productsandservices, presence: true
after_save :send_to_better_video # after_save :send_to_better_video
validate :has_at_least_one_videolisting validate :has_at_least_one_videolisting
after_initialize :set_defaults after_initialize :set_defaults
def set_defaults def set_defaults
@ -23,10 +23,10 @@ class Campaign < ActiveRecord::Base
0 0
end end
def send_to_better_video # def send_to_better_video
if self.sent_changed? && self.sent? == true # if self.sent_changed? && self.sent? == true
#TODO Make API Calls #
end # end
end # end
end end

View File

@ -26,6 +26,7 @@ module Vidpush
generate.test_framework :rspec generate.test_framework :rspec
generate.view_specs false generate.view_specs false
end end
config.autoload_paths += %W(#{config.root}/lib)
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers

View File

@ -32,5 +32,7 @@ Vidpush::Application.configure do
config.action_controller.action_on_unpermitted_parameters = :raise config.action_controller.action_on_unpermitted_parameters = :raise
config.action_mailer.default_url_options = { host: 'localhost:3000' } config.action_mailer.default_url_options = { host: 'localhost:3000' }
end end