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

Commit da49869

Browse files
committed
Can I just die already?
1 parent 306bed1 commit da49869

21 files changed

+812
-117
lines changed

src/Gfycat.Net.Analytics/CameraDirection.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
1+
#pragma warning disable CS1591
52
namespace Gfycat.Analytics
63
{
74
public enum CameraDirection
85
{
6+
None,
97
Front,
108
Back
119
}

src/Gfycat.Net.Analytics/Gfycat.Net.Analytics.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<Description>An unofficial wrapper around the Gfycat analytics API</Description>
1717
</PropertyGroup>
1818

19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
20+
<DocumentationFile>bin\Debug\netstandard1.2\.xml</DocumentationFile>
21+
</PropertyGroup>
22+
1923
<ItemGroup>
2024
<ProjectReference Include="..\Gfycat.Net\Gfycat.Net.csproj" />
2125
</ItemGroup>

src/Gfycat.Net.Analytics/GfycatAnalyticsClient.cs

Lines changed: 116 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,40 @@
55
using System.Net;
66
using System.Linq;
77

8+
[assembly: CLSCompliant(true)]
9+
810
namespace Gfycat.Analytics
911
{
12+
/// <summary>
13+
/// Represents a client for communicating with the Gfycat analytics API. See https://developers.gfycat.com/analytics for info on when to use this client
14+
/// </summary>
1015
public class GfycatAnalyticsClient
1116
{
1217
internal GfycatAnalyticsClientConfig Config { get; }
1318

19+
/// <summary>
20+
/// Gets the current user's tracking cookie
21+
/// </summary>
1422
public string CurrentUserTrackingCookie { get; private set; } = GfycatAnalyticsClientConfig.GenerateCookie();
1523

24+
/// <summary>
25+
/// Creates a new client using the specified app name, app Id, app version, and user tracking cookie
26+
/// </summary>
27+
/// <param name="appName"></param>
28+
/// <param name="appId"></param>
29+
/// <param name="appVersion"></param>
30+
/// <param name="userTrackingCookie"></param>
1631
public GfycatAnalyticsClient(string appName, string appId, Version appVersion, string userTrackingCookie)
1732
{
1833
Config = new GfycatAnalyticsClientConfig(appName, appId, appVersion);
1934
CurrentUserTrackingCookie = userTrackingCookie;
2035
}
2136

37+
/// <summary>
38+
/// Creates a new client using the specified config and user tracking cookie
39+
/// </summary>
40+
/// <param name="config"></param>
41+
/// <param name="userTrackingCookie"></param>
2242
public GfycatAnalyticsClient(GfycatAnalyticsClientConfig config, string userTrackingCookie)
2343
{
2444
Config = config;
@@ -58,7 +78,7 @@ private async Task<RestResponse> SendImpressionInternalAsync(Impression impressi
5878
if (impression == null)
5979
throw new ArgumentNullException(nameof(impression), "The provided impression can't be null!");
6080

61-
return await SendInternalAsync("POST", GfycatAnalyticsClientConfig.BaseImpressionsUrl + impression.CreateQuery(), options);
81+
return await SendInternalAsync("POST", GfycatAnalyticsClientConfig.BaseImpressionsUrl + impression.CreateQuery(this), options);
6282
}
6383

6484
private async Task<RestResponse> SendImpressionsBulkInternalAsync(IEnumerable<Impression> impressions, RequestOptions options)
@@ -68,30 +88,48 @@ private async Task<RestResponse> SendImpressionsBulkInternalAsync(IEnumerable<Im
6888
if (impressions.Count() == 0)
6989
throw new ArgumentException("You can't post an impression for nothing!");
7090

71-
return await SendInternalAsync("POST", GfycatAnalyticsClientConfig.BaseImpressionsUrl + impressions.CreateQuery(), options);
91+
return await SendInternalAsync("POST", GfycatAnalyticsClientConfig.BaseImpressionsUrl + impressions.CreateQuery(this), options);
7292
}
7393

94+
/// <summary>
95+
/// Sends an impression using the specified gfy, context, flow, view tag, and keyword
96+
/// </summary>
97+
/// <param name="gfy"></param>
98+
/// <param name="context"></param>
99+
/// <param name="flow"></param>
100+
/// <param name="viewTag"></param>
101+
/// <param name="keyword"></param>
102+
/// <param name="options"></param>
103+
/// <returns></returns>
74104
public async Task SendImpressionAsync(Gfy gfy, ImpressionContext context = ImpressionContext.None, ImpressionFlow flow = ImpressionFlow.None, string viewTag = null, string keyword = null, RequestOptions options = null)
75105
{
76106
await SendImpressionAsync(new Impression
77107
{
78-
AppId = Config.AppId,
79-
Version = Config.AppVersion.ToString(),
80-
SessionTrackingCookie = Config.SessionId,
81-
UserTrackingCookie = CurrentUserTrackingCookie,
82-
GfycatId = gfy.Id,
83-
Context = (context == ImpressionContext.None ? null : context.ToString()),
84-
Flow = (flow == ImpressionFlow.None ? null : flow.ToString()),
108+
Gfycat = gfy,
109+
Context = context,
110+
Flow = flow,
85111
Keyword = keyword,
86112
ViewTag = viewTag
87113
}, options);
88114
}
89115

116+
/// <summary>
117+
/// Sends one impression to Gfycat impressions
118+
/// </summary>
119+
/// <param name="impression"></param>
120+
/// <param name="options"></param>
121+
/// <returns></returns>
90122
public async Task SendImpressionAsync(Impression impression, RequestOptions options = null)
91123
{
92124
await SendImpressionInternalAsync(impression, options);
93125
}
94126

127+
/// <summary>
128+
/// Sends multiple impressions to Gfycat impressions
129+
/// </summary>
130+
/// <param name="impressions"></param>
131+
/// <param name="options"></param>
132+
/// <returns></returns>
95133
public async Task SendImpressionsBulkAsync(IEnumerable<Impression> impressions, RequestOptions options = null)
96134
{
97135
await SendImpressionsBulkInternalAsync(impressions, options);
@@ -128,33 +166,59 @@ private async Task<RestResponse> SendAnalyticsInternalAsync(AnalyticsEvent aEven
128166
}.Concat(data).ToArray()
129167
), options);
130168
}
131-
169+
/// <summary>
170+
/// Sends a first launch event to Gfycat analytics
171+
/// </summary>
172+
/// <param name="options"></param>
173+
/// <returns></returns>
132174
public async Task SendAppFirstLaunchEventAsync(RequestOptions options = null)
133175
{
134176
await SendAnalyticsInternalAsync(AnalyticsEvent.AppFirstLaunch, options, ("utc", CurrentUserTrackingCookie));
135177
}
136-
178+
/// <summary>
179+
/// Sends a video share event to Gfycat analytics
180+
/// </summary>
181+
/// <param name="gfy"></param>
182+
/// <param name="options"></param>
183+
/// <returns></returns>
137184
public async Task SendShareVideoEventAsync(Gfy gfy, RequestOptions options = null)
138185
{
139186
if (gfy == null)
140187
throw new ArgumentNullException("The provided Gfy was null");
141188

142189
await SendAnalyticsInternalAsync(AnalyticsEvent.ShareGfy, options, ("utc", CurrentUserTrackingCookie), ("gfyid", gfy.Id));
143190
}
144-
191+
/// <summary>
192+
/// Sends a tap category event to Gfycat analytics
193+
/// </summary>
194+
/// <param name="keyword"></param>
195+
/// <param name="options"></param>
196+
/// <returns></returns>
145197
public async Task SendTapCategoryEventAsync(string keyword, RequestOptions options = null)
146198
{
147199
if (string.IsNullOrWhiteSpace(keyword))
148200
throw new ArgumentException("The provided keyword is invalid!");
149201

150202
await SendAnalyticsInternalAsync(AnalyticsEvent.SelectCategory, options, ("utc", CurrentUserTrackingCookie), ("keyword", keyword));
151203
}
152-
204+
/// <summary>
205+
/// Sends a video creation event to Gfycat analytics
206+
/// </summary>
207+
/// <param name="videoLengthMilliseconds"></param>
208+
/// <param name="cameraDirection"></param>
209+
/// <param name="options"></param>
210+
/// <returns></returns>
153211
public async Task SendCreateVideoEventAsync(int? videoLengthMilliseconds = null, CameraDirection? cameraDirection = null, RequestOptions options = null)
154212
{
155-
await SendAnalyticsInternalAsync(AnalyticsEvent.CreateVideo, options, ("utc", CurrentUserTrackingCookie), ("length", videoLengthMilliseconds), ("context", cameraDirection));
213+
await SendAnalyticsInternalAsync(AnalyticsEvent.CreateVideo, options, ("utc", CurrentUserTrackingCookie), ("length", videoLengthMilliseconds), ("context", cameraDirection == CameraDirection.None ? null : cameraDirection));
156214
}
157215

216+
/// <summary>
217+
/// Sends a search videos event to Gfycat analytics
218+
/// </summary>
219+
/// <param name="keyword"></param>
220+
/// <param name="options"></param>
221+
/// <returns></returns>
158222
public async Task SendSearchVideosEventAsync(string keyword, RequestOptions options = null)
159223
{
160224
if (string.IsNullOrWhiteSpace(keyword))
@@ -163,16 +227,36 @@ public async Task SendSearchVideosEventAsync(string keyword, RequestOptions opti
163227
await SendAnalyticsInternalAsync(AnalyticsEvent.SearchVideo, options, ("utc", CurrentUserTrackingCookie), ("keyword", keyword));
164228
}
165229

230+
/// <summary>
231+
/// Sends a scoll in categories event to Gfycat analytics
232+
/// </summary>
233+
/// <param name="count"></param>
234+
/// <param name="options"></param>
235+
/// <returns></returns>
166236
public async Task SendScrollInCategoriesEventAsync(int count, RequestOptions options = null)
167237
{
168238
await SendAnalyticsInternalAsync(AnalyticsEvent.ScrollInCategories, options, ("utc", CurrentUserTrackingCookie), ("count", count));
169239
}
170240

241+
/// <summary>
242+
/// Sends a scroll in videos event to Gfycat analytics
243+
/// </summary>
244+
/// <param name="count"></param>
245+
/// <param name="context"></param>
246+
/// <param name="keyword"></param>
247+
/// <param name="options"></param>
248+
/// <returns></returns>
171249
public async Task SendScrollInVideosEventAsync(int count, ImpressionContext context = ImpressionContext.None, string keyword = null, RequestOptions options = null)
172250
{
173251
await SendAnalyticsInternalAsync(AnalyticsEvent.ScrollInVideos, options, ("utc", CurrentUserTrackingCookie), ("count", count), ("context", (context == ImpressionContext.None ? null : context.ToString())), ("keyword", keyword));
174252
}
175253

254+
/// <summary>
255+
/// Sends a video caption event to Gfycat analytics
256+
/// </summary>
257+
/// <param name="captionText"></param>
258+
/// <param name="options"></param>
259+
/// <returns></returns>
176260
public async Task SendCaptionVideoEventAsync(string captionText, RequestOptions options = null)
177261
{
178262
if (captionText == null)
@@ -181,6 +265,12 @@ public async Task SendCaptionVideoEventAsync(string captionText, RequestOptions
181265
await SendAnalyticsInternalAsync(AnalyticsEvent.CaptionVideos, options, ("utc", CurrentUserTrackingCookie), ("text", captionText));
182266
}
183267

268+
/// <summary>
269+
/// Sends a copy link event to Gfycat analytics
270+
/// </summary>
271+
/// <param name="gfy"></param>
272+
/// <param name="options"></param>
273+
/// <returns></returns>
184274
public async Task SendCopyLinkEventAsync(Gfy gfy, RequestOptions options = null)
185275
{
186276
if (gfy == null)
@@ -189,6 +279,12 @@ public async Task SendCopyLinkEventAsync(Gfy gfy, RequestOptions options = null)
189279
await SendAnalyticsInternalAsync(AnalyticsEvent.CopyLink, options, ("utc", CurrentUserTrackingCookie), ("gfyid", gfy.Id));
190280
}
191281

282+
/// <summary>
283+
/// Sends a download video event to Gfycat analytics
284+
/// </summary>
285+
/// <param name="gfy"></param>
286+
/// <param name="options"></param>
287+
/// <returns></returns>
192288
public async Task SendDownloadVideoEventAsync(Gfy gfy, RequestOptions options = null)
193289
{
194290
if (gfy == null)
@@ -197,6 +293,12 @@ public async Task SendDownloadVideoEventAsync(Gfy gfy, RequestOptions options =
197293
await SendAnalyticsInternalAsync(AnalyticsEvent.DownloadVideo, options, ("utc", CurrentUserTrackingCookie), ("gfyid", gfy.Id));
198294
}
199295

296+
/// <summary>
297+
/// Sends a bookmark video event to Gfycat analytics
298+
/// </summary>
299+
/// <param name="gfy"></param>
300+
/// <param name="options"></param>
301+
/// <returns></returns>
200302
public async Task SendBookmarkVideoEventAsync(Gfy gfy, RequestOptions options = null)
201303
{
202304
if (gfy == null)

src/Gfycat.Net.Analytics/GfycatAnalyticsClientConfig.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,35 @@
44

55
namespace Gfycat.Analytics
66
{
7+
/// <summary>
8+
/// Represents a configuration for a <see cref="GfycatAnalyticsClient"/>
9+
/// </summary>
710
public class GfycatAnalyticsClientConfig
811
{
12+
/// <summary>
13+
/// Gets the base impressions url
14+
/// </summary>
915
public const string BaseImpressionsUrl = "https://px.gfycat.com/px.gif";
16+
/// <summary>
17+
/// Gets the base analytics url
18+
/// </summary>
1019
public const string BaseAnalyticsUrl = "https://metrics.gfycat.com";
1120

21+
/// <summary>
22+
/// Gets the app Id for this config
23+
/// </summary>
1224
public string AppId { get; }
25+
/// <summary>
26+
/// Gets the app name for this config
27+
/// </summary>
1328
public string AppName { get; }
29+
/// <summary>
30+
/// Gets the app version for this config
31+
/// </summary>
1432
public Version AppVersion { get; }
33+
/// <summary>
34+
/// Gets the session Id for this config
35+
/// </summary>
1536
public string SessionId { get; }
1637

1738
/// <summary>
@@ -29,8 +50,21 @@ public class GfycatAnalyticsClientConfig
2950
/// </summary>
3051
public int DefaultTimeout { get; set; } = -1;
3152

53+
/// <summary>
54+
/// Creates a new config using the specified app name, id, and version
55+
/// </summary>
56+
/// <param name="appName"></param>
57+
/// <param name="appId"></param>
58+
/// <param name="appVersion"></param>
3259
public GfycatAnalyticsClientConfig(string appName, string appId, Version appVersion) : this(appName, appId, appVersion, GenerateCookie()) { }
3360

61+
/// <summary>
62+
/// Creates a new config using the specified app name, id, version, and session Id
63+
/// </summary>
64+
/// <param name="appName"></param>
65+
/// <param name="appId"></param>
66+
/// <param name="appVersion"></param>
67+
/// <param name="sessionId"></param>
3468
public GfycatAnalyticsClientConfig(string appName, string appId, Version appVersion, string sessionId)
3569
{
3670
AppId = appId;
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
namespace Gfycat.Analytics
22
{
3+
/// <summary>
4+
/// Represents an gfy impression
5+
/// </summary>
36
public class Impression
47
{
5-
public string AppId { get; set; }
6-
public string Version { get; set; }
7-
public string UserTrackingCookie { get; set; }
8-
public string SessionTrackingCookie { get; set; }
9-
public string GfycatId { get; set; }
10-
public string Context { get; set; }
8+
/// <summary>
9+
/// Sets the gfy this impression is for
10+
/// </summary>
11+
public Gfy Gfycat { get; set; }
12+
/// <summary>
13+
/// Sets the context of this impression
14+
/// </summary>
15+
public ImpressionContext Context { get; set; }
16+
/// <summary>
17+
/// Sets the keyword of this impression
18+
/// </summary>
1119
public string Keyword { get; set; }
12-
public string Flow { get; set; }
20+
/// <summary>
21+
/// Sets the flow of this impression
22+
/// </summary>
23+
public ImpressionFlow Flow { get; set; }
24+
/// <summary>
25+
/// Sets the view tag of this impression
26+
/// </summary>
1327
public string ViewTag { get; set; }
1428
}
1529
}

src/Gfycat.Net.Analytics/ImpressionContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace Gfycat.Analytics
1+
#pragma warning disable CS1591
2+
namespace Gfycat.Analytics
23
{
34
public enum ImpressionContext
45
{

src/Gfycat.Net.Analytics/ImpressionFlow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace Gfycat.Analytics
1+
#pragma warning disable CS1591
2+
namespace Gfycat.Analytics
23
{
34
public enum ImpressionFlow
45
{

0 commit comments

Comments
 (0)