Created
April 10, 2015 10:13
-
-
Save hallojoe/c487e15f5cbf8f8b9d28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MajesticResolver | |
{ | |
public class Results | |
{ | |
public string Error { get; set; } | |
public Result Result { get; set; } | |
public Results() | |
{ | |
Result = new Result(); | |
} | |
} | |
public class Result | |
{ | |
public string OrigRequest { get; set; } | |
public string StatsForDomain { get; set; } | |
public int StatsRefDomains { get; set; } | |
public int StatsExternalBackLinks { get; set; } | |
public int StatsIndexedURLs { get; set; } | |
public string ItemType { get; set; } | |
public string LinkBackURL { get; set; } | |
} | |
public Results GetData(string url, string proxyIp = "", int proxyPort = 0) | |
{ | |
var model = new Results(); | |
string majesticUrlPattern = "http://api.majesticseo.com/getdomainstats.php?apikey=2F85C7EF65&url={0}"; | |
string majesticUrl = string.Format(majesticUrlPattern, url); | |
string data = string.Empty; | |
using (WebClient wc = new WebClient()) | |
{ | |
if (!string.IsNullOrWhiteSpace(proxyIp)) | |
wc.Proxy = new WebProxy(proxyIp, proxyPort); | |
data = wc.DownloadString(majesticUrl); | |
} | |
if (!string.IsNullOrEmpty(data)) | |
{ | |
var document = XDocument.Parse(data); | |
var resultElement = document.Root.Element("Result"); | |
model.Error = document.Root.Attribute("Error").Value; | |
model.Result.ItemType = resultElement.Attribute("ItemType").Value; | |
model.Result.LinkBackURL = resultElement.Attribute("LinkBackURL").Value; | |
model.Result.OrigRequest = resultElement.Attribute("OrigRequest").Value; | |
model.Result.StatsExternalBackLinks = Convert.ToInt32(resultElement.Attribute("StatsExternalBackLinks").Value); | |
model.Result.StatsForDomain = resultElement.Attribute("StatsForDomain").Value; | |
model.Result.StatsIndexedURLs = Convert.ToInt32(resultElement.Attribute("StatsIndexedURLs").Value); | |
model.Result.StatsRefDomains = Convert.ToInt32(resultElement.Attribute("StatsRefDomains")); | |
} | |
return model; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment