示例#1
0
        public static HttpClient Create(ILineConfiguration configuration, ILineBotLogger logger)
        {
            var loggingDelegatingHandler = new LoggingDelegatingHandler(logger);

            var client = new HttpClient(loggingDelegatingHandler)
            {
                BaseAddress = new Uri("https://api.line.me/v2/bot/")
            };

            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {configuration.ChannelAccessToken}");

            return(client);
        }
示例#2
0
        internal LineBot(ILineConfiguration configuration, HttpClient?client, ILineBotLogger?logger)
        {
            Guard.NotNull(nameof(configuration), configuration);

            if (string.IsNullOrWhiteSpace(configuration.ChannelAccessToken))
            {
                throw new ArgumentException($"The {nameof(configuration.ChannelAccessToken)} cannot be null or whitespace.", nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration.ChannelSecret))
            {
                throw new ArgumentException($"The {nameof(configuration.ChannelSecret)} cannot be null or whitespace.", nameof(configuration));
            }

            _logger             = logger ?? new EmptyLineBotLogger();
            _client             = client ?? HttpClientFactory.Create(configuration, _logger);
            _signatureValidator = new SignatureValidator(configuration);
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineBot"/> class.
 /// </summary>
 /// <param name="configuration">The configuration for the client.</param>
 /// <param name="logger">The logger.</param>
 public LineBot(ILineConfiguration configuration, ILineBotLogger logger)
     : this(configuration, null, logger)
 {
 }
 public static ILineBot CreateBot(ILineBotLogger logger)
 {
     return(new LineBot(new TestConfiguration(), TestHttpClient.Create(), logger));
 }
 internal LoggingDelegatingHandler(ILineBotLogger logger, HttpMessageHandler innerHandler)
     : base(innerHandler)
 {
     _logger = logger;
 }
 public LoggingDelegatingHandler(ILineBotLogger logger)
     : this(logger, new HttpClientHandler())
 {
 }