Class: RLS::Client

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/rls/client.rb

Overview

A Client that abstracts a user's API key from REST requests, and provides other helpful higher-level functionality.

Constant Summary

Constants included from API

API::APIBASE

Instance Method Summary collapse

Methods included from API

#platforms, #player, #players, #request, #search, #seasons

Constructor Details

#initialize(api_key) ⇒ Client



13
14
15
# File 'lib/rls/client.rb', line 13

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#current_seasonSeason



25
26
27
# File 'lib/rls/client.rb', line 25

def current_season
  seasons.values.find(&:current?)
end

#platform(id) ⇒ Object

Find a platform by ID or name

Raises:

  • (ArgumentError)

    if id is not an `Integer` or `Symbol`



32
33
34
35
36
# File 'lib/rls/client.rb', line 32

def platform(id)
  return platforms.find { |p| p.id == id } if id.is_a? Integer
  return platforms.find { |p| p.name.downcase.to_sym == id } if id.is_a? Symbol
  raise ArgumentError, 'id must be one of type Integer or Symbol'
end

#season(id) ⇒ Season

Returns a single season by ID



20
21
22
# File 'lib/rls/client.rb', line 20

def season(id)
  seasons[id]
end