private static Resume Resume(string firstnameLastname) { Assert.ValidInput(firstnameLastname, "firstname-lastname"); firstnameLastname = firstnameLastname.Scrub(); if (ServiceCache.IsInCache <Resume>(firstnameLastname)) { var cachedResume = (Resume)ServiceCache.GetFromCache <Resume>(firstnameLastname); if (cachedResume != null) { return(cachedResume); } } var linkedInEmailAddress = ConfigurationManager.AppSettings["LinkedInEmailAddress"]; var linkedInPassword = ConfigurationManager.AppSettings["LinkedInPassword"]; var resumeSniffer = new LinkedInResumeSniffer(linkedInEmailAddress, linkedInPassword, firstnameLastname); Resume resume = null; try { resume = resumeSniffer.GetResume(); } catch (Exception) { HandleErrors(linkedInEmailAddress); } HandleErrors(resumeSniffer.Errors); return(resume.AddToCache(firstnameLastname)); }
private static WhoisEnhancedRecord WhoisEnhanced(string ipAddress, string filters, string referrer) { if (filters != null) { filters = filters.Scrub(); Assert.ValidInput(filters, "filters"); } if (referrer != null) { referrer = referrer.Scrub(); Assert.ValidInput(referrer, "referrer"); } var hash = BuildHashKey(ipAddress, filters); if (ServiceCache.IsInCache <WhoisEnhancedRecord>(hash)) { var cachedRecord = (WhoisEnhancedRecord)ServiceCache.GetFromCache <WhoisEnhancedRecord>(hash); if (cachedRecord != null) { return(cachedRecord); } } var whoisEnhancedRecord = new WhoisEnhancedRecord(Whois(ipAddress), filters, referrer); return(whoisEnhancedRecord.AddToCache(hash)); }
private static WhoisRecord Whois(string ipAddress) { ipAddress = ipAddress.Scrub(); if (string.IsNullOrEmpty(ipAddress)) { ipAddress = GetIpAddressFromRequest(ipAddress); } Assert.ValidInput(ipAddress, "ipAddress"); if (ServiceCache.IsInCache <WhoisRecord>(ipAddress)) { var cachedRecord = (WhoisRecord)ServiceCache.GetFromCache <WhoisRecord>(ipAddress); if (cachedRecord != null) { return(cachedRecord); } } var whoisClient = new WhoisClient(ipAddress); var record = whoisClient.GetWhoisRecord(); HandleErrors(whoisClient.Errors); return(record.AddToCache(ipAddress)); }
private static T GetFromCache <T>(string key) { if (ServiceCache.IsInCache <T>(key)) { return((T)ServiceCache.GetFromCache <T>(key)); } return(default(T)); }
private static Wishlist Wishlist(string listId) { Assert.ValidInput(listId, "listId"); if (ServiceCache.IsInCache <Wishlist>(listId)) { var cachedWishlist = (Wishlist)ServiceCache.GetFromCache <Wishlist>(listId); if (cachedWishlist != null) { return(cachedWishlist); } } var amazonResponse = new AmazonFactory(BuildRequest(null, listId)).GetResponse(); HandleErrors(amazonResponse.Errors); return(new Wishlist(amazonResponse.Products.OrderBy(p => p.AuthorsMLA).ThenBy(p => p.Title)).AddToCache(listId)); }
private static Reviews Reviews(string customerId) { Assert.ValidInput(customerId, "customerId"); if (ServiceCache.IsInCache <Reviews>(customerId)) { var cachedReviews = (Reviews)ServiceCache.GetFromCache <Reviews>(customerId); if (cachedReviews != null) { return(cachedReviews); } } var amazonResponse = new AmazonFactory(BuildRequest(customerId, null)).GetResponse(); HandleErrors(amazonResponse.Errors); return(new Reviews(amazonResponse.Reviews.OrderByDescending(r => r.Date)).AddToCache(customerId)); }
private static Profile DiscoverUser(string username) { username = username.Scrub(); Assert.ValidInput(username, "username"); if (ServiceCache.IsInCache <Profile>(username)) { var cachedProfile = (Profile)ServiceCache.GetFromCache <Profile>(username); if (cachedProfile != null) { return(cachedProfile); } } var sniffer = new ProfileSniffer(username); var profile = sniffer.GetProfile(); HandleErrors(sniffer.Errors); return(profile.AddToCache(username)); }