55using System . Net ;
66using System . Linq ;
77
8+ [ assembly: CLSCompliant ( true ) ]
9+
810namespace 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 )
0 commit comments