diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 54037ad..b42e9e5 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -80,7 +80,7 @@ class CampaignsController < ApplicationController :businessphone, :categories, :city, :companycolors, :contactphone, :customerfirstname, :customerlastname, :description, :emailaddress, :facebookurl, :listingcode, :productsandservices, :state, :targetaudience, :tollfreephone, - :vpa, :websiteurl, :zip, + :vpa, :vpa_email, :websiteurl, :zip, videolistings_attributes: [:_destroy, :id, :asseturls, :clientprovidedscript, :focus, :keywords, :musicselection, :notes, diff --git a/app/controllers/videolistings_controller.rb b/app/controllers/videolistings_controller.rb index 788f2ad..bd805ca 100644 --- a/app/controllers/videolistings_controller.rb +++ b/app/controllers/videolistings_controller.rb @@ -5,6 +5,7 @@ class VideolistingsController < ApplicationController if @videolisting.published? @message = "Campaign Already Published." elsif @videolisting.campaign.sent? + VideolistingMailer.videolisting_complete(@videolisting).deliver @videolisting.published = true @videolisting.save diff --git a/app/mailers/videolisting_mailer.rb b/app/mailers/videolisting_mailer.rb new file mode 100644 index 0000000..2aa58c3 --- /dev/null +++ b/app/mailers/videolisting_mailer.rb @@ -0,0 +1,9 @@ +class VideolistingMailer < ActionMailer::Base + default from: "noreply@propelmarketing.com" + + def videolisting_complete(videolisting) + @to = videolisting.campaign.vpa_email + @listing = videolisting + mail(to: @to, subject: "A Video Listing has been completed by Better Video") + end +end diff --git a/app/models/better_video.rb b/app/models/better_video.rb index 0a52bf1..6f7a5a0 100644 --- a/app/models/better_video.rb +++ b/app/models/better_video.rb @@ -19,12 +19,12 @@ class BetterVideo resp = JSON.parse(response.body) puts resp - if resp["errorcode"] == 0 + if resp["errorcode"].to_i == 0 resp[:success] = true resp[:message] = "Successfully submitted to BetterVideo, Please wait." else resp[:message] = "Error Code #{resp["errorcode"]}: #{resp["errormessage"]}" - if resp["errorcode"] == 1 + if resp["errorcode"].to_i == 1 resp[:message] += "Please Contact Dev" end end diff --git a/app/models/campaign.rb b/app/models/campaign.rb index a677c97..5cb4b18 100644 --- a/app/models/campaign.rb +++ b/app/models/campaign.rb @@ -25,9 +25,8 @@ class Campaign < ActiveRecord::Base 0 end - def to_bettervideo_format - campaign = self.as_json + campaign = self.as_json(except: [:vpa_email,]) campaign[:videolistings] = self.videolistings.all.map {|vl| vl.as_json } campaigns = {campaigns: [campaign,], key: "PRO1234"} campaigns.to_json diff --git a/app/models/videolisting.rb b/app/models/videolisting.rb index 38226e3..0cc6012 100644 --- a/app/models/videolisting.rb +++ b/app/models/videolisting.rb @@ -53,7 +53,6 @@ class Videolisting < ActiveRecord::Base def send_notification_after_change if self.published_changed? && self.published? - #TODO: SEND OUT EMAIL HERE TO CLIENT SERVICES REP end true end diff --git a/app/views/campaigns/_campaign.json.jbuilder b/app/views/campaigns/_campaign.json.jbuilder index 6ca6b59..dc20361 100644 --- a/app/views/campaigns/_campaign.json.jbuilder +++ b/app/views/campaigns/_campaign.json.jbuilder @@ -24,5 +24,6 @@ json.videolistings campaign.videolistings.each do |videolisting| json.partial! 'campaigns/videolisting', videolisting: videolisting end json.vpa campaign.vpa if campaign.vpa +json.vpa_email campaign.vpa_email if campaign.vpa_email json.websiteurl campaign.websiteurl if campaign.websiteurl json.zip campaign.zip if campaign.zip \ No newline at end of file diff --git a/app/views/campaigns/_form.html.erb b/app/views/campaigns/_form.html.erb index d90be86..22bb6d4 100644 --- a/app/views/campaigns/_form.html.erb +++ b/app/views/campaigns/_form.html.erb @@ -32,9 +32,12 @@ <%= frm.input :websiteurl, label: 'Website URL', hint: "Used for script research and may be used in the video if they are including websites in the video graphics." %> - <%= frm.input :vpa, + <%= frm.input :vpa, label: 'Client Service Rep', hint: "This is the full name of the client services representative, as entered in the BetterVideo system associated with this order. This feature is designed for sales reps that are well known to the system. This feature is typically used for automated communication." %> + <%= frm.input :vpa_email, + label: 'Client Service Rep Email', + hint: "The Email for the above Client Service Rep, (not sent to BetterVideo, just used for video completion emails)" %> <%= frm.input :billingcode, label: 'Billing Code', hint: "Market or billing code. Should match a billing code in the BetterVideo system so it can be associated." %> diff --git a/app/views/campaigns/show.html.erb b/app/views/campaigns/show.html.erb index bfaa0ae..816b752 100644 --- a/app/views/campaigns/show.html.erb +++ b/app/views/campaigns/show.html.erb @@ -40,6 +40,12 @@ <%= @campaign.vpa %>

<% end %> + <% unless @campaign.vpa_email.blank? %> +
  • +

    Client Services Rep Email
    + <%= @campaign.vpa_email %>

    +
  • + <% end %> <% unless @campaign.billingcode.blank? %>
  • Billing Code
    diff --git a/app/views/videolisting_mailer/videolisting_complete.html.erb b/app/views/videolisting_mailer/videolisting_complete.html.erb new file mode 100644 index 0000000..915cd5d --- /dev/null +++ b/app/views/videolisting_mailer/videolisting_complete.html.erb @@ -0,0 +1,11 @@ + + + + + + +

    A Video listing is complete.

    +

    The video listing with video code: <%= @listing.videocode %> has been completed by Better video.

    +

    <%= link_to "Preview Video Before setting live.", campaign_videolisting_url(@listing.campaign.listingcode, @listing.videocode) %>

    + + \ No newline at end of file diff --git a/app/views/videolisting_mailer/videolisting_complete.text.erb b/app/views/videolisting_mailer/videolisting_complete.text.erb new file mode 100644 index 0000000..f930888 --- /dev/null +++ b/app/views/videolisting_mailer/videolisting_complete.text.erb @@ -0,0 +1,5 @@ +A Video listing is complete. +============================== +The video listing with video code: <%= @listing.videocode %> has been completed by Better video. + +<%= campaign_videolisting_url(@listing.campaign.listingcode, @listing.videocode) %> \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index b85d282..ed437e9 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,3 +3,5 @@ require File.expand_path('../application', __FILE__) # Initialize the Rails application. Vidpush::Application.initialize! + + diff --git a/config/environments/development.rb b/config/environments/development.rb index 08ba00c..e72ecd0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -15,6 +15,7 @@ Vidpush::Application.configure do # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = true + config.action_mailer.delivery_method = :development # Print deprecation notices to the Rails logger. @@ -32,7 +33,6 @@ Vidpush::Application.configure do config.action_controller.action_on_unpermitted_parameters = :raise - config.action_mailer.default_url_options = { host: 'localhost:3000' } end diff --git a/db/migrate/20140505153412_add_vpa_email_to_campaign.rb b/db/migrate/20140505153412_add_vpa_email_to_campaign.rb new file mode 100644 index 0000000..1103a9f --- /dev/null +++ b/db/migrate/20140505153412_add_vpa_email_to_campaign.rb @@ -0,0 +1,5 @@ +class AddVpaEmailToCampaign < ActiveRecord::Migration + def change + add_column :campaigns, :vpa_email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 619573d..9db59ab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140502151827) do +ActiveRecord::Schema.define(version: 20140505153412) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -62,6 +62,7 @@ ActiveRecord::Schema.define(version: 20140502151827) do t.string "targetaudience" t.string "tollfreephone" t.string "vpa" + t.string "vpa_email" end create_table "delayed_jobs", force: true do |t| diff --git a/spec/mailers/videolisting_mailer_spec.rb b/spec/mailers/videolisting_mailer_spec.rb new file mode 100644 index 0000000..c6eb05f --- /dev/null +++ b/spec/mailers/videolisting_mailer_spec.rb @@ -0,0 +1,5 @@ +require "spec_helper" + +describe VideolistingMailer do + pending "add some examples to (or delete) #{__FILE__}" +end