public TokenRequestor(string apikey, string Name, string pwd) { method = "get"; module = "api.login"; key = apikey; request = new RequestMaker(Name, pwd); }
public Movie GetMovie(string imdbId) { // make url string movie_request_url = RequestMaker.MakeMovieRequest(imdbId); // send request Movie requested_movie = Sender.Send(movie_request_url); return(new Movie()); }
public ActionResult Post() { string username, password, json; HttpPostedFileBase file; try // Extracting the form contents from request. { username = Request.Form["username"]; password = Request.Form["password"]; file = Request.Files["file"]; } catch { TempData["Message"] = "Invalid data in form"; return(new RedirectResult("/")); } try // Uploaded zip file structure interpreted to JSON. { json = ZipParser.zipToJSONString(file); } catch { TempData["Message"] = "Invalid zip file"; return(new RedirectResult("/")); } // Makes request to DataManagementSystem switch (RequestMaker.makeReqest(json, username, password)) { // User gets a different message depending // on the response from DataManagementSystem. case 200: { TempData["Message"] = "Successfully sent zip"; return(new RedirectResult("/")); } case 401: { TempData["Message"] = "Invalid username or password"; return(new RedirectResult("/")); } default: { TempData["Message"] = "Problem sending data"; return(new RedirectResult("/")); } } }
public async Task <Teacher> Get(int id) { Uri teacherUri = new Uri(_configuration.BaseApiUri, _configuration.Endpoints[EndpointType.Teacher]); string jsonBody = JsonProcessor.GetStringFromObject(new IntRequest(id)); HttpResponseMessage responseMessage = await RequestMaker.GetResource(teacherUri, jsonBody); EntityApiResponse <Teacher> apiResponse = JsonProcessor.GetObjectFromStream <EntityApiResponse <Teacher> >(await responseMessage.Content .ReadAsStreamAsync()); ValidateResponse(apiResponse); return(apiResponse.Result); }
private async Task <EntityArrayApiResponse <Activity> > QueryActivityArray(EndpointType type, int id) { Uri activityListUri = new Uri(_configuration.BaseApiUri, _configuration.Endpoints[type]); string jsonBody = JsonProcessor.GetStringFromObject(new IntRequest(id)); HttpResponseMessage responseMessage = await RequestMaker.GetResource(activityListUri, jsonBody); EntityArrayApiResponse <Activity> apiResponse = JsonProcessor.GetObjectFromStream <EntityArrayApiResponse <Activity> >( await responseMessage.Content.ReadAsStreamAsync()); ValidateArrayResponse(apiResponse); return(apiResponse); }
public static string MakePDF(string completeTemplate, List <object> sourceData, string credentials) { PDFDocumentRequestForm form = new PDFDocumentRequestForm() { TemplateHtml = completeTemplate, SourceData = sourceData, TemplateType = "Mustache", IdentifierField = "NUM_CUENTA_PMCP", TagList = "financieraOh,carta,ahorros" }; JsonConvert.SerializeObject(form); RequestMaker requestMaker = new RequestMaker(); return(requestMaker.MakePostPDFRequest(form, credentials)); }
private async Task <EntityArrayApiResponse <Teacher> > QueryTeacherArray(params int[] ids) { Uri teacherListUri = new Uri(_configuration.BaseApiUri, _configuration.Endpoints[EndpointType.TeacherList]); string jsonBody = string.Empty; if (ids.Length > 0) { jsonBody = JsonProcessor.GetStringFromObject(new IntArrayRequest(ids)); } HttpResponseMessage responseMessage = await RequestMaker.GetResource(teacherListUri, jsonBody); EntityArrayApiResponse <Teacher> apiResponse = JsonProcessor.GetObjectFromStream <EntityArrayApiResponse <Teacher> >( await responseMessage.Content.ReadAsStreamAsync()); ValidateArrayResponse(apiResponse); return(apiResponse); }
protected internal override async Task <IEnumerable <ExchangeMarket> > OnGetMarketSymbolsMetadataAsync() { List <ExchangeMarket> markets = new List <ExchangeMarket>(); try { string html = await RequestMaker.MakeRequestAsync("/rest-api", "https://docs.gemini.com"); int startPos = html.IndexOf("<h1 id=\"symbols-and-minimums\">Symbols and minimums</h1>"); if (startPos < 0) { throw new ApplicationException("Gemini html for symbol metadata is missing expected h1 tag and id"); } startPos = html.IndexOf("<tbody>", startPos); if (startPos < 0) { throw new ApplicationException("Gemini html for symbol metadata is missing start tbody tag"); } int endPos = html.IndexOf("</tbody>", startPos); if (endPos < 0) { throw new ApplicationException("Gemini html for symbol metadata is missing ending tbody tag"); } string table = html.Substring(startPos, endPos - startPos + "</tbody>".Length); string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + table; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); if (doc.ChildNodes.Count < 2) { throw new ApplicationException("Gemini html for symbol metadata does not have the expected number of nodes"); } XmlNode root = doc.ChildNodes.Item(1); foreach (XmlNode tr in root.ChildNodes) { // <tr> // <th>Symbol</th> // <th>Minimum Order Size</th> // <th>Tick Size</th> // <th>Quote Currency Price Increment</th> // <td>btcusd</td> // <td>0.00001 BTC (1e-5)</td> // <td>0.00000001 BTC (1e-8)</td> // <td>0.01 USD</td> // </tr> if (tr.ChildNodes.Count != 4) { throw new ApplicationException("Gemini html for symbol metadata does not have 4 rows per entry anymore"); } ExchangeMarket market = new ExchangeMarket { IsActive = true }; XmlNode symbolNode = tr.ChildNodes.Item(0); XmlNode minOrderSizeNode = tr.ChildNodes.Item(1); XmlNode tickSizeNode = tr.ChildNodes.Item(2); XmlNode incrementNode = tr.ChildNodes.Item(3); string symbol = symbolNode.InnerText; int minOrderSizePos = minOrderSizeNode.InnerText.IndexOf(' '); if (minOrderSizePos < 0) { throw new ArgumentException("Min order size text does not have a space after the number"); } decimal minOrderSize = minOrderSizeNode.InnerText.Substring(0, minOrderSizePos).ConvertInvariant <decimal>(); int tickSizePos = tickSizeNode.InnerText.IndexOf(' '); if (tickSizePos < 0) { throw new ArgumentException("Tick size text does not have a space after the number"); } decimal tickSize = tickSizeNode.InnerText.Substring(0, tickSizePos).ConvertInvariant <decimal>(); int incrementSizePos = incrementNode.InnerText.IndexOf(' '); if (incrementSizePos < 0) { throw new ArgumentException("Increment size text does not have a space after the number"); } decimal incrementSize = incrementNode.InnerText.Substring(0, incrementSizePos).ConvertInvariant <decimal>(); market.MarketSymbol = symbol; market.BaseCurrency = symbol.Substring(0, symbol.Length - 3); market.QuoteCurrency = symbol.Substring(symbol.Length - 3); market.MinTradeSize = minOrderSize; market.QuantityStepSize = tickSize; market.PriceStepSize = incrementSize; markets.Add(market); } return(markets); } catch (Exception ex) { markets.Clear(); Logger.Error(ex, "Failed to parse gemini symbol metadata web page, falling back to per symbol query..."); } // slow way, fetch each symbol one by one, gemini api epic fail Logger.Warn("Fetching gemini symbol metadata per symbol, this may take a minute..."); string[] symbols = (await GetMarketSymbolsAsync()).ToArray(); List <Task> tasks = new List <Task>(); foreach (string symbol in symbols) { tasks.Add(Task.Run(async() => { JToken token = await MakeJsonRequestAsync <JToken>("/symbols/details/" + HttpUtility.UrlEncode(symbol)); // {"symbol":"BTCUSD","base_currency":"BTC","quote_currency":"USD","tick_size":1E-8,"quote_increment":0.01,"min_order_size":"0.00001","status":"open"} lock (markets) { markets.Add(new ExchangeMarket { BaseCurrency = token["base_currency"].ToStringInvariant(), IsActive = token["status"].ToStringInvariant().Equals("open", StringComparison.OrdinalIgnoreCase), MarketSymbol = token["symbol"].ToStringInvariant(), MinTradeSize = token["min_order_size"].ConvertInvariant <decimal>(), QuantityStepSize = token["tick_size"].ConvertInvariant <decimal>(), QuoteCurrency = token["quote_currency"].ToStringInvariant(), PriceStepSize = token["quote_increment"].ConvertInvariant <decimal>() }); } })); } await Task.WhenAll(tasks); Logger.Warn("Gemini symbol metadata fetched and cached for several hours."); return(markets); }
protected virtual async Task <bool> GetUrl(UrlType urlType) { if ((urlType == UrlType.Start && GotStartUrl) || string.IsNullOrWhiteSpace(LocalIPAddressString) || string.IsNullOrWhiteSpace(FQDN)) { return(false); } else if (urlType == UrlType.Stop) { GotStartUrl = false; } string url; switch (urlType) { case UrlType.Start: url = Config.GetUrlStart; break; case UrlType.Stop: url = Config.GetUrlStop; break; case UrlType.Update: url = Config.GetUrlUpdate; break; case UrlType.Config: url = Config.GetUrlConfig; break; default: return(false); } if (!string.IsNullOrWhiteSpace(url)) { url = ReplaceUrl(url); try { KeyValuePair <string, object>[] headers = (Authorization is null ? null : new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Authorization", Authorization) }); byte[] bytes = await RequestMaker.MakeRequestAsync(new Uri(url), headers : headers); if (urlType == UrlType.Start) { GotStartUrl = true; } else if (urlType == UrlType.Update) { // if the update url sends bytes, we assume a software update, and run the result as an .exe if (bytes.Length != 0) { string tempFile = Path.Combine(OSUtility.TempFolder, "IPBanServiceUpdate.exe"); File.WriteAllBytes(tempFile, bytes); // however you are doing the update, you must allow -c and -d parameters // pass -c to tell the update executable to delete itself when done // pass -d for a directory which tells the .exe where this service lives string args = "-c \"-d=" + AppContext.BaseDirectory + "\""; Process.Start(tempFile, args); } } else if (urlType == UrlType.Config && bytes.Length != 0) { await WriteConfigAsync(Encoding.UTF8.GetString(bytes)); } } catch (Exception ex) { Logger.Error(ex, "Error getting url of type {0} at {1}", urlType, url); } } return(true); }