Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit bc72146

Browse files
authored
Merge pull request #131 from cgalan-applaudostudios/feature/LAPP-40
LAPP-40 Move default values to optional parameters
2 parents c84ddb3 + b42b3ce commit bc72146

File tree

3 files changed

+26
-51
lines changed

3 files changed

+26
-51
lines changed

Analytics/Config.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using Segment.Model;
56

67
namespace Segment
78
{
@@ -50,30 +51,36 @@ public class Config
5051
/// <param name="send">Don’t send data to Segment</param>
5152
/// <param name="userAgent">Sets User Agent Header</param>
5253
public Config(
53-
string host = null,
54+
string host = "https://api.segment.io",
5455
string proxy = null,
5556
TimeSpan? timeout = null,
56-
int? maxQueueSize = null,
57-
int? flushAt = null,
58-
bool? async = null,
59-
int? threads = null,
60-
double? flushInterval = null,
61-
bool? gzip = null,
62-
bool? send = null,
57+
int maxQueueSize = 10000,
58+
int flushAt = 20,
59+
bool async = true,
60+
int threads = 1,
61+
double flushInterval = 10,
62+
bool gzip = false,
63+
bool send = false,
6364
string userAgent = null
6465
)
6566
{
66-
this.Host = host ?? Defaults.Host;
67+
this.Host = host;
6768
this.Proxy = proxy ?? "";
68-
this.Timeout = timeout ?? Defaults.Timeout;
69-
this.MaxQueueSize = maxQueueSize ?? Defaults.MaxQueueCapacity;
70-
this.FlushAt = flushAt ?? Defaults.FlushAt;
71-
this.Async = async ?? Defaults.Async;
72-
this.FlushIntervalInMillis = (int)((flushInterval ?? Defaults.FlushInterval) * 1000);
73-
this.Gzip = gzip ?? Defaults.Gzip;
74-
this.Send = send ?? false;
75-
this.UserAgent = userAgent ?? Defaults.UserAgent;
76-
this.Threads = threads ?? Defaults.Threads;
69+
this.Timeout = timeout ?? TimeSpan.FromSeconds(5);
70+
this.MaxQueueSize = maxQueueSize;
71+
this.FlushAt = flushAt;
72+
this.Async = async;
73+
this.FlushIntervalInMillis = (int)(flushInterval * 1000);
74+
this.Gzip = gzip;
75+
this.Send = send;
76+
this.UserAgent = userAgent ?? GetDefaultUserAgent();
77+
this.Threads = threads;
78+
}
79+
80+
private static string GetDefaultUserAgent()
81+
{
82+
var lib = new Context()["library"] as Dict;
83+
return $"{lib["name"]}/{lib["version"]}";
7784
}
7885

7986

Analytics/Defaults.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

Test.Net35/Request/BlockingRequestHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void RequestIncludesGzipHeaderWhenCompressRequestIsTrue()
5757
[Test]
5858
public void RequestIncludesUserAgentHeader()
5959
{
60-
_mockHeaders.Verify(x => x.Set("User-Agent", Defaults.UserAgent), Times.Once);
60+
_mockHeaders.Verify(x => x.Set("User-Agent", _client.Config.UserAgent), Times.Once);
6161
}
6262

6363
[Test]

0 commit comments

Comments
 (0)