Skip to content

Commit 5a35a38

Browse files
committed
Add code documentation to requests and paginator
Also tweaked the per_page parameter for the paginator.
1 parent ef65185 commit 5a35a38

File tree

2 files changed

+71
-10
lines changed

2 files changed

+71
-10
lines changed

lib/xivapi/paginator.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ class Paginator
33
include Enumerable
44
include XIVAPI::HTTP
55

6-
def initialize(client, params, endpoint, limit, per_page = nil)
6+
# @param client [XIVAPI::Client] Client that is sending the request
7+
# @param params [Hash] Query parameters
8+
# @param endpoint [String] API endpoint
9+
# @param limit [Integer] Total number of results to limit to
10+
# @param per_page [Integer] Number of results per page, defaults to limit
11+
def initialize(client, params, endpoint, limit, per_page = limit)
712
@client = client
8-
@params = params.merge(limit: per_page || limit)
13+
@params = params.merge(limit: per_page)
914
@endpoint = endpoint
1015
@limit = limit
1116
end

lib/xivapi/request.rb

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ module XIVAPI::Request
44
LODESTONE_LIMIT = 50.freeze
55
ALL_CHARACTER_DATA = 'AC,FR,FC,FCM,PVP'.freeze
66

7-
# Search
7+
# @param indexes [String, Array <String>] One or more indexes to search on
8+
# @param string [String] Value to search for in the string column
9+
# @param string_column [String] Column to perform the string search on
10+
# @param string_algo [String] Algorithm to use for the search
11+
# @param sort_field [String] Column to sort results by
12+
# @param sort_order [String] Order to sort results by
13+
# @param limit [Integer] Total number of results to limit to
14+
# @param filters [String, Array <String>] One or more filters to search on
15+
# @param columns [String, Array <String>] One or more columns to limit results to
16+
# @return [XIVAPI::Paginator] Enumerable search results
817
def search(indexes: [], string: '', string_column: 'Name_en', string_algo: 'wildcard_plus',
918
sort_field: nil, sort_order: nil, limit: 100, filters: [], columns: [])
1019
params = { indexes: [*indexes].join(','), string: string, string_column: string_column, string_algo: string_algo,
1120
sort_field: sort_field, sort_order: sort_order, filters: [*filters].join(','), columns: [*columns].join(',') }
1221
XIVAPI::Paginator.new(self, params, 'search', limit)
1322
end
1423

15-
# Content
24+
# @param name [String] Name of the content (e.g. Achievement, Action, Item)
25+
# @param ids [Integer, Array<Integer>] One or more IDs to retrieve
26+
# @param minify [true, false] Minify resulting data where depth > 1
27+
# @param limit [Integer] Total number of results to limit to
28+
# @param columns [String, Array <String>] One or more columns to limit results to
29+
# @return [Array<String>, OpenStruct, XIVAPI::Paginator]
30+
# Calling with no parameters will return the list of content names
31+
# Calling with a name and a single ID will return that specific content
32+
# Calling with a name and not a singe ID will return enumerable results
1633
def content(name: nil, ids: [], minify: false, limit: 100, columns: [])
1734
if name.nil?
1835
request(self, 'content')
@@ -25,74 +42,113 @@ def content(name: nil, ids: [], minify: false, limit: 100, columns: [])
2542
end
2643
end
2744

45+
# @return [Array<String>] list of servers
2846
def servers
2947
request(self, 'servers')
3048
end
3149

32-
# Character
50+
# @param id [Integer] Character ID
51+
# @param all_data [true, false] Return the full set of character data
52+
# @param poll [true, false] Continuously call the API until a result is cached and returned
53+
# @param columns [String, Array <String>] One or more columns to limit results to
54+
# @return [OpenStruct] The requested character
3355
def character(id: nil, all_data: false, poll: false, columns: [])
3456
params = { data: all_data ? ALL_CHARACTER_DATA : nil, columns: [*columns].join(',') }
3557
request_cached(self, "character/#{id}", :character, params, poll)
3658
end
3759

60+
# @param name [String] Character name
61+
# @param server [String] Character server
62+
# @param columns [String, Array <String>] One or more columns to limit results to
63+
# @return [XIVAPI::Paginator] Enumerable search results
3864
def character_search(name: nil, server: nil, columns: [])
3965
params = { name: name, server: server&.capitalize, columns: [*columns].join(',') }
4066
XIVAPI::Paginator.new(self, params, 'character/search', LODESTONE_LIMIT)
4167
end
4268

69+
# @param id [Integer] Character ID
70+
# @param duplicate_id [Integer] Duplicate character ID
71+
# @return [true, false] Whether or not the character was deleted successfully
4372
def character_delete(id: nil, duplicate_id: nil)
4473
params = { duplicate: duplicate_id }
4574
!!request(self, "character/#{id}/delete", params)
4675
end
4776

77+
# @param id [Integer] Character ID
78+
# @return [true, false] Whether or not the character update was requested successfully
4879
def character_update(id: nil)
4980
request(self, "character/#{id}/update") == 1
5081
end
5182

83+
# @param id [Integer] Character ID
84+
# @return [true, false] Whether or not the character is verified
5285
def character_verified?(id: nil)
5386
request(self, "character/#{id}/verification").verification_token_pass
5487
end
5588

56-
# FreeCompany
89+
# @param id [Integer] Free company ID
90+
# @param members [true, false] Return member data
91+
# @param poll [true, false] Continuously call the API until a result is cached and returned
92+
# @param columns [String, Array <String>] One or more columns to limit results to
93+
# @return [OpenStruct] The requested free company
5794
def free_company(id: nil, members: false, poll: false, columns: [])
5895
params = { data: members ? 'FCM' : nil, columns: [*columns].join(',') }
5996
request_cached(self, "freecompany/#{id}", :free_company, params, poll)
6097
end
6198

99+
# @param name [String] Free company name
100+
# @param server [String] Free company server
101+
# @param columns [String, Array <String>] One or more columns to limit results to
102+
# @return [XIVAPI::Paginator] Enumerable search results
62103
def free_company_search(name: nil, server: nil, columns: [])
63104
params = { name: name, server: server&.capitalize, columns: [*columns].join(',') }
64105
XIVAPI::Paginator.new(self, params, 'freecompany/search', LODESTONE_LIMIT)
65106
end
66107

67-
# Linkshell
108+
# @param id [Integer] Linkshell ID
109+
# @param poll [true, false] Continuously call the API until a result is cached and returned
110+
# @param columns [String, Array <String>] One or more columns to limit results to
111+
# @return [OpenStruct] The requested linkshell
68112
def linkshell(id: nil, poll: false, columns: [])
69113
params = { columns: [*columns].join(',') }
70114
request_cached(self, "linkshell/#{id}", :linkshell, params, poll)
71115
end
72116

117+
# @param name [String] Linkshell name
118+
# @param server [String] Linkshell server
119+
# @param columns [String, Array <String>] One or more columns to limit results to
120+
# @return [XIVAPI::Paginator] Enumerable search results
73121
def linkshell_search(name: nil, server: nil, columns: [])
74122
params = { name: name, server: server&.capitalize, columns: [*columns].join(',') }
75123
XIVAPI::Paginator.new(self, params, 'linkshell/search', LODESTONE_LIMIT)
76124
end
77125

78-
# PvPTeam
126+
# @param id [Integer] PVP team ID
127+
# @param poll [true, false] Continuously call the API until a result is cached and returned
128+
# @param columns [String, Array <String>] One or more columns to limit results to
129+
# @return [OpenStruct] The requested PVP team
79130
def pvp_team(id: nil, poll: false, columns: [])
80131
params = { columns: [*columns].join(',') }
81132
request_cached(self, "pvpteam/#{id}", :pvp_team, params, poll)
82133
end
83134

135+
# @param name [String] PVP team name
136+
# @param server [String] PVP team server
137+
# @param columns [String, Array <String>] One or more columns to limit results to
138+
# @return [XIVAPI::Paginator] Enumerable search results
84139
def pvp_team_search(name: nil, server: nil, columns: [])
85140
params = { name: name, server: server&.capitalize, columns: [*columns].join(',') }
86141
XIVAPI::Paginator.new(self, params, 'pvpteam/search', LODESTONE_LIMIT)
87142
end
88143

89-
# Lodestone
144+
# @param category [String, Symbol] Category to retrieve (e.g. News, Updates, DevBlog)
145+
# @return [Array<OpenStruct>] The requested Lodestone data
90146
def lodestone(category)
91147
endpoint = category.to_s.downcase.delete('_')
92148
request(self, "lodestone/#{endpoint}")
93149
end
94150

95-
# PatchList
151+
# @return [Array<OpenStruct>] List of game patches
96152
def patch_list
97153
request(self, 'patchlist')
98154
end

0 commit comments

Comments
 (0)