@@ -8,8 +8,17 @@ class FortniteAPI
8
8
ShopItem = Struct . new ( :regularPrice , :finalPrice , :isBundle , :giftable , :refundable , :panel , :sortPriority , :banner , :items )
9
9
CreatorCode = Struct . new ( :id , :slug , :displayName , :status , :verified )
10
10
11
+ def initialize ( apikey = nil )
12
+ @apikey = apikey
13
+ @headers = { "x-api-key" => @apikey }
14
+
15
+ if apikey == nil
16
+ puts 'Warning: Next monday (Dec. 9th) at 8 PM (UTC) every endpoint will require an API-Key, you can get one at: fortnite-api.com.'
17
+ end
18
+ end
19
+
11
20
def search_cosmetic ( searchQuery , tag = 'name' , language = 'en' , searchLanguage = 'en' )
12
- response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br/search?#{ tag } =#{ searchQuery } &language=#{ language } &searchLanguage=#{ searchLanguage } " )
21
+ response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br/search?#{ tag } =#{ searchQuery } &language=#{ language } &searchLanguage=#{ searchLanguage } " , :headers => @headers )
13
22
body = JSON . parse ( response . body ) [ 'data' ]
14
23
if response . code == 200
15
24
searchResult = BRCosmetic . new ( body [ 'id' ] , body [ 'type' ] , body [ 'backendType' ] , body [ 'rarity' ] , body [ 'displayRarity' ] , body [ 'backendRarity' ] , body [ 'name' ] , body [ 'shortDescription' ] , body [ 'description' ] , body [ 'set' ] , body [ 'setText' ] , body [ 'backendSeries' ] , body [ 'images' ] , body [ 'variants' ] , body [ 'gameplayTags' ] , body [ 'displayAssetPath' ] , body [ 'definition' ] , body [ 'requiredItemId' ] , body [ 'builtInEmoteId' ] , body [ 'path' ] , body [ 'lastUpdate' ] , body [ 'added' ] )
@@ -30,12 +39,14 @@ def search_cosmetic(searchQuery, tag='name', language='en', searchLanguage='en')
30
39
end
31
40
32
41
def get_creator_code ( slug )
33
- repsonse = HTTParty . get ( "https://fortnite-api.com/creatorcode/search?slug=#{ slug } " )
42
+ response = HTTParty . get ( "https://fortnite-api.com/creatorcode/search?slug=#{ slug } " , :headers => @headers )
34
43
body = JSON . parse ( response . body ) [ 'data' ]
35
44
supportACreator = CreatorCode . new ( body [ 'id' ] , body [ 'slug' ] , body [ 'displayName' ] , body [ 'status' ] , body [ 'verified' ] )
45
+ supportACreator
46
+ end
36
47
37
48
def search_cosmetic_id ( searchQuery , language = 'en' )
38
- response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br/#{ searchQuery } &language=#{ language } " )
49
+ response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br/#{ searchQuery } &language=#{ language } " , :headers => @headers )
39
50
body = JSON . parse ( response . body ) [ 'data' ]
40
51
if response . code == 200
41
52
searchResult = BRCosmetic . new ( body [ 'id' ] , body [ 'type' ] , body [ 'backendType' ] , body [ 'rarity' ] , body [ 'displayRarity' ] , body [ 'backendRarity' ] , body [ 'name' ] , body [ 'shortDescription' ] , body [ 'description' ] , body [ 'set' ] , body [ 'setText' ] , body [ 'backendSeries' ] , body [ 'images' ] , body [ 'variants' ] , body [ 'gameplayTags' ] , body [ 'displayAssetPath' ] , body [ 'definition' ] , body [ 'requiredItemId' ] , body [ 'builtInEmoteId' ] , body [ 'path' ] , body [ 'lastUpdate' ] , body [ 'added' ] )
@@ -57,7 +68,7 @@ def search_cosmetic_id(searchQuery, language='en')
57
68
58
69
def search_cosmetics ( searchQuery , tag = 'name' , language = 'en' , searchLanguage = 'en' )
59
70
cosmetics = [ ]
60
- response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br/search/all?#{ tag } =#{ searchQuery } &language=#{ language } &searchLanguage=#{ searchLanguage } " )
71
+ response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br/search/all?#{ tag } =#{ searchQuery } &language=#{ language } &searchLanguage=#{ searchLanguage } " , :headers => @headers )
61
72
body = JSON . parse ( response . body ) [ 'data' ]
62
73
if response . code == 200
63
74
for x in body
@@ -81,13 +92,13 @@ def search_cosmetics(searchQuery, tag='name', language='en', searchLanguage='en'
81
92
end
82
93
83
94
def all_cosmetics ( )
84
- response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br" )
95
+ response = HTTParty . get ( "https://fortnite-api.com/cosmetics/br" , :headers => @headers )
85
96
JSON . parse ( response . body )
86
97
end
87
98
88
99
def get_br_news ( language = 'en' )
89
100
br_news_list = [ ]
90
- response = HTTParty . get ( "https://fortnite-api.com/news/br?language=#{ language } " )
101
+ response = HTTParty . get ( "https://fortnite-api.com/news/br?language=#{ language } " , :headers => @headers )
91
102
messages = JSON . parse ( response . body ) [ 'data' ] [ 'messages' ]
92
103
for x in messages
93
104
newsResult = BRNews . new ( x [ 'image' ] , x [ 'hidden' ] , x [ 'messageType' ] , x [ 'type' ] , x [ 'adspace' ] , x [ 'spotlight' ] , x [ 'title' ] , x [ 'body' ] )
@@ -98,7 +109,7 @@ def get_br_news(language='en')
98
109
99
110
def get_stw_news ( language = 'en' )
100
111
stw_news_list = [ ]
101
- response = HTTParty . get ( "https://fortnite-api.com/news/stw?language=#{ language } " )
112
+ response = HTTParty . get ( "https://fortnite-api.com/news/stw?language=#{ language } " , :headers => @headers )
102
113
messages = JSON . parse ( response . body ) [ 'data' ] [ 'messages' ]
103
114
for x in messages
104
115
newsResult = STWNews . new ( x [ 'image' ] , x [ 'hidden' ] , x [ 'messageType' ] , x [ 'type' ] , x [ 'adspace' ] , x [ 'spotlight' ] , x [ 'title' ] , x [ 'body' ] )
@@ -109,7 +120,7 @@ def get_stw_news(language='en')
109
120
110
121
def get_creative_news ( language = 'en' )
111
122
creative_news_list = [ ]
112
- response = HTTParty . get ( "https://fortnite-api.com/news/creative?language=#{ language } " )
123
+ response = HTTParty . get ( "https://fortnite-api.com/news/creative?language=#{ language } " , :headers => @headers )
113
124
messages = JSON . parse ( response . body ) [ 'data' ] [ 'messages' ]
114
125
for x in messages
115
126
newsResult = CreativeNews . new ( x [ 'image' ] , x [ 'hidden' ] , x [ 'messageType' ] , x [ 'type' ] , x [ 'adspace' ] , x [ 'spotlight' ] , x [ 'title' ] , x [ 'body' ] )
@@ -121,7 +132,7 @@ def get_creative_news(language='en')
121
132
def get_br_store ( language = 'en' )
122
133
featured_items = [ ]
123
134
daily_items = [ ]
124
- response = HTTParty . get ( "https://fortnite-api.com/shop/br?language=#{ language } " )
135
+ response = HTTParty . get ( "https://fortnite-api.com/shop/br?language=#{ language } " , :headers => @headers )
125
136
featured = JSON . parse ( response . body ) [ 'data' ] [ 'featured' ]
126
137
for x in featured
127
138
featuredItem = ShopItem . new ( x [ 'regularPrice' ] , x [ 'finalPrice' ] , x [ 'isBundle' ] , x [ 'giftable' ] , x [ 'refundable' ] , x [ 'panel' ] , x [ 'sortPriority' ] , x [ 'banner' ] , x [ 'items' ] )
@@ -131,7 +142,7 @@ def get_br_store(language='en')
131
142
for x in daily
132
143
dailyItem = ShopItem . new ( x [ 'regularPrice' ] , x [ 'finalPrice' ] , x [ 'isBundle' ] , x [ 'giftable' ] , x [ 'refundable' ] , x [ 'panel' ] , x [ 'sortPriority' ] , x [ 'banner' ] , x [ 'items' ] )
133
144
daily_items . push ( dailyItem )
134
- end
145
+ end
135
146
br_store = [ featured_items , daily_items ]
136
147
br_store
137
148
end
0 commit comments