protected JustGivingClientBase(ClientConfiguration clientConfiguration, IHttpClient httpClient, IAccountApi accountApi, IDonationApi donationApi, IPageApi pageApi, ISearchApi searchApi, ICharityApi charityApi, IEventApi eventApi, ITeamApi teamApi) { if(httpClient == null) { throw new ArgumentNullException("httpClient", "httpClient must not be null to access the api."); } HttpClient = httpClient; HttpClient.ConnectionTimeOut = TimeSpan.FromMinutes(3); Account = accountApi; Donation = donationApi; Page = pageApi; Search = searchApi; Charity = charityApi; Event = eventApi; Team = teamApi; Configuration = clientConfiguration; InitApis(HttpClient, clientConfiguration); }
public JustGivingClient(ClientConfiguration clientConfiguration, IHttpClient httpClient, IAccountApi accountApi, IDonationApi donationApi, IPageApi pageApi, ISearchApi searchApi, ICharityApi charityApi, IEventApi eventApi, ITeamApi teamApi, IOneSearchApi oneSearch, ICountryApi countryApi, ICurrencyApi currencyApi, IProjectApi projectApi) : base( clientConfiguration, httpClient, accountApi, donationApi, pageApi, searchApi, charityApi, eventApi, teamApi, oneSearch, countryApi, currencyApi, projectApi) { }
protected void SetClientContext(string email, string password) { if (email == null || password == null) return; Username = email; Password = password; var config = new ClientConfiguration(_apiLocation, _apiKey, API_VERSION) { Username = email, Password = password }; JustGivingClient.UpdateConfiguration(config); }
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 void ListAllPages_ValidUserNameAndPassword_CallsExpectedUrl() { var client = new MockHttpClient<FundraisingPageSummaries>(HttpStatusCode.OK); var config = new ClientConfiguration("test") { Username = "******", Password = "******" }; var api = ApiClient.Create<PageApi, FundraisingPageSummaries>(config, client); api.ListAll(); var expected = string.Format( "{0}{1}/v{2}/fundraising/pages", config.RootDomain, config.ApiKey, config.ApiVersion); var url = client.LastRequestedUrl; Assert.AreEqual(expected, url); }
public void InitApis(IHttpClient httpClient, ClientConfiguration clientConfiguration) { HttpChannel = new HttpChannel(clientConfiguration, httpClient); Account = Account ?? new AccountApi(HttpChannel); Donation = Donation ?? new DonationApi(HttpChannel); Page = Page ?? new PageApi(HttpChannel); Search = Search ?? new SearchApi(HttpChannel); Charity = Charity ?? new CharityApi(HttpChannel); Event = Event ?? new EventApi(HttpChannel); Team = Team ?? new TeamApi(HttpChannel); }
/// <summary> /// Creates the kernel that will manage your application. /// </summary> /// <returns>The created kernel.</returns> private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); kernel.Bind<IHttpContentGetter>().To<CachingHttpContentGetter>(); kernel.Bind<IHttpContentGetter>().To<HttpContentGetter>().WhenInjectedInto<CachingHttpContentGetter>(); kernel.Bind<IJustGivingClient>().ToMethod(context => { var clientConfiguration = new ClientConfiguration("https://api-sandbox.justgiving.com/", "8b347861", 1); return new JustGivingClient(clientConfiguration); }).InRequestScope(); RegisterServices(kernel); return kernel; }
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); }
public void UpdateConfiguration(ClientConfiguration configuration) { Configuration = configuration; InitApis(HttpClient, configuration); }
protected JustGivingClientBase(ClientConfiguration clientConfiguration, IHttpClient httpClient) : this(clientConfiguration, httpClient, null, null, null, null, null, null, null, null, null, null, null) { }
public JustGivingClient(ClientConfiguration clientConfiguration, IHttpClient httpClient, IAccountApi accountApi, IDonationApi donationApi, IPageApi pageApi, ISearchApi searchApi, ICharityApi charityApi, IEventApi eventApi, ITeamApi teamApi): base(clientConfiguration, httpClient, accountApi, donationApi, pageApi, searchApi, charityApi, eventApi, teamApi) { }
public JustGivingClient(ClientConfiguration clientConfiguration, IHttpClient httpClient) : base(clientConfiguration, httpClient, null, null, null, null, null, null, null) { }
public JustGivingClient(ClientConfiguration clientConfiguration) : base(clientConfiguration, new HttpClientWrapper(), null, null, null, null, null, null, null) { }
// 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" }; } }
public void ListAll_WhenUsernameAuthenticationIsNull_ThrowsException() { var httpClient = new MockHttpClient<FundraisingPageSummaries>(HttpStatusCode.OK); var config = new ClientConfiguration(TestContext.ApiLocation, TestContext.ApiKey, TestContext.ApiVersion) { Password = "******" }; var api = ApiClient.Create<PageApi, FundraisingPageSummaries>(config, httpClient); var exception = Assert.Throws<Exception>(() => api.ListAll()); Assert.That(exception.Message, Is.StringContaining("Authentication required to list pages. Please set a valid configuration object.")); }
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()}); }
protected DataApiClientBase(HttpChannel channel, ClientConfiguration clientConfiguration) : base(channel) { DataClientConfiguration = clientConfiguration as DataClientConfiguration; }