class Brawlhalla::API::Client

Constants

BASE_URL

Public Class Methods

new(api_key, debug: false) click to toggle source
# File lib/brawlhalla/api/client.rb, line 8
def initialize(api_key, debug: false)
  @api_key = api_key
  @debug = debug
end

Public Instance Methods

ranked(brawlhalla_id) click to toggle source

Get player ranked stats by giving the Brawlhalla ID.

Example

bh = Brawlhalla::API::Client.new('YOUR_API_KEY_HERE')
bh.ranked(8817417)
# File lib/brawlhalla/api/client.rb, line 39
def ranked(brawlhalla_id)
  request(path: "player/#{brawlhalla_id}/ranked")
end
stats(brawlhalla_id) click to toggle source

Get player stats by giving the Brawlhalla ID.

Example

bh = Brawlhalla::API::Client.new('YOUR_API_KEY_HERE')
bh.stats(8817417)
# File lib/brawlhalla/api/client.rb, line 30
def stats(brawlhalla_id)
  request(path: "player/#{brawlhalla_id}/stats")
end

Private Instance Methods

build_url(path, params = {}) click to toggle source
# File lib/brawlhalla/api/client.rb, line 62
def build_url(path, params = {})
  url = Addressable::URI.join(path)
  url.query_values = { api_key: @api_key }.merge(params)
  url
end
client() click to toggle source
# File lib/brawlhalla/api/client.rb, line 45
def client
  @client ||= Faraday.new(url: BASE_URL) do |conn|
    conn.headers['Content-Type'] = 'application/json'
    conn.use FaradayMiddleware::ParseJson
    conn.response :json, parser_options: { symbolize_names: true }
    conn.response :logger if @debug
    conn.adapter Faraday.default_adapter
  end
end
request(path:, params: {}) click to toggle source
# File lib/brawlhalla/api/client.rb, line 55
def request(path:, params: {})
  full_url = build_url(path, params)

  response = client.get(full_url)
  response.body
end