Class: SwgohComlink
- Inherits:
-
Object
- Object
- SwgohComlink
- Defined in:
- lib/swgoh_comlink.rb
Overview
Base class for the gem, a wrapper for Comlink See github.com/swgoh-utils/swgoh-comlink for more info on Comlink
Instance Method Summary collapse
- #data(version, include_pve_units = true, request_segment = 0, enums = false) ⇒ Object
- #enums ⇒ Object
- #get_events(enums = false) ⇒ Object
- #get_guild_leaderboard(leaderboards, count, enums = false) ⇒ Object
- #get_guilds(filter_type, name = nil, search_criteria = nil, count = 10, enums = false) ⇒ Object
- #get_leaderboard(payload, enums = false) ⇒ Object
- #guild(guild_id, include_recent_guild_activity = false, enums = false) ⇒ Object
-
#initialize(comlink_url, keys = {}) ⇒ SwgohComlink
constructor
A new instance of SwgohComlink.
- #localization(id, unzip = false, enums = false) ⇒ Object
- #metadata(client_specs = {}, enums = false) ⇒ Object
- #player(player_id, enums = false) ⇒ Object
- #player_arena(player_id, enums = false) ⇒ Object
Constructor Details
#initialize(comlink_url, keys = {}) ⇒ SwgohComlink
Returns a new instance of SwgohComlink.
10 11 12 |
# File 'lib/swgoh_comlink.rb', line 10 def initialize(comlink_url, keys = {}) @api_requester = ComlinkApiRequest.new(comlink_url, keys) end |
Instance Method Details
#data(version, include_pve_units = true, request_segment = 0, enums = false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/swgoh_comlink.rb', line 38 def data(version, include_pve_units = true, request_segment = 0, enums = false) body = { payload: { version: version, includePveUnits: include_pve_units, requestSegment: request_segment }, enums: enums } body_validation(body, [ { validation: (0..4), error_message: 'Request segment must be between 0 and 4', path: [:payload, :requestSegment] } ]) JSON.parse(@api_requester.post('/data', body.to_json)) end |
#enums ⇒ Object
14 15 16 |
# File 'lib/swgoh_comlink.rb', line 14 def enums JSON.parse(@api_requester.get('/enums')) end |
#get_events(enums = false) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/swgoh_comlink.rb', line 107 def get_events(enums = false) body = { enums: enums } JSON.parse(@api_requester.post('/getEvents', body.to_json)) end |
#get_guild_leaderboard(leaderboards, count, enums = false) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/swgoh_comlink.rb', line 140 def get_guild_leaderboard(leaderboards, count, enums = false) def_ids = [ 'sith_raid', 'rancor', 'aat', 'kraytdragon', 'speederbike', 't01D', 't02D', 't03D', 't04D', 't05D', 'TERRITORY_WAR_LEADERBOARD', 'GUILD:RAIDS:NORMAL_DIFF:RANCOR:DIFF06', 'GUILD:RAIDS:NORMAL_DIFF:RANCOR:HEROIC80', 'GUILD:RAIDS:NORMAL_DIFF:AAT:DIFF06', 'GUILD:RAIDS:NORMAL_DIFF:AAT:HEROIC85', 'GUILD:RAIDS:NORMAL_DIFF:SITH_RAID:DIFF06', 'GUILD:RAIDS:NORMAL_DIFF:SITH_RAID:HEROIC85', 'GUILD:RAIDS:NORMAL_DIFF:KRAYTDRAGON:DIFF01', 'GUILD:RAIDS:NORMAL_DIFF:ROTJ:SPEEDERBIKE' ] leaderboards.each do |leaderboard| payload = verify_parameters(leaderboard, ['leaderboardType', 'defId', 'monthOffset']) body_validation(leaderboard, [ { validation: [0, 2, 3, 4, 5, 6], error_message: 'leaderboardType must in [0, 2, 3, 4, 5, 6]', path: [:leaderboardType], required: true }, { validation: def_ids, error_message: 'defId must be certain values, see docs', path: [:defId], required: [2, 4, 5, 6].include?(leaderboard.with_indifferent_access[:leaderboardType]) }, { validation: [0, 1], error_message: 'monthOffset must 0 or 1', path: [:monthOffset] } ]) end body = { payload: { leaderboardId: leaderboards, count: count }, enums: enums } JSON.parse(@api_requester.post('/getGuildLeaderboard', body.to_json)) end |
#get_guilds(filter_type, name = nil, search_criteria = nil, count = 10, enums = false) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/swgoh_comlink.rb', line 83 def get_guilds(filter_type, name = nil, search_criteria = nil, count = 10, enums = false) body = { payload: { filterType: filter_type, count: count, enums: enums } } validations = [ { validation: [4, 5], error_message: 'filterType must be 4 or 5', path: [:payload, :filterType], required: true } ] if filter_type == 4 body[:payload][:name] = name validations << { error_message: 'Name is required when filterType is 4', path: [:payload, :name], required: true } elsif filter_type == 5 body[:payload][:searchCriteria] = search_criteria && verify_parameters(search_criteria, ['minMemberCount', 'maxMemberCount', 'includeInviteOnly', 'minGuildGalacticPower', 'maxGuildGalacticPower', 'recentTbParticipatedIn']) validations << { error_message: 'searchCriteria is required when filterType is 5', path: [:payload, :searchCriteria], required: true } end body_validation(body, validations) JSON.parse(@api_requester.post('/getGuilds', body.to_json)) end |
#get_leaderboard(payload, enums = false) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/swgoh_comlink.rb', line 115 def get_leaderboard(payload, enums = false) body_validation(payload, [ { validation: [4, 6], error_message: 'leaderboardType must be 4 or 6', path: [:leaderboardType] } ]) if payload[:leaderboardType] == 4 || payload[:leaderboard_type] == 4 payload = verify_parameters(payload, ['leaderboardType', 'eventInstanceId', 'groupId']) body_validation(payload, [ { error_message: 'eventInstanceId must be present', path: [:eventInstanceId], required: true }, { error_message: 'groupId must be present', path: [:groupId], required: true } ]) else payload = verify_parameters(payload, ['leaderboardType', 'league', 'division']) body_validation(payload, [ { validation: [20, 40, 60, 80, 100], error_message: 'league must be in [20, 40, 60, 80, 100]', path: [:league], required: true }, { validation: [5, 10, 15, 20, 25], error_message: 'division must be in [5, 10, 15, 20, 25]', path: [:division], required: true } ]) end body = { payload: payload, enums: false } JSON.parse(@api_requester.post('/getLeaderboard', body.to_json)) end |
#guild(guild_id, include_recent_guild_activity = false, enums = false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/swgoh_comlink.rb', line 71 def guild(guild_id, include_recent_guild_activity = false, enums = false) body = { payload: { guildId: guild_id, includeRecentGuildActivityInfo: include_recent_guild_activity }, enums: enums } JSON.parse(@api_requester.post('/guild', body.to_json)) end |
#localization(id, unzip = false, enums = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/swgoh_comlink.rb', line 18 def localization(id, unzip = false, enums = false) body = { payload: { id: id }, unzip: unzip, enums: enums } JSON.parse(@api_requester.post('/localization', body.to_json)) end |
#metadata(client_specs = {}, enums = false) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/swgoh_comlink.rb', line 30 def (client_specs = {}, enums = false) body = {} body['payload'] = { "clientSpecs" => verify_parameters(client_specs, ['platform', 'bundleId', 'externalVersion', 'internalVersion', 'region']) } unless client_specs.empty? body['enums'] = false JSON.parse(@api_requester.post('/metadata', body.to_json)) end |
#player(player_id, enums = false) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/swgoh_comlink.rb', line 53 def player(player_id, enums = false) body = { payload: format_player_id_hash(player_id), enums: enums } JSON.parse(@api_requester.post('/player', body.to_json)) end |
#player_arena(player_id, enums = false) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/swgoh_comlink.rb', line 62 def player_arena(player_id, enums = false) body = { payload: format_player_id_hash(player_id), enums: enums } JSON.parse(@api_requester.post('/playerArena', body.to_json)) end |