Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
project.lock.json
test/SegmentDotNet.Tests/bin/
test/SegmentDotNet.Tests/obj/
src/SegmentDotNet/obj/
src/SegmentDotNet/bin/Debug/
test/SegmentDotNet.Tests/.env
.vs/
12 changes: 11 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# SegmentDotNet

Segment integration for your .NET Core projects, relies on dependency injection.
Segment integration for your .NET Core projects, relies on dependency injection.

# Tests

Copy test/SegmentDotNet.Tests/sample.env to test/SegmentDotNet.Tests/.env and fill out the `SEGMENT_WRITE_KEY` variable with your Segment write key.

To run tests run `dotnet test` from the command line using test/SegmentDotNet.tests as your working directory.

There would be more tests but [Segment returns 200 response codes](https://segment.com/docs/libraries/http/#selecting-integrations) regardless of invalid input, auth keys, or any other bad information other than malformed/too large JSON. I'll add more once Segment fixes this.

Running tests will attempt to push events using the key defined as the environment variable `SEGMENT_WRITE_KEY`, you can check for results in the debugger on Segment for now.
44 changes: 44 additions & 0 deletions SegmentDotNet.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5E6DE7BC-0749-4C63-8441-95A5756E5167}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EDA04816-70FA-4427-AC2D-D5FBA1B12951}"
ProjectSection(SolutionItems) = preProject
CHANGELOG.md = CHANGELOG.md
global.json = global.json
LICENSE.txt = LICENSE.txt
Readme.md = Readme.md
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SegmentDotNet", "src\SegmentDotNet\SegmentDotNet.xproj", "{AE25F674-BAAB-41B7-8FF5-36EAF7341ECC}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SegmentDotNet.Tests", "test\SegmentDotNet.Tests\SegmentDotNet.Tests.xproj", "{D5950492-E758-4EB5-AE16-F5D4BCF1EC85}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5BF05EAE-3AD2-40BF-9EE1-5E92C1F5A90B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE25F674-BAAB-41B7-8FF5-36EAF7341ECC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE25F674-BAAB-41B7-8FF5-36EAF7341ECC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE25F674-BAAB-41B7-8FF5-36EAF7341ECC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE25F674-BAAB-41B7-8FF5-36EAF7341ECC}.Release|Any CPU.Build.0 = Release|Any CPU
{D5950492-E758-4EB5-AE16-F5D4BCF1EC85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5950492-E758-4EB5-AE16-F5D4BCF1EC85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5950492-E758-4EB5-AE16-F5D4BCF1EC85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5950492-E758-4EB5-AE16-F5D4BCF1EC85}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AE25F674-BAAB-41B7-8FF5-36EAF7341ECC} = {5E6DE7BC-0749-4C63-8441-95A5756E5167}
{D5950492-E758-4EB5-AE16-F5D4BCF1EC85} = {5BF05EAE-3AD2-40BF-9EE1-5E92C1F5A90B}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
9 changes: 9 additions & 0 deletions src/SegmentDotNet/Abstractions/IDateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SegmentDotNet.Abstractions
{
using System;

public interface IDateTime
{
DateTime UtcNow { get; }
}
}
9 changes: 9 additions & 0 deletions src/SegmentDotNet/Abstractions/SystemDateTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SegmentDotNet.Abstractions
{
using System;

public class SystemDateTime : IDateTime
{
public DateTime UtcNow { get { return DateTime.UtcNow; } }
}
}
17 changes: 17 additions & 0 deletions src/SegmentDotNet/Client/Request/Abstract/AnonymousBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SegmentDotNet.Client.Request.Abstract
{
using Abstractions;
using Newtonsoft.Json;
using Populators.Contexts;
using Populators.Integrations;

public abstract class AnonymousBase : UserTimestampBase
{
public AnonymousBase(Context context, IDateTime datetime, Integrations integrations) : base(context, datetime, integrations)
{
}

[JsonProperty("anonymousId")]
public string AnonymousId { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/SegmentDotNet/Client/Request/Abstract/Base.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace SegmentDotNet.Client.Request.Abstract
{
using Interfaces;
using Newtonsoft.Json;
using Populators.Contexts;
using Populators.Integrations;

public abstract class Base : ISegmentRequest
{
public Base(
Context context,
Integrations integrations)
{
this.Context = context;
this.Integrations = integrations;
}

[JsonProperty("context")]
public Context Context { get; set; }

[JsonProperty("integrations")]
public Integrations Integrations { get; set; }

public abstract string Endpoint { get; }
}
}
19 changes: 19 additions & 0 deletions src/SegmentDotNet/Client/Request/Abstract/TraitsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace SegmentDotNet.Client.Request.Abstract
{
using Abstractions;
using Newtonsoft.Json;
using Populators.Traits;
using Populators.Contexts;
using Populators.Integrations;

public abstract class TraitsBase : AnonymousBase
{
public TraitsBase(Context context, IDateTime datetime, Integrations integrations, Traits traits) : base(context, datetime, integrations)
{
this.Traits = traits;
}

[JsonProperty("traits")]
public Traits Traits { get; set; }
}
}
32 changes: 32 additions & 0 deletions src/SegmentDotNet/Client/Request/Abstract/UserTimestampBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace SegmentDotNet.Client.Request.Abstract
{
using Abstractions;
using Newtonsoft.Json;
using System;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public abstract class UserTimestampBase : Base
{
public UserTimestampBase(
Context context,
IDateTime datetime,
Integrations integrations)
: base(context, integrations)
{
this.DateTime = datetime;
}

protected IDateTime DateTime { get; set; }

[JsonProperty("type")]
public abstract string Type { get; }

[JsonProperty("userId")]
public string UserId { get; set; }

[JsonProperty("timestamp")]
public DateTime Timestamp { get { return this.DateTime.UtcNow; } }
}
}
25 changes: 25 additions & 0 deletions src/SegmentDotNet/Client/Request/Alias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

namespace SegmentDotNet.Client.Request
{
using System;
using Abstract;
using Abstractions;
using Newtonsoft.Json;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Alias : UserTimestampBase
{
public Alias(Context context, IDateTime datetime, Integrations integrations) : base(context, datetime, integrations)
{
}

public override string Type { get { return "alias"; } }

public override string Endpoint { get { return "alias"; } }

[JsonProperty("previousId")]
public string PreviousId { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/SegmentDotNet/Client/Request/Batch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace SegmentDotNet.Client.Request
{
using Abstract;
using Newtonsoft.Json;
using System.Collections.Generic;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Batch : Base
{
public Batch(Context context, Integrations integrations) : base(context, integrations)
{
this.Items = new List<UserTimestampBase>();
}

public override string Endpoint { get { return "batch"; } }

[JsonProperty("batch")]
public List<UserTimestampBase> Items { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/SegmentDotNet/Client/Request/Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace SegmentDotNet.Client.Request
{
using Abstract;
using Abstractions;
using Newtonsoft.Json;
using Populators.Traits;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Group : TraitsBase
{
public Group(Context context, IDateTime datetime, Integrations integrations, Traits traits) : base(context, datetime, integrations, traits)
{
}

public override string Type { get { return "group"; } }

public override string Endpoint { get { return "group"; } }

[JsonProperty("groupId")]
public string GroupId { get; set; }
}
}
21 changes: 21 additions & 0 deletions src/SegmentDotNet/Client/Request/Identify.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace SegmentDotNet.Client.Request
{
using Abstract;
using Abstractions;
using Newtonsoft.Json;
using Populators.Traits;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Identify : TraitsBase
{
public Identify(Context context, IDateTime datetime, Integrations integrations, Traits traits) : base(context, datetime, integrations, traits)
{
}

public override string Type { get { return "identify"; } }

public override string Endpoint { get { return "identify"; } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SegmentDotNet.Client.Request.Interfaces
{
public interface ISegmentRequest
{
string Endpoint { get; }
}
}
23 changes: 23 additions & 0 deletions src/SegmentDotNet/Client/Request/Page.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace SegmentDotNet.Client.Request
{
using Abstract;
using Abstractions;
using Newtonsoft.Json;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Page : AnonymousBase
{
public Page(Context context, IDateTime datetime, Integrations integrations) : base(context, datetime, integrations)
{
}

public override string Type { get { return "page"; } }

public override string Endpoint { get { return "page"; } }

[JsonProperty("name")]
public string Name { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/SegmentDotNet/Client/Request/Screen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace SegmentDotNet.Client.Request
{
using Abstract;
using Abstractions;
using Newtonsoft.Json;
using Populators.Contexts;
using Populators.Integrations;

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Screen : AnonymousBase
{
public Screen(Context context, IDateTime datetime, Integrations integrations) : base(context, datetime, integrations)
{
}

public override string Type { get { return "screen"; } }

public override string Endpoint { get { return "screen"; } }

[JsonProperty("name")]
public string Name { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/SegmentDotNet/Client/Request/Track.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace SegmentDotNet.Client.Request
{
using Abstract;
using Abstractions;
using Newtonsoft.Json;
using Populators.Contexts;
using Populators.Integrations;
using Populators.Properties;
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class Track : AnonymousBase
{
public Track(Context context, IDateTime datetime, Integrations integrations, Properties properties) : base(context, datetime, integrations)
{
this.Properties = properties;
}

public override string Type { get { return "track"; } }

public override string Endpoint { get { return "track"; } }

[JsonProperty("event")]
public string Event { get; set; }

[JsonProperty("properties")]
public Properties Properties { get; set; }
}
}
Loading