private static void SetupFacebookInfo() { if (string.IsNullOrEmpty(FacebookId)) { var facebookApi = new ApiDataService().GetApiParametersByName(FacebookName); FacebookId = facebookApi.Item1; FacebookSecret = facebookApi.Item2; } }
static InternalService() { var dropbox = new ApiDataService().GetApiParametersByName(DropboxService.ApiName); DropboxService = new DropboxService( dropbox.Item1, dropbox.Item2, dropbox.Item3); ImageService = new ImageService(); }
private static GoogleOAuth2AuthenticationOptions GetNewGoogleAuthenticationOptions() { if (string.IsNullOrEmpty(GoogleKey)) { var googleApi = new ApiDataService().GetApiParametersByName(GoogleName); GoogleKey = googleApi.Item1; GoogleSecrete = googleApi.Item2; } return(new GoogleOAuth2AuthenticationOptions { ClientId = GoogleKey, ClientSecret = GoogleSecrete }); }
private async Task BuildComputerCallback(IDialogContext context, IAwaitable <BuildComputerForm> result) { var token = await result; var name = "User"; context.UserData.TryGetValue <string>("Name", out name); //TODO: John - await context.PostAsync($"Ok, thanks! I am looking up that information for you now. Please wait..."); var api = new ApiDataService(); var recommendation = await api.GetComputerPartsRecommendation(token); var builder = new StringBuilder(); builder.Append($"Great we got that all set up for you! \r\nHere is your recommended computer build: "); if (recommendation.Processor != null) { builder.Append($" \r\n - **CPU** = {recommendation.Processor.Name} for {recommendation.Processor.Price:C} at {recommendation.Processor.VendorUrl}"); } if (recommendation.RamKit != null) { builder.Append($" \r\n - **Memory** = {recommendation.RamKit.Name} for {recommendation.RamKit.Price:C} at {recommendation.RamKit.VendorUrl}"); } if (recommendation.HardDiskDrive != null) { builder.Append($" \r\n - **Hard Drive** = {recommendation.HardDiskDrive.Name} for {recommendation.HardDiskDrive.Price:C} at {recommendation.HardDiskDrive.VendorUrl}"); } if (recommendation.VideoCard != null) { builder.Append($" \r\n - **Video Card** = {recommendation.VideoCard.Name} for {recommendation.VideoCard.Price:C} at {recommendation.VideoCard.VendorUrl}"); } if (recommendation.Processor == null && recommendation.RamKit == null && recommendation.HardDiskDrive == null && recommendation.VideoCard == null) { builder.Append($" \r\nSorry. No results found."); } else { builder.Append($" \r\n - **Total Price** = {recommendation.TotalPrice:C}"); } await context.PostAsync(builder.ToString()); await context.PostAsync($"Thank you for using the Austin Weird Bot, {name}!"); context.Wait(MessageReceived); }
public async Task Default(String pathInfo) { StartTenant(); var request = ApiRequest.FromHttpRequest(Request, pathInfo, (rq) => { rq.UserId = UserId; rq.Segment = UserSegment; rq.ClientId = User.Identity.GetUserClaim("ClientId"); if (_host.IsMultiTenant) { rq.TenantId = TenantId; } rq.Config = _host.GetAppSettingsObject("apiV2Config"); }); var apiService = new ApiDataService(_host, _dbContext); var response = await apiService.ProcessRequest(request); Response.ContentType = response.ContentType; Response.Write(response.Body); }
public MinimumIntervalRule(int customerId, ApiDataService service, int minInterval = 2000) { _minInterval = minInterval; _customerId = customerId; _service = service; }
private dynamic RouteSearch(string searchQuery, int page, string rarity, string category, string faction, string rItems, string mItems, int id) { if (searchQuery == null) { searchQuery = ""; } sql.Open(WebSettings.Settings.CreateDescription()); var parmeter = new List <Parameter>(); bool hasFilter = !string.IsNullOrEmpty(searchQuery); FilterModel filterModel = new FilterModel { Categories = ApiDataService.SelectCategories(sql), Rarities = ApiDataService.SelectRarities(sql), Factions = ApiDataService.SelectFactions(sql), }; var rarityItem = filterModel.VerifyRarity(rarity); var categoryItem = filterModel.VerifyCategory(category); var factionItem = filterModel.VerifyFaction(faction); var showRemovedItems = filterModel.VerifyRmdItems(rItems); var showMetaItems = filterModel.VerifyMetaItems(mItems); filterModel.CurrentShowRemovedItems = showRemovedItems; filterModel.CurrentShowMetaItems = showMetaItems; string sqlQuery = DataService.BuildSearchQuery(hasFilter, true, false, id > 0, rarityItem != null, categoryItem != null, factionItem != null, showRemovedItems, showMetaItems); if (hasFilter) { var p = new Parameter { Identifier = "@filter", Value = $"%{searchQuery}%" }; parmeter.Add(p); } if (rarityItem != null) { var p = new Parameter { Identifier = "@rarity", Value = $"{rarityItem.Id}" }; parmeter.Add(p); } if (categoryItem != null) { var p = new Parameter { Identifier = "@category", Value = $"{categoryItem.Id}" }; parmeter.Add(p); } if (factionItem != null) { var p = new Parameter { Identifier = "@faction", Value = $"{factionItem.Id}" }; parmeter.Add(p); } if (id > 0) { var p = new Parameter { Identifier = "@id", Value = $"{id}" }; parmeter.Add(p); } var ds = sql.SelectDataSet(sqlQuery, parmeter); var searchResult = new List <Item>(); foreach (var row in ds) { Item item = Item.Create(row); CrossoutDataService.Instance.AddData(item); searchResult.Add(item); } //var str = JsonConvert.SerializeObject(searchResult); return(Response.AsJson(searchResult)); }
public ApiModule() { OnError += (ctx, exp) => { var modelBindingException = exp as ModelBindingException; if (modelBindingException != null) { var errorModel = new { ErrorMessage = modelBindingException.Message, PropertyBindingErrors = modelBindingException.PropertyBindingExceptions?.Select(x => new { ErrorMessage = x.Message, InnerException = x.InnerException?.Message }).ToArray() }; return(Response.AsJson(errorModel, HttpStatusCode.BadRequest)); } return(null); }; Get["/api/v1/rarities"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetRarities(); return(Response.AsJson(model)); }; Get["/api/v1/factions"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetFactions(); return(Response.AsJson(model)); }; Get["/api/v1/types"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetItemTypes(); return(Response.AsJson(model)); }; Get["/api/v1/categories"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetCategories(); return(Response.AsJson(model)); }; Get["/api/v1/items"] = x => { return(RouteSearch(null, 0, null, null, null, null, null, 0)); }; Get["/api/v1/items"] = x => { string rarity = (string)Request.Query.Rarity; string category = (string)Request.Query.Category; string faction = (string)Request.Query.Faction; string showRemovedItems = (string)Request.Query.RemovedItems; string showMetaItems = (string)Request.Query.MetaItems; var query = (string)Request.Query.Query; int id = (int)Request.Query.Id; return(RouteSearch(query, 0, rarity, category, faction, showRemovedItems, showMetaItems, id)); }; Get["/api/v1/item/{item:int}"] = x => { string rarity = (string)Request.Query.Rarity; string category = (string)Request.Query.Category; string faction = (string)Request.Query.Faction; string showRemovedItems = (string)Request.Query.RemovedItems; string showMetaItems = (string)Request.Query.MetaItems; var query = (string)Request.Query.Query; int id = (int)x.item; return(RouteSearch(query, 0, rarity, category, faction, showRemovedItems, showMetaItems, id)); }; Get["/api/v1/recipe/{item:int}"] = x => { var id = (int)x.item; sql.Open(WebSettings.Settings.CreateDescription()); DataService db = new DataService(sql); var itemModel = db.SelectItem(id, true); var recipeModel = db.SelectRecipeModel(itemModel.Item, false); return(Response.AsJson(recipeModel)); }; Get["/api/v1/recipe-deep/{item:int}"] = x => { var id = (int)x.item; sql.Open(WebSettings.Settings.CreateDescription()); DataService db = new DataService(sql); var itemModel = db.SelectItem(id, true); var recipeModel = db.SelectRecipeModel(itemModel.Item, true); itemModel.Recipe = recipeModel; return(Response.AsJson(itemModel)); }; Get["/api/v1/market/{name}/{id:int}"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); string name = x.name; HashSet <string> validMarkets = new HashSet <string>() { "sellprice", "buyprice", "selloffers", "buyorders" }; bool unixTimeStamp = (bool)Request.Query.unixTimestamp; string timestampColumn = "market.datetime"; if (validMarkets.Contains(name)) { if (unixTimeStamp) { timestampColumn = "UNIX_TIMESTAMP(market.datetime)"; } string query = $"(SELECT {timestampColumn},market.{name} FROM market where market.itemnumber = @id ORDER BY market.Datetime desc LIMIT 40000);"; var parmeter = new List <Parameter> { new Parameter { Identifier = "@id", Value = x.id }, }; var ds = sql.SelectDataSet(query, parmeter); return(Response.AsJson(ds)); } else { return(Response.AsJson("Market not found", HttpStatusCode.NotFound)); } }; Get["/api/v1/market-all/{id:int}"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); var request = this.Bind <MarketAllRequest>(); var startTimestamp = request.StartTimestamp; var endTimestamp = request.EndTimestamp; if (startTimestamp.HasValue && startTimestamp < 0) { return(Response.AsJson(new { ErrorMessage = "Parameter startTimestamp should be positive integer less than or equal to " + int.MaxValue }, HttpStatusCode.BadRequest)); } if (endTimestamp.HasValue && endTimestamp < 0) { return(Response.AsJson(new { ErrorMessage = "Parameter endTimestamp should be positive integer less than or equal to " + int.MaxValue }, HttpStatusCode.BadRequest)); } var whereClause = "where market.itemnumber = @id"; if (startTimestamp.HasValue && endTimestamp.HasValue) { whereClause += " AND market.datetime BETWEEN FROM_UNIXTIME(@startTimestamp) AND FROM_UNIXTIME(@endTimestamp)"; } else { if (startTimestamp.HasValue) { whereClause += " AND market.datetime >= FROM_UNIXTIME(@startTimestamp)"; } if (endTimestamp.HasValue) { whereClause += " AND market.datetime <= FROM_UNIXTIME(@endTimestamp)"; } } string query = "(" + "SELECT market.id,market.sellprice,market.buyprice,market.selloffers,market.buyorders,market.datetime,UNIX_TIMESTAMP(market.datetime) as unixdatetime " + "FROM market " + $"{whereClause} " + "ORDER BY market.Datetime desc LIMIT 40000" + ") ORDER BY id ASC;"; var p = new Parameter { Identifier = "@id", Value = request.Id }; var parmeter = new List <Parameter>(); parmeter.Add(p); if (startTimestamp.HasValue) { parmeter.Add(new Parameter("startTimestamp", startTimestamp.Value)); } if (endTimestamp.HasValue) { parmeter.Add(new Parameter("endTimestamp", endTimestamp.Value)); } var ds = sql.SelectDataSet(query, parmeter); return(Response.AsJson(ds)); }; After.AddItemToEndOfPipeline((ctx) => { ctx.Response.WithHeader("Access-Control-Allow-Origin", "*") .WithHeader("Access-Control-Allow-Methods", "POST,GET") .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type"); }); }
public ApiService(ApiDataService dataService) { _dataService = dataService; }
public MaximumReqInPeriodRule(int customerId, ApiDataService service) { _customerId = customerId; _service = service; }
public ApiModule() { Get["/api/v1/rarities"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetRarities(); return(Response.AsJson(model)); }; Get["/api/v1/factions"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetFactions(); return(Response.AsJson(model)); }; Get["/api/v1/types"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetItemTypes(); return(Response.AsJson(model)); }; Get["/api/v1/categories"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); ApiDataService dataService = new ApiDataService(sql); var model = dataService.GetCategories(); return(Response.AsJson(model)); }; Get["/api/v1/items"] = x => { return(RouteSearch(null, 0, null, null, null, null, null, 0)); }; Get["/api/v1/items"] = x => { string rarity = (string)Request.Query.Rarity; string category = (string)Request.Query.Category; string faction = (string)Request.Query.Faction; string showRemovedItems = (string)Request.Query.RemovedItems; string showMetaItems = (string)Request.Query.MetaItems; var query = (string)Request.Query.Query; int id = (int)Request.Query.Id; return(RouteSearch(query, 0, rarity, category, faction, showRemovedItems, showMetaItems, id)); }; Get["/api/v1/item/{item:int}"] = x => { string rarity = (string)Request.Query.Rarity; string category = (string)Request.Query.Category; string faction = (string)Request.Query.Faction; string showRemovedItems = (string)Request.Query.RemovedItems; string showMetaItems = (string)Request.Query.MetaItems; var query = (string)Request.Query.Query; int id = (int)x.item; return(RouteSearch(query, 0, rarity, category, faction, showRemovedItems, showMetaItems, id)); }; Get["/api/v1/recipe/{item:int}"] = x => { var id = (int)x.item; sql.Open(WebSettings.Settings.CreateDescription()); DataService db = new DataService(sql); var itemModel = db.SelectItem(id, true); var recipeModel = db.SelectRecipeModel(itemModel.Item, false); return(Response.AsJson(recipeModel)); }; Get["/api/v1/recipe-deep/{item:int}"] = x => { var id = (int)x.item; sql.Open(WebSettings.Settings.CreateDescription()); DataService db = new DataService(sql); var itemModel = db.SelectItem(id, true); var recipeModel = db.SelectRecipeModel(itemModel.Item, true); itemModel.Recipe = recipeModel; return(Response.AsJson(itemModel)); }; Get["/api/v1/market/{name}/{id:int}"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); string name = x.name; HashSet <string> validMarkets = new HashSet <string>() { "sellprice", "buyprice", "selloffers", "buyorders" }; bool unixTimeStamp = (bool)Request.Query.unixTimestamp; string timestampColumn = "market.datetime"; if (validMarkets.Contains(name)) { if (unixTimeStamp) { timestampColumn = "UNIX_TIMESTAMP(market.datetime)"; } string query = $"(SELECT {timestampColumn},market.{name} FROM market where market.itemnumber = @id ORDER BY market.Datetime desc LIMIT 40000);"; var parmeter = new List <Parameter> { new Parameter { Identifier = "@id", Value = x.id }, }; var ds = sql.SelectDataSet(query, parmeter); return(Response.AsJson(ds)); } else { return(Response.AsJson("Market not found", HttpStatusCode.NotFound)); } }; Get["/api/v1/market-all/{id:int}"] = x => { sql.Open(WebSettings.Settings.CreateDescription()); string query = "(SELECT market.id,market.sellprice,market.buyprice,market.selloffers,market.buyorders,market.datetime,UNIX_TIMESTAMP(market.datetime) as unixdatetime FROM market where market.itemnumber = @id ORDER BY market.Datetime desc LIMIT 40000) ORDER BY id ASC;"; var p = new Parameter { Identifier = "@id", Value = x.id }; var parmeter = new List <Parameter>(); parmeter.Add(p); var ds = sql.SelectDataSet(query, parmeter); return(Response.AsJson(ds)); }; }
public ApiDataServiceTests() { apiDataService = new ApiDataService(fakeApiService); }