Module: XIVAPI::Request

Includes:
HTTP
Included in:
Client
Defined in:
lib/xivapi/request.rb

Overview

Collection of requests that can be made to XIVAPI

Constant Summary collapse

LODESTONE_LIMIT =

The results limit applied to Lodestone requests

50.freeze
ALL_CHARACTER_DATA =

Options used to retrieve all data when querying a character

'AC,MIMO,CJ,FR,FC,FCM,PVP'.freeze

Constants included from HTTP

HTTP::API_BASE, HTTP::STAGING_API_BASE

Instance Method Summary collapse

Methods included from HTTP

#request

Instance Method Details

#character(id: nil, all_data: false, extended: false, data: [], columns: []) ⇒ OpenStruct

Returns The requested character

Parameters:

  • id (Integer)

    Character ID

  • all_data (true, false)

    Return the full set of character data

  • extended (true, false)

    Return additional data for various fields (e.g. name, icon)

  • data (String, Array <String>)

    Additional data to request, see: xivapi.com/docs/Character#character

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:

  • (OpenStruct)

    The requested character



70
71
72
73
74
# File 'lib/xivapi/request.rb', line 70

def character(id: nil, all_data: false, extended: false, data: [], columns: [])
  params = { data: character_data(all_data, data), columns: [*columns].join(',') }
  params[:extended] = 1 if extended
  request(self, "character/#{id}", params)
end

#character_search(name: nil, server: nil, columns: []) ⇒ XIVAPI::Paginator

Returns Enumerable search results

Parameters:

  • name (String)

    Character name

  • server (String)

    Character server

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:



80
81
82
83
# File 'lib/xivapi/request.rb', line 80

def character_search(name: nil, server: nil, columns: [])
  params = { name: name, server: server, columns: [*columns].join(',') }
  XIVAPI::Paginator.new(self, params, 'character/search', LODESTONE_LIMIT)
end

#character_verified?(id: nil, token: nil) ⇒ true, false

Returns Whether or not the character is verified

Parameters:

  • id (Integer)

    Character ID

  • token (String)

    Verification token to check for

Returns:

  • (true, false)

    Whether or not the character is verified



88
89
90
# File 'lib/xivapi/request.rb', line 88

def character_verified?(id: nil, token: nil)
  character(id: id, columns: 'Character.Bio').character.bio.match?(token)
end

#content(name: nil, ids: [], minify: false, limit: 100, columns: []) ⇒ Array<String>, ...

Returns Calling with no parameters will return the list of content names Calling with a name and a single ID will return that specific content Calling with a name and not a singe ID will return enumerable results

Parameters:

  • name (String)

    Name of the content (e.g. Achievement, Action, Item)

  • ids (Integer, Array<Integer>)

    One or more IDs to retrieve

  • minify (true, false)

    Minify resulting data where depth > 1

  • limit (Integer)

    Total number of results to limit to

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:

  • (Array<String>, OpenStruct, XIVAPI::Paginator)

    Calling with no parameters will return the list of content names Calling with a name and a single ID will return that specific content Calling with a name and not a singe ID will return enumerable results



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/xivapi/request.rb', line 45

def content(name: nil, ids: [], minify: false, limit: 100, columns: [])
  if name.nil?
    request(self, 'content')
  elsif [*ids].size == 1
    params = { minify: minify ? 1 : 0, columns: [*columns].join(',') }
    request(self, "#{name}/#{[*ids].first}", params)
  else
    params = { ids: [*ids].join(','), columns: [*columns].join(',') }
    XIVAPI::Paginator.new(self, params, name, limit)
  end
end

#free_company(id: nil, members: false, columns: []) ⇒ OpenStruct

Returns The requested free company

Parameters:

  • id (Integer)

    Free company ID

  • members (true, false)

    Return member data

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:

  • (OpenStruct)

    The requested free company



96
97
98
99
# File 'lib/xivapi/request.rb', line 96

def free_company(id: nil, members: false, columns: [])
  params = { data: members ? 'FCM' : nil, columns: [*columns].join(',') }
  request(self, "freecompany/#{id}", params)
end

#free_company_search(name: nil, server: nil, columns: []) ⇒ XIVAPI::Paginator

Returns Enumerable search results

Parameters:

  • name (String)

    Free company name

  • server (String)

    Free company server

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:



105
106
107
108
# File 'lib/xivapi/request.rb', line 105

def free_company_search(name: nil, server: nil, columns: [])
  params = { name: name, server: server, columns: [*columns].join(',') }
  XIVAPI::Paginator.new(self, params, 'freecompany/search', LODESTONE_LIMIT)
end

#linkshell(id: nil, columns: []) ⇒ OpenStruct

Returns The requested linkshell

Parameters:

  • id (Integer)

    Linkshell ID

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:

  • (OpenStruct)

    The requested linkshell



113
114
115
116
# File 'lib/xivapi/request.rb', line 113

def linkshell(id: nil, columns: [])
  params = { columns: [*columns].join(',') }
  request(self, "linkshell/#{id}", params)
end

#linkshell_search(name: nil, server: nil, columns: []) ⇒ XIVAPI::Paginator

Returns Enumerable search results

Parameters:

  • name (String)

    Linkshell name

  • server (String)

    Linkshell server

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:



122
123
124
125
# File 'lib/xivapi/request.rb', line 122

def linkshell_search(name: nil, server: nil, columns: [])
  params = { name: name, server: server, columns: [*columns].join(',') }
  XIVAPI::Paginator.new(self, params, 'linkshell/search', LODESTONE_LIMIT)
end

#lore(string: '', limit: 100) ⇒ XIVAPI::Paginator

Returns Enumerable lore results

Parameters:

  • string (String)

    String of lore to search for

  • limit (Integer)

    Total number of results to limit to

Returns:



32
33
34
# File 'lib/xivapi/request.rb', line 32

def lore(string: '', limit: 100)
  XIVAPI::Paginator.new(self, { string: string }, 'lore', limit)
end

#patch_listArray<OpenStruct>

Returns List of game patches

Returns:

  • (Array<OpenStruct>)

    List of game patches



145
146
147
# File 'lib/xivapi/request.rb', line 145

def patch_list
  request(self, 'patchlist')
end

#pvp_team(id: nil, columns: []) ⇒ OpenStruct

Returns The requested PVP team

Parameters:

  • id (Integer)

    PVP team ID

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:

  • (OpenStruct)

    The requested PVP team



130
131
132
133
# File 'lib/xivapi/request.rb', line 130

def pvp_team(id: nil, columns: [])
  params = { columns: [*columns].join(',') }
  request(self, "pvpteam/#{id}", params)
end

#pvp_team_search(name: nil, server: nil, columns: []) ⇒ XIVAPI::Paginator

Returns Enumerable search results

Parameters:

  • name (String)

    PVP team name

  • server (String)

    PVP team server

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:



139
140
141
142
# File 'lib/xivapi/request.rb', line 139

def pvp_team_search(name: nil, server: nil, columns: [])
  params = { name: name, server: server, columns: [*columns].join(',') }
  XIVAPI::Paginator.new(self, params, 'pvpteam/search', LODESTONE_LIMIT)
end

#search(indexes: [], string: '', string_column: nil, string_algo: nil, sort_field: nil, sort_order: nil, limit: 100, body: nil, filters: [], columns: []) ⇒ XIVAPI::Paginator

Returns Enumerable search results

Parameters:

  • indexes (String, Array <String>)

    One or more indexes to search on

  • string (String)

    Value to search for in the string column

  • string_column (String)

    Column to perform the string search on

  • string_algo (String)

    Algorithm to use for the search

  • sort_field (String)

    Column to sort results by

  • sort_order (String)

    Order to sort results by

  • limit (Integer)

    Total number of results to limit to

  • body (Hash)

    Request body for advanced ElasticSearch queries

  • filters (String, Array <String>)

    One or more filters to search on

  • columns (String, Array <String>)

    One or more columns to limit results to

Returns:



22
23
24
25
26
27
# File 'lib/xivapi/request.rb', line 22

def search(indexes: [], string: '', string_column: nil, string_algo: nil,
           sort_field: nil, sort_order: nil, limit: 100, body: nil, filters: [], columns: [])
  params = { indexes: [*indexes].join(','), string: string, string_column: string_column, string_algo: string_algo,
             sort_field: sort_field, sort_order: sort_order, filters: [*filters].join(','), columns: [*columns].join(',') }
  XIVAPI::Paginator.new(self, params, 'search', limit, body)
end

#servers(group: false) ⇒ Array<String>

Returns List of servers

Parameters:

  • group (true, false)

    Group the servers by data center

Returns:

  • (Array<String>)

    List of servers



59
60
61
62
# File 'lib/xivapi/request.rb', line 59

def servers(group: false)
  endpoint = group ? 'servers/dc' : 'servers'
  request(self, endpoint)
end