2014-04-30 17:57:58 +00:00
|
|
|
require 'net/http'
|
|
|
|
require 'uri'
|
|
|
|
require 'json'
|
|
|
|
|
2014-04-29 21:05:21 +00:00
|
|
|
class BetterVideo
|
|
|
|
def initialize(options={})
|
2014-05-07 18:22:18 +00:00
|
|
|
@addvideo_url = options.fetch(:url, ENV['BETTER_VIDEO_URL'])
|
2014-04-29 21:05:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def addVideo(campaign)
|
2014-05-07 20:03:10 +00:00
|
|
|
uri = URI.parse("#{@addvideo_url}/addVideo")
|
2014-04-30 18:41:57 +00:00
|
|
|
header = {}
|
2014-04-30 17:57:58 +00:00
|
|
|
|
|
|
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
|
|
request = Net::HTTP::Post.new(uri.request_uri, header)
|
|
|
|
request.body = campaign[:campaign]
|
|
|
|
response = http.request(request)
|
|
|
|
|
|
|
|
resp = JSON.parse(response.body)
|
|
|
|
|
2014-05-05 18:07:33 +00:00
|
|
|
if resp["errorcode"].to_i == 0
|
2014-04-30 17:57:58 +00:00
|
|
|
resp[:success] = true
|
|
|
|
resp[:message] = "Successfully submitted to BetterVideo, Please wait."
|
|
|
|
else
|
2014-05-09 18:17:00 +00:00
|
|
|
resp['errormessage'].sub!("VPA", "Customer Service Rep") # fix for Customer Service Reps being called VPA in BV
|
|
|
|
resp[:message] = "Error Code #{resp["errorcode"]}: #{resp['errormessage']}"
|
2014-05-05 18:07:33 +00:00
|
|
|
if resp["errorcode"].to_i == 1
|
2014-04-30 18:41:57 +00:00
|
|
|
resp[:message] += "Please Contact Dev"
|
|
|
|
end
|
2014-04-30 17:57:58 +00:00
|
|
|
end
|
|
|
|
resp
|
2014-04-29 21:05:21 +00:00
|
|
|
end
|
2014-04-30 17:57:58 +00:00
|
|
|
end
|