/// <summary>
 /// Adds a default HTTP parameter (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
 /// Used on every request made by this client instance
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the parameter</param>
 /// <param name="value">Value of the parameter</param>
 /// <returns>This request</returns>
 public static IRestClient AddDefaultParameter(this IRestClient restClient, string name, object value)
 => restClient.AddDefaultParameter(new Parameter
 {
     Name  = name,
     Value = value,
     Type  = ParameterType.GetOrPost
 });
示例#2
0
 /// <summary>
 /// Adds a parameter to the request. There are four types of parameters:
 ///    - GetOrPost: Either a QueryString value or encoded form value based on method
 ///    - HttpHeader: Adds the name/value pair to the HTTP request's Headers collection
 ///    - UrlSegment: Inserted into URL if there is a matching url token e.g. {AccountId}
 ///    - RequestBody: Used by AddBody() (not recommended to use directly)
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the parameter</param>
 /// <param name="value">Value of the parameter</param>
 /// <param name="type">The type of parameter to add</param>
 /// <returns>This request</returns>
 public static void AddDefaultParameter(this IRestClient restClient, string name, object value,
                                        ParameterType type)
 {
     restClient.AddDefaultParameter(new Parameter {
         Name = name, Value = value, Type = type
     });
 }
示例#3
0
        public SkypeClient(ILogger log, SkypeCrawlJobData skypeCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (skypeCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(skypeCrawlJobData));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
            _exchangeService.UseDefaultCredentials = false;
            _exchangeService.Credentials           = new WebCredentials(skypeCrawlJobData.email, skypeCrawlJobData.password);
            _exchangeService.AutodiscoverUrl(skypeCrawlJobData.email);

            _imHistory = new List <EmailMessage>();

            this.log    = log ?? throw new ArgumentNullException(nameof(log));
            this.client = client ?? throw new ArgumentNullException(nameof(client));

            // TODO use info from skypeCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(BaseUri);
            client.AddDefaultParameter("api_key", skypeCrawlJobData.ApiKey, ParameterType.QueryString);
        }
 /// <summary>
 ///     Adds a default parameter to the request. There are four types of parameters:
 ///     - GetOrPost: Either a QueryString value or encoded form value based on method
 ///     - HttpHeader: Adds the name/value pair to the HTTP request's Headers collection
 ///     - UrlSegment: Inserted into URL if there is a matching url token e.g. {AccountId}
 ///     - RequestBody: Used by AddBody() (not recommended to use directly)
 ///     Used on every request made by this client instance
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the parameter</param>
 /// <param name="value">Value of the parameter</param>
 /// <param name="type">The type of parameter to add</param>
 /// <returns>This request</returns>
 public static IRestClient AddDefaultParameter(
     this IRestClient restClient,
     string name,
     object value,
     ParameterType type
     )
 => restClient.AddDefaultParameter(new Parameter(name, value, type));
        public RottenTomatoesRestClient(string apiKey)
        {
            _client = new RestClient
            {
                UserAgent = "rotten-tomatoes-csharp",
                BaseUrl   = "http://api.rottentomatoes.com/api/public/v1.0",
            };

            _client.AddDefaultParameter("apiKey", apiKey);
        }
        public HubSpotClient(ILogger log, HubSpotCrawlJobData hubspotCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (hubspotCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(hubspotCrawlJobData));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _log = log ?? throw new ArgumentNullException(nameof(log));

            // TODO use info from hubspotCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(s_baseUri);
            client.AddDefaultParameter("api_key", hubspotCrawlJobData.ApiKey, ParameterType.QueryString);
        }
示例#7
0
        public HubSpotClient(ILogger log, HubSpotCrawlJobData hubspotCrawlJobData, IRestClient client)
        {
            if (hubspotCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(hubspotCrawlJobData));
            }

            _log = log ?? throw new ArgumentNullException(nameof(log));

            _client         = client ?? throw new ArgumentNullException(nameof(client));
            _client.BaseUrl =
                hubspotCrawlJobData.BaseUri != null
                    ? hubspotCrawlJobData.BaseUri
                    : new Uri(HubSpotConstants.ApiBaseUri);

            _client.AddDefaultParameter("hapikey", hubspotCrawlJobData.ApiToken, ParameterType.QueryString);
        }
示例#8
0
        public SQLClient(ILogger <SQLClient> log, SQLCrawlJobData sqlCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (sqlCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(sqlCrawlJobData));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.log    = log ?? throw new ArgumentNullException(nameof(log));
            this.client = client ?? throw new ArgumentNullException(nameof(client));

            // TODO use info from sqlCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(BaseUri);
            client.AddDefaultParameter("api_key", sqlCrawlJobData.ConnectionString, ParameterType.QueryString);
        }
示例#9
0
        public ModulusAPIClient(ILogger log, ModulusAPICrawlJobData modulusapiCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (modulusapiCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(modulusapiCrawlJobData));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.log    = log ?? throw new ArgumentNullException(nameof(log));
            this.client = client ?? throw new ArgumentNullException(nameof(client));

            // TODO use info from modulusapiCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(BaseUri);
            client.AddDefaultParameter("api_key", modulusapiCrawlJobData.ApiKey, ParameterType.QueryString);
        }
示例#10
0
        public KafkaClient(ILogger log, KafkaCrawlJobData kafkaCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (kafkaCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(kafkaCrawlJobData));
            }

            _kafkaCrawlJobData = kafkaCrawlJobData;

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.log    = log ?? throw new ArgumentNullException(nameof(log));
            this.client = client ?? throw new ArgumentNullException(nameof(client));

            // TODO use info from kafkaCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(BaseUri);
            client.AddDefaultParameter("api_key", kafkaCrawlJobData.ApiKey, ParameterType.QueryString);

            if (!string.IsNullOrEmpty(_kafkaCrawlJobData.KafkaServer)) //this means that Kafka stream is not configured, so we should use the API. If it's not empty/null, then it's configured so we should use it.
            {
                //Configure the consumer
                _consumerConfig = new ConsumerConfig
                {
                    BootstrapServers = _kafkaCrawlJobData.KafkaServer,

                    SecurityProtocol = SecurityProtocol.SaslSsl,
                    SaslMechanism    = SaslMechanism.Plain,
                    SslCaLocation    = @".\cacert.pem",
                    SocketTimeoutMs  = 60000,
                    SessionTimeoutMs = 30000,
                    SaslUsername     = @"$ConnectionString",

                    SaslPassword = _kafkaCrawlJobData.KafkaConnectionString,

                    GroupId         = @"$Default",
                    AutoOffsetReset = AutoOffsetReset.Earliest
                };
            }
        }
示例#11
0
        public ODataClient(ILogger log, ODataCrawlJobData odataCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (odataCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(odataCrawlJobData));
            }
            _oDataCrawlJobData = odataCrawlJobData ?? throw new ArgumentNullException(nameof(odataCrawlJobData));

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.log    = log ?? throw new ArgumentNullException(nameof(log));
            this.client = client ?? throw new ArgumentNullException(nameof(client));

            // TODO use info from odataCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(BaseUri);
            client.AddDefaultParameter("api_key", odataCrawlJobData.Url, ParameterType.QueryString);
        }
示例#12
0
 /// <summary>
 /// Adds a default URL query parameter to the RestClient. Used on every request made by this client instance.
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the query parameter to add</param>
 /// <param name="value">Value of the query parameter to add</param>
 /// <returns></returns>
 public static IRestClient AddDefaultQueryParameter(this IRestClient restClient, string name, string value)
 => restClient.AddDefaultParameter(name, value, ParameterType.QueryString);
示例#13
0
 /// <summary>
 /// Adds a default URL segment parameter to the RestClient. Used on every request made by this client instance.
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the segment to add</param>
 /// <param name="value">Value of the segment to add</param>
 /// <returns></returns>
 public static IRestClient AddDefaultUrlSegment(this IRestClient restClient, string name, string value)
 => restClient.AddDefaultParameter(name, value, ParameterType.UrlSegment);
示例#14
0
 /// <summary>
 /// Adds a default header to the RestClient. Used on every request made by this client instance.
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the header to add</param>
 /// <param name="value">Value of the header to add</param>
 /// <returns></returns>
 public static IRestClient AddDefaultHeader(this IRestClient restClient, string name, string value)
 => restClient.AddDefaultParameter(name, value, ParameterType.HttpHeader);
示例#15
0
 /// <summary>
 /// Adds a default HTTP parameter (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
 /// Used on every request made by this client instance
 /// </summary>
 /// <param name="restClient">The IRestClient instance</param>
 /// <param name="name">Name of the parameter</param>
 /// <param name="value">Value of the parameter</param>
 /// <returns>This request</returns>
 public static IRestClient AddDefaultParameter(this IRestClient restClient, string name, object value)
 {
     return(restClient.AddDefaultParameter(new Parameter(name, value, ParameterType.GetOrPost)));
 }
 public RebrickableInfoRepository(IConfiguration config)
 {
     _rebrickableClient = new RestClient("https://rebrickable.com/api/v3/");
     _rebrickableClient.AddDefaultParameter(new Parameter("key", config["rebrickable:key"], ParameterType.QueryString));
 }
示例#17
0
 void SetApiKey(string apiKey)
 {
     this.apiKey = apiKey;
     restClient.AddDefaultParameter(new Parameter("apikey", apiKey, ParameterType.QueryString));
 }