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,15 +38,26 @@ class CampaignsController < ApplicationController
end
def update
notice = 'Campaign was saved for later use. It is not published yet.'
if @campaign.update(campaign_params)
if params[:send]
client = BetterVideo.new(:url => "xxx")
bv_response = client.addVideo(campaign: @campaign)
if bv_response[:success]
notice = bv_response[:message]
@campaign.update({sent: true})
end
redirect_to campaign_path(@campaign.listingcode), notice: 'Campaign was successfully updated.'
return redirect_to campaign_path(@campaign.listingcode), notice: notice
else
show_errors('edit')
flash.now[:alert] = bv_response[:message]
return show_errors('edit')
end
end
else
return show_errors('edit')
end
redirect_to campaign_path(@campaign.listingcode), notice: notice
end
def destroy
@campaign.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 :description, presence: true
validates :productsandservices, presence: true
after_save :send_to_better_video
# after_save :send_to_better_video
validate :has_at_least_one_videolisting
after_initialize :set_defaults
def set_defaults
@ -23,10 +23,10 @@ class Campaign < ActiveRecord::Base
0
end
def send_to_better_video
if self.sent_changed? && self.sent? == true
#TODO Make API Calls
end
end
# def send_to_better_video
# if self.sent_changed? && self.sent? == true
#
# end
# end
end

View File

@ -26,6 +26,7 @@ module Vidpush
generate.test_framework :rspec
generate.view_specs false
end
config.autoload_paths += %W(#{config.root}/lib)
# Settings in config/environments/* take precedence over those specified here.
# 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_mailer.default_url_options = { host: 'localhost:3000' }
end