Skip to content

Commit d91334d

Browse files
committed
Add remaining endpoints, refactor objectify
Adds the remaining Lodestone and PatchList endpoints. Refactors objectify to handle the Array responses they return, and converts type checking to the cleaner switch syntax.
1 parent 126f450 commit d91334d

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lib/xivapi/http.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,27 @@ def request_url(endpoint)
4646
end
4747

4848
def objectify(response)
49-
return response unless response.is_a?(Hash)
50-
result = {}
49+
case response
50+
when Hash
51+
result = {}
5152

52-
response.each do |key, value|
53-
if value.is_a?(Hash)
54-
new_value = objectify(value)
55-
elsif value.is_a?(Array)
56-
new_value = value.map { |val| objectify(val) }
57-
else
58-
new_value = value
53+
response.each do |key, value|
54+
case value
55+
when Hash, Array
56+
new_value = objectify(value)
57+
else
58+
new_value = value
59+
end
60+
61+
result[underscore(key)] = new_value
5962
end
6063

61-
result[underscore(key)] = new_value
64+
OpenStruct.new(result)
65+
when Array
66+
response.map { |data| objectify(data) }
67+
else
68+
response
6269
end
63-
64-
OpenStruct.new(result)
6570
end
6671

6772
def underscore(key)

lib/xivapi/request.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,15 @@ def pvp_team_search(name: nil, server: nil, columns: [])
8484
params = { name: name, server: server&.capitalize, columns: [*columns].join(',') }
8585
XIVAPI::Paginator.new(self, params, 'pvpteam/search', LODESTONE_LIMIT)
8686
end
87+
88+
# Lodestone
89+
def lodestone(category)
90+
endpoint = category.to_s.downcase.delete('_')
91+
request(self, "lodestone/#{endpoint}")
92+
end
93+
94+
# PatchList
95+
def patch_list
96+
request(self, 'patchlist')
97+
end
8798
end

0 commit comments

Comments
 (0)