public BCAPI(string accountName) { BrightcoveConfig bc = (BrightcoveConfig)ConfigurationManager.GetSection("brightcove"); foreach (AccountConfigElement a in bc.Accounts) { if (a.Name.Equals(accountName)) { Account = new BCAccount(a); } } }
public BCAPI(long publisherId) { BrightcoveConfig bc = (BrightcoveConfig)ConfigurationManager.GetSection("brightcove"); foreach (AccountConfigElement a in bc.Accounts) { if (a.PublisherID.Equals(publisherId)) { Account = new BCAccount(a); } } }
public static String BuildReadQuery(Dictionary <String, String> reqParams, BCAccount a) { String reqUrl = ""; //append url tokens and count if necessary reqUrl += a.ReadURL.Value; reqUrl += "?token=" + a.ReadToken.Value; reqUrl += "&get_item_count=true"; foreach (String key in reqParams.Keys) { reqUrl += "&" + String.Format("{0}={1}", key, HttpUtility.UrlEncode(reqParams[key])); } return(reqUrl); }
public async Task <IActionResult> Login(LoginModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { IBCAccount Account = new BCAccount(); var result = Account.Usuario(model); if (result.Succeeded) { await RetrieveApiServiceToken(result); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } return(View(model)); }
private static BCQueryResult MultipleQueryHandler(Dictionary <String, String> reqparams, BCObjectType itemType, BCAccount account) { //Get the JSon reader returned from the APIRequest BCQueryResult qr = new BCQueryResult(); qr.TotalCount = 0; int defaultPageSize = 100; if (!reqparams.ContainsKey("page_size")) // if page size is not set than set it { reqparams.Add("page_size", defaultPageSize.ToString()); qr.MaxToGet = -1; } else // else parse it { qr.MaxToGet = Convert.ToInt32(reqparams["page_size"]); defaultPageSize = qr.MaxToGet; } MakeRequest(qr, reqparams, itemType, account); if (!reqparams.ContainsKey("page_number")) // if page number is not set then pass make recursive calls { reqparams.Add("page_number", "0"); //make sure you get the correct page num int modifier = (qr.MaxToGet.Equals(-1)) ? qr.TotalCount : qr.MaxToGet; double maxPageNum = (qr.TotalCount > 0) ? Math.Ceiling((double)(modifier / defaultPageSize)) : 0; //if there are more to get move to next page and keep getting them for (int pageNum = 1; pageNum <= maxPageNum; pageNum++) { //update page each iteration reqparams["page_number"] = pageNum.ToString(); MakeRequest(qr, reqparams, itemType, account); } if (itemType.Equals(BCObjectType.videos)) { //trim if specified if (qr.Videos.Count > qr.MaxToGet && !qr.MaxToGet.Equals(-1) && qr.MaxToGet < qr.TotalCount) { List <BCVideo> vidTemp = qr.Videos.GetRange(0, Convert.ToInt32(qr.MaxToGet)); qr.Videos.Clear(); qr.Videos.AddRange(vidTemp); } } } return(qr); }
/// <summary> /// RJE 10-16-2012 /// Construct an API with a supplied configuration /// </summary> public BCAPI(BCAccount account) { Account = account; }
private static void MakeRequest(BCQueryResult qr, Dictionary <string, string> reqparams, BCObjectType itemType, BCAccount account) { QueryResultPair qrp = BCAPIRequest.ExecuteRead(reqparams, account); qrp.JsonResult = qrp.JsonResult.Replace("\"items\":", "\"" + itemType.ToString() + "\":"); qr.QueryResults.Add(qrp); qr.Merge(JSON.Converter.Deserialize <BCQueryResult>(qrp.JsonResult)); }
public static RPCResponse <T> ExecuteWriteNew <T>(Dictionary <String, Object> postParams, BCAccount a) { string jsonResult = _ExecuteWriteNew(postParams, a); RPCResponse <T> rpcr = JSON.Converter.Deserialize <RPCResponse <T> >(jsonResult); return(rpcr); }
private static string _ExecuteWriteNew(Dictionary <String, Object> postParams, BCAccount a) { MultipartForm form = new MultipartForm(); form.BuildForm(a.WriteURL.Value, "BCAPI SDK Write Request", postParams); // Uncomment this line to debug the form // string debug = form.ToString(); HttpWebResponse webResponse = form.PostForm(); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string jsonResult = responseReader.ReadToEnd(); webResponse.Close(); //this is so that we don't cast null as an object (replaces null with empty error) jsonResult = jsonResult.Replace("\"error\": null", "\"error\": { \"name\" : null, \"message\" : null, \"code\" : null }"); return(jsonResult); }
public static RPCResponse ExecuteWrite(Dictionary <String, Object> postParams, BCAccount a) { // Create request and receive response HttpWebResponse webResponse = PostRequests.MultipartFormDataPost(a.WriteURL.Value, "BCAPI SDK Write Request", postParams); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string jsonResult = responseReader.ReadToEnd(); webResponse.Close(); //this is so that we don't cast null as an object (replaces null with empty error) jsonResult = jsonResult.Replace("\"error\": null", "\"error\": { \"name\" : null, \"message\" : null, \"code\" : null }"); RPCResponse rpcr = JSON.Converter.Deserialize <RPCResponse>(jsonResult); return(rpcr); }
public static QueryResultPair ExecuteRead(Dictionary <String, String> reqParams, BCAccount a) { String reqUrl = BuildReadQuery(reqParams, a); HttpWebRequest webRequest = WebRequest.Create(reqUrl) as HttpWebRequest; HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse; TextReader textreader = new StreamReader(response.GetResponseStream()); string jsonStr = textreader.ReadToEnd(); QueryResultPair qrp = new QueryResultPair(reqUrl, jsonStr); return(qrp); }