Class: RiotApi::API
- Inherits:
-
Object
- Object
- RiotApi::API
- Defined in:
- lib/riot_api/api.rb
Instance Method Summary collapse
- #champions ⇒ Object
- #default_faraday ⇒ Object
- #game ⇒ Object
-
#initialize(params) ⇒ API
constructor
Creates a new Riot API client instance.
- #league ⇒ Object
- #stats ⇒ Object
- #summoner ⇒ Object
- #team ⇒ Object
Constructor Details
#initialize(params) ⇒ API
Creates a new Riot API client instance.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/riot_api/api.rb', line 18 def initialize(params) @api_key = params[:api_key] @region = params[:region] @debug = params[:debug] @ssl = params[:ssl] || { :verify => true } @base_url = params[:base_url] || "http://prod.api.pvp.net/api/" @faraday_adapter = params[:faraday_adapter] || Faraday.default_adapter @raise_status_errors = params[:raise_status_errors] || false @faraday = params[:faraday] || default_faraday raise ArgumentError, ':api_key missing' unless @api_key raise ArgumentError, ':region missing' unless @region raise ArgumentError, "Invalid Region (Valid regions: 'eune','br','tr','na','euw')" unless ['eune','br','tr','na','euw'].include?(@region) end |
Instance Method Details
#champions ⇒ Object
32 33 34 |
# File 'lib/riot_api/api.rb', line 32 def champions RiotApi::Resource::Champions.new(@faraday, @region) end |
#default_faraday ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/riot_api/api.rb', line 56 def default_faraday Faraday.new(:url => @base_url, :ssl => @ssl) do |faraday| faraday.use Faraday::Response::RaiseError if @raise_status_errors faraday.request :url_encoded faraday.response :rashify faraday.response :json faraday.response(:logger) if @debug faraday.adapter @faraday_adapter faraday.params['api_key'] = @api_key faraday.headers['User-Agent'] = "riot_api rubygem v#{RiotApi::VERSION}" end end |
#game ⇒ Object
36 37 38 |
# File 'lib/riot_api/api.rb', line 36 def game RiotApi::Resource::Game.new(@faraday, @region) end |
#league ⇒ Object
40 41 42 |
# File 'lib/riot_api/api.rb', line 40 def league RiotApi::Resource::League.new(@faraday, @region) end |
#stats ⇒ Object
44 45 46 |
# File 'lib/riot_api/api.rb', line 44 def stats RiotApi::Resource::Stats.new(@faraday, @region) end |