-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
126 lines (96 loc) · 3.92 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using MuntersGIPHY;
using MuntersGIPHY.Requests;
using Newtonsoft.Json;
namespace MuntersGIPHY
{
class Program
{
//this in the future will be a web application so the main oage will change
// it can be also a win form application
//it beeing written in a consol application due to time frames
static async Task Main(string[] args)
{
var _cache = new CacheGiphy();
var apiKey = "Et1mg38eAxAup2oJU61RT7Tvilu0v1Me";
Console.WriteLine("Please type Trending If you Would Like to See ALl the url Trending");
var line = Console.ReadLine().ToLower();
ServiceTypeEnum typeService = (ServiceTypeEnum) 0;
switch (line)
{
case "1":
typeService = ServiceTypeEnum.Trending;
break;
case "2":
Console.WriteLine("Search");
typeService = ServiceTypeEnum.Search;
break;
default:
System.Environment.Exit(1);
break;
}
var gimphyService = new GimphyService();
if (typeService == ServiceTypeEnum.Trending)
{
var trendingResualts =await gimphyService.GetTrending(new GetTrendingRequest() { ApiKey = apiKey });
foreach (var item in trendingResualts.Urls)
{
Console.WriteLine(item);
}
Console.WriteLine("click 0 to go to main menu");
var userChoose1 = Console.ReadLine();
if (userChoose1 == "0")
{
Console.Clear();
await Main(args);
}
else
{
System.Environment.Exit(1);
}
}
if (typeService == ServiceTypeEnum.Search)
{
await Search(gimphyService, apiKey, _cache);
Console.WriteLine("For another Search Type 1 go back to main Page type 0 ");
var userChoose = Console.ReadLine();
if (userChoose == "1")
{
await Search(gimphyService, apiKey, _cache);
}
else
{
Console.Clear();
await Main(args);
}
}
}
private static async Task Search(GimphyService gimphyService, string apiKey, CacheGiphy _cache)
{
Console.WriteLine("Please Type you Desire Search Word ");
var wordToSearch = Console.ReadLine();
//TODO need to finish cache implimitation with DB
//wordToSearch = _cache.GetOrCreate(wordToSearch);
var trendingResualts = await gimphyService.GimphySerach(new GetSearchRequest() {ApiKey = apiKey,SearchWord = wordToSearch });
foreach (var item in trendingResualts.Items)
{
using (StreamWriter writetext =
new StreamWriter(
"C:\\searchresults.html",
true))
{
writetext.WriteLine($"<h1><a href='{ item.bitly_gif_url}'>{item.title}</a></h1>");
}
}
Console.WriteLine("Location of the file is here C:\\searchresults.html");
}
}
}