public HttpResponseMessage Bullet([FromUri]string format = "JSON", [FromUri]string type = "1") { try { if (!User.Identity.IsAuthenticated) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("API key not specified.")); } if (Guid.Parse(ConfigurationManager.AppSettings["GeckoAPIkey"]).ToString() != User.Identity.Name) { return this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception(string.Format("Unknown API key, should be '{0}'.", ConfigurationManager.AppSettings["GeckoAPIkey"]))); } //if (int.Parse(type) != 1) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(string.Format("Type parameter '{0}' is wrong.", type))); } // You would modify what gets returned here to make it meaningful var retVal = new GeckoBulletChart() { Orientation = "horizontal", Item = new GeckoBulletItem() { Label = "Revenue 2011 YTD", SubLabel = "(U.S. $ in thousands)", Axis = new GeckoBulletAxis() { Points = new List<string>() { "0", "200", "400", "600", "800", "1000" } }, Range = new List<GeckoBulletRangeItem>() { new GeckoBulletRangeItem() { Color = "red", Start = 0, End = 400 }, new GeckoBulletRangeItem() { Color = "amber", Start = 401, End = 700 }, new GeckoBulletRangeItem() { Color = "green", Start = 701, End = 1000 } }, Measure = new GeckoBulletMeasure() { Current = new GeckoBulletRangeItemString() { Start = "0", End = "500" }, Projected = new GeckoBulletRangeItemString() { Start = "100", End = "900" } }, Comparative = new GeckoBulletPointString() { Point = "600" } } }; return this.Request.CreateResponse<GeckoBulletChart>(HttpStatusCode.OK, retVal); } catch (Exception ex) { return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } }
public void Live_Push_Bullet() { // Arrange var widgetKey = BULLET_WIDGETKEY; // replace this value with your own var obj = new GeckoBulletChart() { Orientation = "horizontal", Item = new GeckoBulletItem() { Axis = new GeckoBulletAxis() { Points = new System.Collections.Generic.List <string> { "0", "50", "100", "150", "200", "250" } }, Comparative = new GeckoBulletPointString() { Point = "220" }, Label = "Revenue", Measure = new GeckoBulletMeasure() { Current = new GeckoBulletRangeItemString() { End = "235", Start = "0" } }, Range = new System.Collections.Generic.List <GeckoBulletRangeItem>() { new GeckoBulletRangeItem() { Color = "red", End = 125, Start = 0 }, new GeckoBulletRangeItem() { Color = "amber", End = 200, Start = 126 }, new GeckoBulletRangeItem() { Color = "green", End = 250, Start = 201 } }, SubLabel = "U.S. $ (1,000s)" } }; var push = new PushPayload <GeckoBulletChart>() { ApiKey = _apiKey, Data = obj }; var client = new GeckoConnect(); var json = JsonConvert.SerializeObject(push, Formatting.Indented); // Just for curiosity sake // Act Assert.AreNotEqual("<api key here>", _apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push <GeckoBulletChart>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public void Live_Push_Bullet() { // Arrange var widgetKey = "<api widget here>"; // replace this value with your own var obj = new GeckoBulletChart() { Orientation = "horizontal", Item = new GeckoBulletItem() { Axis = new GeckoBulletAxis() { Points = new System.Collections.Generic.List<string> { "0", "50", "100", "150", "200", "250" } }, Comparative = new GeckoBulletPointString() { Point = "220" }, Label = "Revenue", Measure = new GeckoBulletMeasure() { Current = new GeckoBulletRangeItemString() { End = "235", Start = "0" } }, Range = new System.Collections.Generic.List<GeckoBulletRangeItem>() { new GeckoBulletRangeItem(){ Color = "red", End = 125, Start = 0}, new GeckoBulletRangeItem(){ Color = "amber", End = 200, Start = 126}, new GeckoBulletRangeItem(){ Color = "green", End = 250, Start = 201} }, SubLabel = "U.S. $ (1,000s)" } }; var push = new PushPayload<GeckoBulletChart>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); var json = JsonConvert.SerializeObject(push, Formatting.Indented); // Just for curiosity sake // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<GeckoBulletChart>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public HttpResponseMessage Bullet([FromUri] string format = "JSON", [FromUri] string type = "1") { try { if (!User.Identity.IsAuthenticated) { return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception("API key not specified."))); } if (Guid.Parse(ConfigurationManager.AppSettings["GeckoAPIkey"]).ToString() != User.Identity.Name) { return(this.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new Exception(string.Format("Unknown API key, should be '{0}'.", ConfigurationManager.AppSettings["GeckoAPIkey"])))); } //if (int.Parse(type) != 1) { return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentException(string.Format("Type parameter '{0}' is wrong.", type))); } // You would modify what gets returned here to make it meaningful var retVal = new GeckoBulletChart() { Orientation = "horizontal", Item = new GeckoBulletItem() { Label = "Revenue 2011 YTD", SubLabel = "(U.S. $ in thousands)", Axis = new GeckoBulletAxis() { Points = new List <string>() { "0", "200", "400", "600", "800", "1000" } }, Range = new List <GeckoBulletRangeItem>() { new GeckoBulletRangeItem() { Color = "red", Start = 0, End = 400 }, new GeckoBulletRangeItem() { Color = "amber", Start = 401, End = 700 }, new GeckoBulletRangeItem() { Color = "green", Start = 701, End = 1000 } }, Measure = new GeckoBulletMeasure() { Current = new GeckoBulletRangeItemString() { Start = "0", End = "500" }, Projected = new GeckoBulletRangeItemString() { Start = "100", End = "900" } }, Comparative = new GeckoBulletPointString() { Point = "600" } } }; return(this.Request.CreateResponse <GeckoBulletChart>(HttpStatusCode.OK, retVal)); } catch (Exception ex) { return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }