public BaseController(JustGivingClient justGivingClient) { _apiLocation = ConfigurationManager.AppSettings["apiLocation"]; _apiKey = ConfigurationManager.AppSettings["apiKey"]; JustGivingClient = justGivingClient ?? CreateJustGivingClient(); }
public ActionResult FindCharities(string q) { var config = new ClientConfiguration( "https://api.staging.justgiving.com/", ConfigurationManager.AppSettings["JGApiKey"], 1); var client = new JustGivingClient(config); var results = client.Search.CharitySearch(q, 1, 10); return Json(results.Results, JsonRequestBehavior.AllowGet); }
public IEnumerable<BtwCharitySearchResult> FindCharities(string q) { var config = new ClientConfiguration( ConfigurationManager.AppSettings["JgApiBaseUrl"], ConfigurationManager.AppSettings["JGApiKey"], 1); var client = new JustGivingClient(config); var response = client.Search.CharitySearch(q); return response.Results .Select(r=> new BtwCharitySearchResult() { Id=int.Parse(r.CharityId), Name=r.Name, Logo=r.LogoFileName, Description=r.Description }); }
public SearchResults Search(IEnumerable<string> keywords) { var clientConfig = new ClientConfiguration("https://api-staging.justgiving.com/", "decbf1d2", 1); var client = new JustGivingClient(clientConfig); var all = client.Search.CharitySearch(string.Join(" + ", keywords)); if(all == null || all.Results == null) { return new SearchResults(); } var cleaner = new HtmlCleaner.HtmlCleaner(); var results = all.Results.Take(20).ToDictionary(charitySearchResult => charitySearchResult.CharityId, charitySearchResult => new SearchResult { Description = cleaner.RemoveHtml(charitySearchResult.Description), Title = cleaner.RemoveHtml(charitySearchResult.Name), CharityId = charitySearchResult.CharityId }); return new SearchResults(results.Values); }
// GET: Sdi public async Task<ActionResult> Return(string guid, int? donationId) { try { if (!donationId.HasValue) return RedirectToAction("Index", "Home"); var config = new ClientConfiguration( ConfigurationManager.AppSettings["JgApiBaseUrl"], ConfigurationManager.AppSettings["JGApiKey"], 1); var client = new JustGivingClient(config); DonationStatus donationStatus = null; try { donationStatus = client.Donation.RetrieveStatus(donationId.Value); } catch { } if ((donationStatus != null && donationStatus.Status == "Accepted") || ConfigurationManager.AppSettings["SkipDonationReferenceCheck"] == "true") { if (donationStatus != null) { _indulgeMeService.Absolve(guid, donationStatus.DonationId, donationStatus.DonationRef, donationStatus.Amount, donationStatus.Reference); } else if (ConfigurationManager.AppSettings["SkipDonationReferenceCheck"] == "true") { _indulgeMeService.Absolve(guid, 1, "1", 10, "not-a-real-donation"); } var indulgence = _indulgeMeService.GetIndulgenceByGuid(guid); _indulgeMeService.GenerateIndulgence(indulgence, System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "fonts"), System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Content")); await _indulgenceEmailer.Send(indulgence, ConfigurationManager.AppSettings["IndulgencePdfRelativePath"]); _indulgeMeService.Tweet(indulgence); TempData["absolved"] = guid; ControllerContext.RequestContext.HttpContext.Cache.Remove("siteInfo"); ControllerContext.RequestContext.HttpContext.Response.RemoveOutputCacheItem(Url.Action("GetLatest", "Api")); ViewData["ShowBlessing"] = true; return RedirectToAction("Index", "Indulgence", new {guid = guid}); } return HttpNotFound(); } catch (Exception ex) { _log.Error("unhandled error returning from SDI", ex); return new ContentResult() { Content = ex.Message + "\r\n" + ex.StackTrace, ContentEncoding = Encoding.UTF8, ContentType = "text/plain" }; } }
// Entry point for threads which periodically poll for a fundraiser's details. public static void EntryPoint(object threadId) { int threadIdInt = (int)threadId; // Create the API client JustGivingClient client = new JustGivingClient("9cce4750"); // Enter the loop which polls the API periodically while (true) { // Get the page ID from the config controller based on this thread's thread ID String pageId = ConfigController.GetPageIds()[threadIdInt]; int pollingPeriod = ConfigController.GetApiPollingPeriod(); // Get the page FundraisingPage page = client.Page.Retrieve(pageId); if (page != null) { // Get the information we need and put it in to our model string id = pageId; string name = page.PageTitle; decimal? fundingTarget = page.TargetAmount; string currentFunding = page.TotalRaised; string currencySymbol = page.CurrencySymbol; DateTime endDate = page.PageExpiryDate; List<Model.Donation> recentDonations = new List<Model.Donation>(); // Get the donations with a separate API call FundraisingPageDonations pageDonations = client.Page.RetrieveDonationsForPage(pageId); List<FundraisingPageDonation> donations = pageDonations.Donations; for (int i = 0; i < donations.Count && i < MAX_RECENT_DONATIONS; i++) { FundraisingPageDonation donation = donations[i]; DateTime? date = donation.DonationDate; string donator = donation.DonorDisplayName; decimal? value = donation.Amount; Model.Donation newDonation = new Model.Donation(date, donator, value); recentDonations.Add(newDonation); } Fundraiser fundraiser = new Fundraiser(id, name, fundingTarget, currentFunding, currencySymbol, endDate, recentDonations); // Check to see whether the storage controller currently has this fundraiser stored Fundraiser existingFundraiser = DataStorageController.GetFundraiser(pageId); if (existingFundraiser == null) { // It doesn't exist yet, so just add it DataStorageController.AddFundraiser(fundraiser); } else { // There's an existing item, lock it and then copy over the new details lock (existingFundraiser.ReadWriteLock) { existingFundraiser.CopyDetails(fundraiser); } } } Thread.Sleep(pollingPeriod); } }
public void SetUp() { var clientConfig = new ClientConfiguration("https://api-staging.justgiving.com/", "AppID", 1); _apiClient = new JustGivingClient(clientConfig); }
public ActionResult Absolve(int id, int? donationId) { var config = new ClientConfiguration( "https://api.staging.justgiving.com/", ConfigurationManager.AppSettings["JGApiKey"], 1); var client = new JustGivingClient(config); DonationStatus donation = null; if (donationId.HasValue) donation = client.Donation.RetrieveStatus(donationId.Value); else { donationId = 1; donation = new DonationStatus() {Amount = new decimal(r.NextDouble()*100), DonationId = 1, Reference = "1"}; } var indulgence = MvcApplication.CurrentSession.Load<Indulgence>(id.ToRavenDbId("indulgences")); if (indulgence == null) return new HttpNotFoundResult(); indulgence.IsBlessed = true; if (donation != null) { indulgence.AmountDonated = donation.Amount; indulgence.JustGivingDonationId = donationId.Value; indulgence.DonationReference = donation.Reference; } var sin = MvcApplication.CurrentSession.Load<Sin>(indulgence.SinId); sin.TotalDonationCount++; if (donation != null) sin.TotalDonated += donation.Amount; MvcApplication.CurrentSession.SaveChanges(); MvcApplication.TotalDonated = MvcApplication.CurrentSession .Query<Indulgence>("BlessedIndulgences").ToList().Sum(a => a.AmountDonated); string storagePath = HostingEnvironment.MapPath("~/content/indulgences"); string pdfFilename = string.Format("{0}/indulgence.pdf", indulgence.Id.IdValue()); string imageFilename = string.Format("{0}/indulgence.png", indulgence.Id.IdValue()); pdfFilename = Path.Combine(storagePath, pdfFilename); imageFilename = Path.Combine(storagePath, imageFilename); _indulgeMeService.GenerateIndulgence(pdfFilename, imageFilename, indulgence, HostingEnvironment.MapPath("~/content"), HostingEnvironment.MapPath("~/content")); // if the user supplied an email address send the pdf to them if (!string.IsNullOrWhiteSpace(indulgence.DonorEmailAddress)) { string donorEmailAddress = indulgence.DonorEmailAddress; string donorName = string.IsNullOrWhiteSpace(indulgence.Name) ? "" : indulgence.Name; indulgenceEmailer.Send(indulgence, pdfFilename); } try { // add the indulgence to the queue to tweet _tweetOutbox.Add(indulgence); } catch (Exception e) { log.Error("Could not tweet!", e); } TempData["absolutionId"] = id; // invalidate cache ControllerContext.RequestContext.HttpContext.Cache.Remove("siteInfo"); ControllerContext.RequestContext.HttpContext.Response.RemoveOutputCacheItem(Url.Action("GetLatest", "Api")); return RedirectToAction("Index", "Indulgence", new {id=indulgence.Id.IdValue()}); }