GitLab's annual major release is around the corner, along with a lot of new and exciting features, there will be a few breaking changes, learn more here.

Commit 01b42e5b authored by Francis's avatar Francis
Browse files

Added icons to wow playable class payload

parent 66f6d25f
Pipeline #50598354 passed with stages
in 3 minutes and 40 seconds
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-16 19:08:57 -0200 using RuboCop version 0.61.1.
# on 2019-03-06 13:04:37 -0300 using RuboCop version 0.61.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 3
Lint/UriEscapeUnescape:
Exclude:
- 'lib/blizzard_api/wow/community/character.rb'
- 'lib/blizzard_api/wow/community/guild.rb'
Please view this file on the master branch, otherwise it may be outdated
**Version 0.2.1**
* Added icon to playable_class return value
* Temporarily ignoring some rubocop offenses as the recommended alternatives are not suitable
**Version 0.2.0**
* D3/SC2 endpoints
* Lots of improvements to WoW endpoints
**Version 0.1.0**
* Initial release
\ No newline at end of file
PATH
remote: .
specs:
blizzard_api (0.1.0)
blizzard_api (0.2.0)
redis (~> 4.1, >= 4.1.0)
GEM
......
# frozen_string_literal: true
##
# API Exception
class ApiException < RuntimeError
attr_reader :code
module BlizzardApi
##
# API Exception
class ApiException < RuntimeError
attr_reader :code
def initialize(msg = '', code = nil)
@code = code
super msg
def initialize(msg = '', code = nil)
@code = code
super msg
end
end
end
......@@ -159,7 +159,7 @@ module BlizzardApi
# Executes the request
http.request(request).tap do |response|
raise ApiException.new 'Request failed', response.code unless response.code.to_i == 200
raise BlizzardApi::ApiException.new 'Request failed', response.code.to_i unless response.code.to_i == 200
end
end
......
......@@ -2,5 +2,5 @@
module BlizzardApi
# Gem version
VERSION = '0.2.0'
VERSION = '0.2.1'
end
......@@ -60,7 +60,7 @@ module BlizzardApi
opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
api_request "#{base_url(:community)}/character/#{realm}/#{CGI.escape(character)}", opts
api_request "#{base_url(:community)}/character/#{realm}/#{URI.encode(character)}", opts
end
##
......@@ -79,7 +79,7 @@ module BlizzardApi
def get_keystone_profile(realm, character, user_token, season = nil, options = {})
opts = { ttl: CACHE_HOUR, namespace: "profile-#{region}" }.merge(options)
opts[:access_token] = user_token
url = "#{base_url(:profile)}/character/#{realm}/#{CGI.escape(character)}/mythic-keystone-profile"
url = "#{base_url(:profile)}/character/#{realm}/#{URI.encode(character)}/mythic-keystone-profile"
url += "/season/#{season}" unless season.nil?
api_request url, opts
end
......
......@@ -60,7 +60,7 @@ module BlizzardApi
opts = { ttl: CACHE_DAY, fields: fields.join(',') }.merge(options)
api_request "#{base_url(:community)}/guild/#{realm}/#{guild}", opts
api_request "#{base_url(:community)}/guild/#{realm}/#{URI.encode(guild)}", opts
end
end
end
......
......@@ -43,12 +43,19 @@ module BlizzardApi
index_data[:classes].each do |pclass|
class_id = %r{playable-class/([0-9]+)}.match(pclass[:key].to_s)[1]
class_data = get class_id, options
class_data.delete :_links
classes.push class_data
end
end
end
def get(id, options = {})
data = api_request "#{base_url(:game_data)}/#{@endpoint}/#{id}", default_options.merge(options)
data[:icon] = get_class_icon data[:media], options
data.delete :_links
data.delete :media
data
end
protected
def endpoint_setup
......@@ -57,6 +64,11 @@ module BlizzardApi
@collection = 'classes'
@ttl = CACHE_TRIMESTER
end
def get_class_icon(media_url, options)
media_data = request media_url[:key][:href], options
%r{56/([a-z_]+).jpg}.match(media_data[:assets][0][:value].to_s)[1]
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment