-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiOrigins.go
402 lines (275 loc) ยท 18.6 KB
/
apiOrigins.go
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
package emojis
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"strconv"
"strings"
)
// Function to return all emojis categories inside a ListOfCategories object...
func GetAllCategories(accessKey string) ListOfCategories {
// Declaration of the 'categoriesInterface' interface...
var categoriesInterface []interface{}
// Declaration of the 'allCategoriesMap' map[string]Category...
var allCategoriesMap map[string]Category
// Declaration of the 'allCategories' list of categories...
var allCategories ListOfCategories
// Declaration of the 'categoriesInterfaceLen' variable which contains the length of the 'categoriesInterface' interface...
var categoriesInterfaceLen int
// Declaration of the 'currentCategory' Category...
var currentCategory Category
// Declaration of the 'subCategoriesArray' []string (array of strings)...
var subCategoriesArray []string
// Definition of the HTTPS request's URL to get all emojis categories from the Open Emoji API...
getEmojisCategoriesFromTheOpenEmojiAPIRequest := "https://emoji-api.com/categories?access_key=" + accessKey
// Execution of the Get HTTPS request to get all emojis categories from the Open Emoji API...
getEmojisCategoriesFromTheOpenEmojiAPIResp, err := http.Get(getEmojisCategoriesFromTheOpenEmojiAPIRequest)
// Manage the possible occured error...
errorHandlerFunction(err)
// Read the HTTP response's body in the 'getEmojisCategoriesFromTheOpenEmojiAPIJsonString' string variable...
getEmojisCategoriesFromTheOpenEmojiAPIJsonString, err := ioutil.ReadAll(getEmojisCategoriesFromTheOpenEmojiAPIResp.Body)
// Manage the possible occured error...
errorHandlerFunction(err)
// Unmarshall all of received datas of all received emojis categories in the 'categoriesInterface' interface...
err = json.Unmarshal(getEmojisCategoriesFromTheOpenEmojiAPIJsonString, &categoriesInterface)
// Manage the possible occured error...
errorHandlerFunction(err)
// Initialization of the 'categoriesInterfaceLen' variable with the 'emojisInterface' interface length...
categoriesInterfaceLen = len(categoriesInterface)
// Allocation of all necessary memory for the 'allCategoriesMap' map[string]Category...
allCategoriesMap = make(map[string]Category)
// Initialization of the main loop of this function...
for i := 0; i < categoriesInterfaceLen; i++ {
// Conversion of the current element of the 'categoriesInterface' interface to a map[string]interface{}...
currentCategoryAsMap := categoriesInterface[i].(map[string]interface{})
// Conversion of the 'subCategories' field of the currentCategoryAsMap map[string]interface{} into an array...
subCategoriesArray = reflectValueToStringArrayFunction(reflect.ValueOf(currentCategoryAsMap["subCategories"]))
// Initialization of the 'currentCategory' category with the corresponding collected datas...
currentCategory.InitializeCategory(fmt.Sprintf("%v", currentCategoryAsMap["slug"]), subCategoriesArray)
// Adding the 'currentCategory' category in the 'allCategoriesMap' map[string]Category...
allCategoriesMap[fmt.Sprintf("%v", currentCategoryAsMap["slug"])] = currentCategory
}
// Initialization of the 'allCategories' ListOfCategories to make it contain all existing emojis categories...
allCategories.InitializeListOfCategories(allCategoriesMap)
// Returning the completed 'allCategories' ListOfCategories which now contains all existing emojis categories...
return allCategories
}
// Function to return the emoji calculated from the 'codePointOfEmoji' codePoint...
func GetEmojiFromCodePoint(codePointOfEmoji string) string {
// Calculating and returning the emoji from the 'codePointOfEmoji' codePoint...
resultAsRune, error := strconv.ParseInt(strings.TrimPrefix(codePointOfEmoji, "\\U"), 16, 32)
// Manage the possible occured error...
errorHandlerFunction(error)
// Returning finally the emoticon with some necessary operations...
return string(rune(resultAsRune))
}
// Function to return all emojis by taken your personal 'accessKey' of the Open Emoji API as argument...
func GetAllEmojis(accessKey string) ListOfEmojis {
// Declaration of the 'emojiSInterface' interface...
var emojisInterface []interface{}
// Declaration of the 'allEmojisMap' map[string]Emoji...
var allEmojisMap map[string]Emoji
// Declaration of the 'allEmojis' list of emojis...
var allEmojis ListOfEmojis
// Declaration of the 'emojisInterfaceLen' variable which contains the length of the 'emojisInterface' interface...
var emojisInterfaceLen int
// Declaration of the 'currentEmoji' emoji...
var currentEmoji Emoji
// Definition of the HTTPS request's URL to get all emojis from the Open Emoji API...
getEmojiFromTheOpenEmojiAPIRequest := "https://emoji-api.com/emojis?access_key=" + accessKey
// Execution of the Get HTTPS request to get all existing emojis from the Open Emoji API...
getEmojiFromTheOpenEmojiAPIResp, err := http.Get(getEmojiFromTheOpenEmojiAPIRequest)
// Manage the possible occured error...
errorHandlerFunction(err)
// Read the HTTP response's body in the 'getEmojiFromTheOpenEmojiAPIJsonString' string variable...
getEmojiFromTheOpenEmojiAPIJsonString, err := ioutil.ReadAll(getEmojiFromTheOpenEmojiAPIResp.Body)
// Manage the possible occured error...
errorHandlerFunction(err)
// Unmarshall all of received datas of all received emojis in the 'emojisInterface' interface...
err = json.Unmarshal(getEmojiFromTheOpenEmojiAPIJsonString, &emojisInterface)
// Manage the possible occured error...
errorHandlerFunction(err)
// Initialization of the 'emojisInterfaceLen' variable with the 'emojisInterface' interface length...
emojisInterfaceLen = len(emojisInterface)
// Allocation of all necessary memory for the 'allEmojisMap' map[string]Emoji...
allEmojisMap = make(map[string]Emoji)
// Initialization of the main loop of this function...
for i := 0; i < emojisInterfaceLen; i++ {
// Conversion of the 'emojisInterface' interface to a map[string]interface{}...
currentEmojiAsMap := emojisInterface[i].(map[string]interface{})
// Initialization of the 'currentEmoji' emoji with the corresponding collected datas...
currentEmoji.InitializeEmoji(fmt.Sprintf("%v", currentEmojiAsMap["slug"]), fmt.Sprintf("%v", currentEmojiAsMap["character"]), fmt.Sprintf("%v", currentEmojiAsMap["unicodeName"]), fmt.Sprintf("%v", currentEmojiAsMap["codePoint"]), fmt.Sprintf("%v", currentEmojiAsMap["group"]), fmt.Sprintf("%v", currentEmojiAsMap["subGroup"]))
// Adding the 'currentEmoji' emoji in the 'allEmojisMap' map[string]Emoji...
allEmojisMap[fmt.Sprintf("%v", currentEmojiAsMap["slug"])] = currentEmoji
}
// Initialization of the 'allEmojis' ListOfEmojis to make it contain all existing emojis...
allEmojis.InitializeListOfEmojis(allEmojisMap)
// Returning the completed 'allEmojisMap' ListOfEmojis which now contains all existing emojis...
return allEmojis
}
// Function to return the emoji specified by its slug by taken the 'unicodeName' of the wished emoji and your personal 'accessKey' of the Open Emoji API as arguments...
func GetASingleEmoji(slug string, accessKey string) Emoji {
// Declaration of the 'emojiSInterface' interface...
var emojiSInterface []interface{}
// Declaration of the 'emojiSMap' map[string]interface{}...
var emojiSMap map[string]interface{}
// Declaration of the 'returnedEmoji' emoji...
var returnedEmoji Emoji
// Definition of the HTTPS request's URL to get the wished emoji from the Open Emoji API...
getEmojiFromTheOpenEmojiAPIRequest := "https://emoji-api.com/emojis/" + slug + "?access_key=" + accessKey
// Execution of the Get HTTPS request to get the wished emoji from the Open Emoji API...
getEmojiFromTheOpenEmojiAPIResp, err := http.Get(getEmojiFromTheOpenEmojiAPIRequest)
// Manage the possible occured error...
errorHandlerFunction(err)
// Take the body of the previous Get HTTPS request's response in the 'getEmojiFromTheOpenEmojiAPIResp' variable...
getEmojiFromTheOpenEmojiAPIJsonString, err := ioutil.ReadAll(getEmojiFromTheOpenEmojiAPIResp.Body)
// Manage the possible occured error...
errorHandlerFunction(err)
// Unmarshall all of received datas in the 'emojiSInterface' interface...
err = json.Unmarshal(getEmojiFromTheOpenEmojiAPIJsonString, &emojiSInterface)
// Manage the possible occured error...
errorHandlerFunction(err)
// Conversion of the first element of the 'emojiSInterface' interface to a map[string]interface{}...
emojiSMap = emojiSInterface[0].(map[string]interface{})
// Initialization of the 'returnedEmoji' current emoji...
returnedEmoji.InitializeEmoji(fmt.Sprintf("%v", emojiSMap["slug"]), fmt.Sprintf("%v", emojiSMap["character"]), fmt.Sprintf("%v", emojiSMap["unicodeName"]), fmt.Sprintf("%v", emojiSMap["codePoint"]), fmt.Sprintf("%v", emojiSMap["group"]), fmt.Sprintf("%v", emojiSMap["subGroup"]))
// Returning the 'returnedEmoji' initialized emoji...
return returnedEmoji
}
// Function to return all emojis from a wished 'searchedFor' subGroup of emojis as a ListOfEmojis...
func GetSearchedForEmojis(searchedFor string, accessKey string) ListOfEmojis {
// Declaration of the 'searchedForEmojisInterface' interface...
var searchedForEmojisInterface []interface{}
// Declaration of the 'searchedForEmojisMap' map[string]Emoji...
var searchedForEmojisMap map[string]Emoji
// Declaration of the 'searchedForEmojis' list of emojis...
var searchedForEmojis ListOfEmojis
// Declaration of the 'searchedForEmojisInterfaceLen' variable which contains the length of the 'searchedForEmojisInterface' interface...
var searchedForEmojisInterfaceLen int
// Declaration of the 'currentEmoji' emoji...
var currentEmoji Emoji
// Definition of the HTTPS request's URL to get all interesting emojis from the Open Emoji API...
getSearchedForEmojisFromTheOpenEmojiAPIRequest := "https://emoji-api.com/emojis?search=" + searchedFor + "&access_key=" + accessKey
// Execution of the Get HTTPS request to get all interesting emojis from the Open Emoji API...
getSearchedForEmojisFromTheOpenEmojiAPIResp, err := http.Get(getSearchedForEmojisFromTheOpenEmojiAPIRequest)
// Manage the possible occured error...
errorHandlerFunction(err)
// Take the body of the previous Get HTTPS request's response in the 'getSearchedForEmojisFromTheOpenEmojiAPIResp' variable...
getSearchedForEmojisFromTheOpenEmojiAPIJsonString, err := ioutil.ReadAll(getSearchedForEmojisFromTheOpenEmojiAPIResp.Body)
// Manage the possible occured error...
errorHandlerFunction(err)
// Unmarshall all of received datas in the 'searchedForEmojisInterface' interface...
err = json.Unmarshal(getSearchedForEmojisFromTheOpenEmojiAPIJsonString, &searchedForEmojisInterface)
// Manage the possible occured error...
errorHandlerFunction(err)
// Initialization of the 'searchedForEmojisInterfaceLen' variable with the 'searchedForEmojisInterface' interface length...
searchedForEmojisInterfaceLen = len(searchedForEmojisInterface)
// Allocation of all necessary memory for the 'searchedForEmojisMap' map[string]Emoji...
searchedForEmojisMap = make(map[string]Emoji)
// Initialization of the main loop of this function...
for i := 0; i < searchedForEmojisInterfaceLen; i++ {
// Conversion of the 'searchedForEmojisInterface' interface to a map[string]interface{}...
currentEmojiAsMap := searchedForEmojisInterface[i].(map[string]interface{})
// Initialization of the 'currentEmoji' emoji with the corresponding collected datas...
currentEmoji.InitializeEmoji(fmt.Sprintf("%v", currentEmojiAsMap["slug"]), fmt.Sprintf("%v", currentEmojiAsMap["character"]), fmt.Sprintf("%v", currentEmojiAsMap["unicodeName"]), fmt.Sprintf("%v", currentEmojiAsMap["codePoint"]), fmt.Sprintf("%v", currentEmojiAsMap["group"]), fmt.Sprintf("%v", currentEmojiAsMap["subGroup"]))
// Adding the 'currentEmoji' Emoji in the 'searchedForEmojisMap' map[string]Emoji...
searchedForEmojisMap[fmt.Sprintf("%v", currentEmojiAsMap["slug"])] = currentEmoji
}
// Initialization of the 'searchedForEmojis' current ListOfEmojis...
searchedForEmojis.InitializeListOfEmojis(searchedForEmojisMap)
// Returning the completed 'searchedForEmojis' ListOfEmojis which now contains all interesting emojis...
return searchedForEmojis
}
// Function to return all emojis from a wished 'category' category of emojis as a ListOfEmojis...
func GetInCategoryEmojis(category string, accessKey string) ListOfEmojis {
// Declaration of the 'inCategoryEmojisInterface' interface...
var inCategoryEmojisInterface []interface{}
// Declaration of the 'inCategoryEmojisMap' map[string]Emoji...
var inCategoryEmojisMap map[string]Emoji
// Declaration of the 'inCategoryEmojis' list of emojis...
var inCategoryEmojis ListOfEmojis
// Declaration of the 'inCategoryEmojisInterfaceLen' variable which contains the length of the 'inCategoryEmojisInterface' interface...
var inCategoryEmojisInterfaceLen int
// Declaration of the 'currentEmoji' emoji...
var currentEmoji Emoji
// Definition of the HTTPS request's URL to get the wished emoji in the wished category from the Open Emoji API...
getEmojisFromCategoryFromTheOpenEmojiAPIRequest := "https://emoji-api.com/categories/" + category + "?access_key=" + accessKey
// Execution of the Get HTTPS request to get all existing emojis in the wished category from the Open Emoji API...
getEmojisFromCategoryFromTheOpenEmojiAPIResp, err := http.Get(getEmojisFromCategoryFromTheOpenEmojiAPIRequest)
// Manage the possible occured error...
errorHandlerFunction(err)
// Read the HTTP response's body in the 'getEmojisFromCategoryFromTheOpenEmojiAPIJsonString' string variable...
getEmojisFromCategoryFromTheOpenEmojiAPIJsonString, err := ioutil.ReadAll(getEmojisFromCategoryFromTheOpenEmojiAPIResp.Body)
// Manage the possible occured error...
errorHandlerFunction(err)
// Unmarshall all of received datas of all received emojis belonging to the wished category in the 'inCategoryEmojisInterface' interface...
err = json.Unmarshal(getEmojisFromCategoryFromTheOpenEmojiAPIJsonString, &inCategoryEmojisInterface)
// Manage the possible occured error...
errorHandlerFunction(err)
// Initialization of the 'inCategoryEmojisInterfaceLen' variable with the 'inCategoryEmojisInterface' interface length...
inCategoryEmojisInterfaceLen = len(inCategoryEmojisInterface)
// Allocation of all necessary memory for the 'inCategoryEmojisMap' map[string]Emoji...
inCategoryEmojisMap = make(map[string]Emoji)
// Initialization of the main loop of this function...
for i := 0; i < inCategoryEmojisInterfaceLen; i++ {
// Conversion of the 'inCategoryEmojisInterface' interface to a map[string]interface{}...
currentEmojiAsMap := inCategoryEmojisInterface[i].(map[string]interface{})
// Initialization of the 'currentEmoji' emoji with the corresponding collected datas...
currentEmoji.InitializeEmoji(fmt.Sprintf("%v", currentEmojiAsMap["slug"]), fmt.Sprintf("%v", currentEmojiAsMap["character"]), fmt.Sprintf("%v", currentEmojiAsMap["unicodeName"]), fmt.Sprintf("%v", currentEmojiAsMap["codePoint"]), fmt.Sprintf("%v", currentEmojiAsMap["group"]), fmt.Sprintf("%v", currentEmojiAsMap["subGroup"]))
// Adding the 'currentEmoji' emoji in the 'inCategoryEmojisMap' map[string]Emoji...
inCategoryEmojisMap[fmt.Sprintf("%v", currentEmojiAsMap["slug"])] = currentEmoji
}
// Initialization of the 'inCategoryEmojis' ListOfEmojis to make it contain all existing emojis belonging to the wished category...
inCategoryEmojis.InitializeListOfEmojis(inCategoryEmojisMap)
// Returning the completed 'inCategoryEmojis' ListOfEmojis which now contains all existing emojis in the wished category...
return inCategoryEmojis
}
// Defining the 'GetEmojisFromSubGroup' function to get and return all emojis from a wished 'subGroup' subgroup in a 'ListOfEmojis' variable...
func GetEmojisFromSubGroup(subGroup string, accessKey string) ListOfEmojis {
// Declaration of the 'emojiSInterface' interface...
var emojisInterface []interface{}
// Declaration of the 'fromSubGroupEmojisMap' map[string]Emoji...
var fromSubGroupEmojisMap map[string]Emoji
// Declaration of the 'inCategoryEmojis' list of emojis...
var fromSubGroupEmojis ListOfEmojis
// Declaration of the 'emojisInterfaceLen' variable which contains the length of the 'emojisInterface' interface...
var emojisInterfaceLen int
// Declaration of the 'currentEmoji' emoji...
var currentEmoji Emoji
// Definition of the HTTPS request's URL to get all emojis from the Open Emoji API...
getEmojiFromTheOpenEmojiAPIRequest := "https://emoji-api.com/emojis?access_key=" + accessKey
// Execution of the Get HTTPS request to get all existing emojis from the Open Emoji API...
getEmojiFromTheOpenEmojiAPIResp, err := http.Get(getEmojiFromTheOpenEmojiAPIRequest)
// Manage the possible occured error...
errorHandlerFunction(err)
// Read the HTTP response's body in the 'getEmojiFromTheOpenEmojiAPIJsonString' string variable...
getEmojiFromTheOpenEmojiAPIJsonString, err := ioutil.ReadAll(getEmojiFromTheOpenEmojiAPIResp.Body)
// Manage the possible occured error...
errorHandlerFunction(err)
// Unmarshall all of received datas of all received emojis in the 'emojisInterface' interface...
err = json.Unmarshal(getEmojiFromTheOpenEmojiAPIJsonString, &emojisInterface)
// Manage the possible occured error...
errorHandlerFunction(err)
// Initialization of the 'emojisInterfaceLen' variable with the 'emojisInterface' interface length...
emojisInterfaceLen = len(emojisInterface)
// Allocation of all necessary memory for the 'fromSubGroupEmojisMap' map[string]Emoji...
fromSubGroupEmojisMap = make(map[string]Emoji)
// Initialization of the main loop of this function...
for i := 0; i < emojisInterfaceLen; i++ {
// Conversion of the 'emojisInterface' interface to a map[string]interface{}...
currentEmojiAsMap := emojisInterface[i].(map[string]interface{})
// If the current emoji's sub group is equal to the wished 'subGroup' sub group so...
if fmt.Sprintf("%v", currentEmojiAsMap["subGroup"]) == subGroup {
// Initialization of the 'currentEmoji' emoji with the corresponding collected datas...
currentEmoji.InitializeEmoji(fmt.Sprintf("%v", currentEmojiAsMap["slug"]), fmt.Sprintf("%v", currentEmojiAsMap["character"]), fmt.Sprintf("%v", currentEmojiAsMap["unicodeName"]), fmt.Sprintf("%v", currentEmojiAsMap["codePoint"]), fmt.Sprintf("%v", currentEmojiAsMap["group"]), fmt.Sprintf("%v", currentEmojiAsMap["subGroup"]))
// Adding the 'currentEmoji' emoji in the 'fromSubGroupEmojisMap' map[string]Emoji...
fromSubGroupEmojisMap[fmt.Sprintf("%v", currentEmojiAsMap["slug"])] = currentEmoji
}
}
// Initialization of the 'fromSubGroupEmojis' ListOfEmojis to make it contain all emojis from the wished sub group...
fromSubGroupEmojis.InitializeListOfEmojis(fromSubGroupEmojisMap)
// Returning the completed 'fromSubGroupEmojis' ListOfEmojis which now contains all emojis from the wished sub group...
return fromSubGroupEmojis
}