vidpush/app/models/better_video.rb

33 lines
863 B
Ruby
Raw Normal View History

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={})
@addvideo_url = options.fetch(:url, "http://servicestest.bettervideo.com/orders/MDS.OrdersWS.svc/addVideo")
end
def addVideo(campaign)
2014-04-30 17:57:58 +00:00
uri = URI.parse(@addvideo_url)
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-04-30 18:41:57 +00:00
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