fortniteapi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4de573efd34f764f42f3951df15929b7ffe392eb8340ac50e619416f1e876224
4
+ data.tar.gz: '087a5598fa707ed1968b31187456453fe63e898d4c611d2fb498672cd88c8b93'
5
+ SHA512:
6
+ metadata.gz: 480f0ea76b06f2e2dbe23fc1b9961761154739f38337a41932f487700d6d7905d64d93ada459f883054ad22eeb5ba3a3b75addf6f6348ad5c3f4cda6a815a30b
7
+ data.tar.gz: b7a9b9621115b49089b6566627b93230a6256a809db03dec603cb1de8728953c886a25688873b2d40913452543ec587d21dd61128c6b6415711096a2b8cc157b
@@ -0,0 +1 @@
1
+ require_relative 'fortniteapi/api.rb'
@@ -0,0 +1,132 @@
1
+ require 'httparty'
2
+
3
+ class FortniteAPI
4
+ BRCosmetic = Struct.new(:id, :type, :backendType, :rarity, :displayRarity, :backendRarity, :name, :shortDescription, :description, :set, :setText, :backendSeries, :images, :variants, :gameplayTags, :displayAssetPath, :definition, :requiredItemId, :builtInEmoteId, :path, :lastUpdate, :added)
5
+ BRNews = Struct.new(:image, :hidden, :messageType, :type, :adspace, :spotlight, :title, :body)
6
+ STWNews = Struct.new(:image, :hidden, :messageType, :type, :adspace, :spotlight, :title, :body)
7
+ CreativeNews = Struct.new(:image, :hidden, :messageType, :type, :adspace, :spotlight, :title, :body)
8
+ ShopItem = Struct.new(:regularPrice, :finalPrice, :isBundle, :giftable, :refundable, :panel, :sortPriority, :banner, :items)
9
+
10
+ def search_cosmetic(searchQuery, tag='name', language='en', searchLanguage='en')
11
+ response = HTTParty.get("https://fortnite-api.com/cosmetics/br/search?#{tag}=#{searchQuery}&language=#{language}&searchLanguage=#{searchLanguage}")
12
+ body = JSON.parse(response.body)['data']
13
+ if response.code == 200
14
+ 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'])
15
+ searchResult
16
+ elsif response.code == 404
17
+ raise "Error when trying to fetch cosmetic: #{searchQuery} - #{body['error']}"
18
+ searchResult = BRCosmetic.new()
19
+ searchResult
20
+ elsif response.code == 400
21
+ raise "Error when using parameter, it might be that it is invalid.: #{tag} - #{body['error']}"
22
+ searchResult = BRCosmetic.new()
23
+ searchResult
24
+ else
25
+ raise "An unexpected error occured. Status code: #{response.code}, Request body: #{response.body}"
26
+ searchResult = BRCosmetic.new()
27
+ searchResult
28
+ end
29
+ end
30
+
31
+ def search_cosmetic_id(searchQuery, language='en')
32
+ response = HTTParty.get("https://fortnite-api.com/cosmetics/br/#{searchQuery}&language=#{language}")
33
+ body = JSON.parse(response.body)['data']
34
+ if response.code == 200
35
+ 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'])
36
+ searchResult
37
+ elsif response.code == 404
38
+ raise "Error when trying to fetch cosmetic: #{searchQuery} - #{body['error']}"
39
+ searchResult = BRCosmetic.new()
40
+ searchResult
41
+ elsif response.code == 400
42
+ raise "Error when using parameter, it might be that it is invalid.: #{tag} - #{body['error']}"
43
+ searchResult = BRCosmetic.new()
44
+ searchResult
45
+ else
46
+ raise "An unexpected error occured. Status code: #{response.code}, Request body: #{response.body}"
47
+ searchResult = BRCosmetic.new()
48
+ searchResult
49
+ end
50
+ end
51
+
52
+ def search_cosmetics(searchQuery, tag='name', language='en', searchLanguage='en')
53
+ cosmetics = []
54
+ response = HTTParty.get("https://fortnite-api.com/cosmetics/br/search/all?#{tag}=#{searchQuery}&language=#{language}&searchLanguage=#{searchLanguage}")
55
+ body = JSON.parse(response.body)['data']
56
+ if response.code == 200
57
+ for x in body
58
+ searchResult = BRCosmetic.new(x['id'], x['type'], x['backendType'], x['rarity'], x['displayRarity'], x['backendRarity'], x['name'], x['shortDescription'], x['description'], x['set'], x['setText'], x['backendSeries'], x['images'], x['variants'], x['gameplayTags'], x['displayAssetPath'], x['definition'], x['requiredItemId'], x['builtInEmoteId'], x['path'], x['lastUpdate'], x['added'])
59
+ cosmetics.push(searchResult)
60
+ end
61
+ cosmetics
62
+ elsif response.code == 404
63
+ raise "Error when trying to fetch cosmetic: #{searchQuery} - #{body['error']}"
64
+ searchResult = BRCosmetic.new()
65
+ searchResult
66
+ elsif response.code == 400
67
+ raise "Error when using parameter, it might be that it is invalid.: #{tag} - #{body['error']}"
68
+ searchResult = BRCosmetic.new()
69
+ searchResult
70
+ else
71
+ raise "An unexpected error occured. Status code: #{response.code}, Request body: #{response.body}"
72
+ searchResult = BRCosmetic.new()
73
+ searchResult
74
+ end
75
+ end
76
+
77
+ def all_cosmetics()
78
+ response = HTTParty.get("https://fortnite-api.com/cosmetics/br")
79
+ JSON.parse(response.body)
80
+ end
81
+
82
+ def get_br_news(language='en')
83
+ br_news_list = []
84
+ response = HTTParty.get("https://fortnite-api.com/news/br?language=#{language}")
85
+ messages = JSON.parse(response.body)['data']['messages']
86
+ for x in messages
87
+ newsResult = BRNews.new(x['image'], x['hidden'], x['messageType'], x['type'], x['adspace'], x['spotlight'], x['title'], x['body'])
88
+ br_news_list.push(newsResult)
89
+ end
90
+ br_news_list
91
+ end
92
+
93
+ def get_stw_news(language='en')
94
+ stw_news_list = []
95
+ response = HTTParty.get("https://fortnite-api.com/news/stw?language=#{language}")
96
+ messages = JSON.parse(response.body)['data']['messages']
97
+ for x in messages
98
+ newsResult = STWNews.new(x['image'], x['hidden'], x['messageType'], x['type'], x['adspace'], x['spotlight'], x['title'], x['body'])
99
+ stw_news_list.push(newsResult)
100
+ end
101
+ stw_news_list
102
+ end
103
+
104
+ def get_creative_news(language='en')
105
+ creative_news_list = []
106
+ response = HTTParty.get("https://fortnite-api.com/news/creative?language=#{language}")
107
+ messages = JSON.parse(response.body)['data']['messages']
108
+ for x in messages
109
+ newsResult = CreativeNews.new(x['image'], x['hidden'], x['messageType'], x['type'], x['adspace'], x['spotlight'], x['title'], x['body'])
110
+ creative_news_list.push(newsResult)
111
+ end
112
+ creative_news_list
113
+ end
114
+
115
+ def get_br_store(language='en')
116
+ featured_items = []
117
+ daily_items = []
118
+ response = HTTParty.get("https://fortnite-api.com/shop/br?language=#{language}")
119
+ featured = JSON.parse(response.body)['data']['featured']
120
+ for x in featured
121
+ featuredItem = ShopItem.new(x['regularPrice'], x['finalPrice'], x['isBundle'], x['giftable'], x['refundable'], x['panel'], x['sortPriority'], x['banner'], x['items'])
122
+ featured_items.push(featuredItem)
123
+ end
124
+ daily = JSON.parse(response.body)['data']['daily']
125
+ for x in daily
126
+ dailyItem = ShopItem.new(x['regularPrice'], x['finalPrice'], x['isBundle'], x['giftable'], x['refundable'], x['panel'], x['sortPriority'], x['banner'], x['items'])
127
+ daily_items.push(dailyItem)
128
+ end
129
+ br_store = [featured_items, daily_items]
130
+ br_store
131
+ end
132
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fortniteapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - xMistt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.17.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.17.1
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/fortniteapi.rb
34
+ - lib/fortniteapi/api.rb
35
+ homepage: https://github.com/Fortnite-API/ruby-wrapper
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.0.6
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Ruby implementation for https://fortnite-api.com
57
+ test_files: []