private Class CreateResultClass(VimeoApiEndpointInfo apiInfo) { var d = apiInfo.CommandParameters.Where(el => el.Required).ToDictionary(el => el.Name, el => "messi"); d["access_token"] = this.AccessToken; var json = this.CallApi(apiInfo, d); JsonParser parser = new JsonParser(); var c = parser.Parse(json, "Result"); apiInfo.ResultClassName = String.Format("{0}.{1}.Result", apiInfo.Name1, apiInfo.Name2); if (json.StartsWith("[") == true) { apiInfo.ResultIsArray = true; } else if (json.StartsWith("{") == true) { apiInfo.ResultIsArray = false; } else { throw new NotSupportedException(); } return c; }
private void AddEntityClasses(HtmlDocument document, Namespace nameSpace, TwitterApiEndpointInfo apiInfo) { var ns = nameSpace; var doc = document; Class api1 = new Class(AccessModifier.Public, apiInfo.Name1); api1.Modifier.Partial = true; ns.Classes.Add(api1); Class api2 = new Class(AccessModifier.Public, apiInfo.Name2); api2.Modifier.Partial = true; api1.Classes.Add(api2); api2.Classes.Add(this.CreateCommandClass(doc, apiInfo)); //Result class var exampleNode = doc.DocumentNode.SelectSingleNode("//article[@id='main-content']" + "//pre[@class='brush: jscript' or @class='brush: javascript']"); if (exampleNode == null) { return; } var json = exampleNode.InnerText.Trim(); json = json.Replace(".json\";", ".json\"");//https://dev.twitter.com/rest/reference/post/geo/place json = json.Replace(" ...", "");//https://dev.twitter.com/rest/reference/get/trends/available JsonParser parser = new JsonParser(); var resultClass = parser.Parse(json, "Result"); //friendships/no_retweets/ids if (apiInfo.Name1 == "Friendships" && apiInfo.Name2 == "No_Retweets_Ids") { apiInfo.ResultClassName = "String"; } else { api2.Classes.Add(resultClass); apiInfo.ResultClassName = String.Format("{0}.{1}.Result", apiInfo.Name1, apiInfo.Name2); } if (json.StartsWith("[") == true) { apiInfo.ResultIsArray = true; } else if (json.StartsWith("{") == true) { apiInfo.ResultIsArray = false; } else { throw new NotSupportedException(); } }