private static HttpClientHandler SetCookie(ExhentaiConfiguration configuration) { if (configuration == null || configuration.ipb_member_id == 0 || String.IsNullOrWhiteSpace(configuration.ipb_pass_hash)) { throw new ArgumentException("Incorrect data in nameof(configuration)"); } var handler = new HttpClientHandler { CookieContainer = new CookieContainer() }; handler.CookieContainer.Add(new Uri(BASE_EXHENTAI_URL), new Cookie(nameof(configuration.ipb_member_id), configuration.ipb_member_id.ToString())); handler.CookieContainer.Add(new Uri(BASE_EXHENTAI_URL), new Cookie(nameof(configuration.ipb_pass_hash), configuration.ipb_pass_hash)); return(handler); }
public EHentaiParser(EhentaiType type = EhentaiType.Ehentai, ExhentaiConfiguration configuration = null) { Type = type; switch (Type) { case EhentaiType.Ehentai: _client = new HttpClient { BaseAddress = new Uri(BASE_EHENTAI_URL) }; break; case EhentaiType.Exhentai: var handler = SetCookie(configuration); _client = new HttpClient(handler) { BaseAddress = new Uri(BASE_EXHENTAI_URL) }; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }