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

Commit 06f7941

Browse files
committed
Added support for x-api-key.
1 parent c80df04 commit 06f7941

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To install this gem, simply type into your terminal:
1616
```ruby
1717
require 'fortniteapi'
1818

19-
fortnite_api = FortniteAPI.new()
19+
fortnite_api = FortniteAPI.new(apikey=X-API-KEY-HERE)
2020
cosmetics = fortnite_api.search_cosmetic('Renegade')
2121
puts cosmetics.id
2222
=> cid_013_athena_commando_f

fortniteapi-1.0.0.gem

5.5 KB
Binary file not shown.

fortniteapi.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
33

44
Gem::Specification.new do |spec|
55
spec.name = 'fortniteapi'
6-
spec.version = '0.0.2'
6+
spec.version = '1.0.0'
77
spec.authors = ['xMistt']
88
spec.summary = 'Ruby implementation for https://fortnite-api.com'
99
spec.homepage = 'https://github.com/Fortnite-API/ruby-wrapper'

lib/fortniteapi/api.rb

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ class FortniteAPI
88
ShopItem = Struct.new(:regularPrice, :finalPrice, :isBundle, :giftable, :refundable, :panel, :sortPriority, :banner, :items)
99
CreatorCode = Struct.new(:id, :slug, :displayName, :status, :verified)
1010

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+
1120
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)
1322
body = JSON.parse(response.body)['data']
1423
if response.code == 200
1524
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')
3039
end
3140

3241
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)
3443
body = JSON.parse(response.body)['data']
3544
supportACreator = CreatorCode.new(body['id'], body['slug'], body['displayName'], body['status'], body['verified'])
45+
supportACreator
46+
end
3647

3748
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)
3950
body = JSON.parse(response.body)['data']
4051
if response.code == 200
4152
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')
5768

5869
def search_cosmetics(searchQuery, tag='name', language='en', searchLanguage='en')
5970
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)
6172
body = JSON.parse(response.body)['data']
6273
if response.code == 200
6374
for x in body
@@ -81,13 +92,13 @@ def search_cosmetics(searchQuery, tag='name', language='en', searchLanguage='en'
8192
end
8293

8394
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)
8596
JSON.parse(response.body)
8697
end
8798

8899
def get_br_news(language='en')
89100
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)
91102
messages = JSON.parse(response.body)['data']['messages']
92103
for x in messages
93104
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')
98109

99110
def get_stw_news(language='en')
100111
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)
102113
messages = JSON.parse(response.body)['data']['messages']
103114
for x in messages
104115
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')
109120

110121
def get_creative_news(language='en')
111122
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)
113124
messages = JSON.parse(response.body)['data']['messages']
114125
for x in messages
115126
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')
121132
def get_br_store(language='en')
122133
featured_items = []
123134
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)
125136
featured = JSON.parse(response.body)['data']['featured']
126137
for x in featured
127138
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')
131142
for x in daily
132143
dailyItem = ShopItem.new(x['regularPrice'], x['finalPrice'], x['isBundle'], x['giftable'], x['refundable'], x['panel'], x['sortPriority'], x['banner'], x['items'])
133144
daily_items.push(dailyItem)
134-
end
145+
end
135146
br_store = [featured_items, daily_items]
136147
br_store
137148
end

0 commit comments

Comments
 (0)