ruby-lol 0.0.7 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64b2c711ab04175c2affa3e50c2e2edcd19174cc
4
- data.tar.gz: 332cbea429a999952017e23e26e156dcf777e64c
3
+ metadata.gz: 3ed1b5474d3abe4a83a978853e1e40f51b205d51
4
+ data.tar.gz: 951a6a05d57d7574b7a01e1a7d1168941a993b9e
5
5
  SHA512:
6
- metadata.gz: 745627a7bcdcb12d570f246dd5da1dd8636e7061036de7f9b24b4ea9a7b323f9db119c923d53c49efd0b20acd9d80cd7fbba8944cac0d6e1a509f6746c4817bf
7
- data.tar.gz: 7b7c2824be9137a8f3c7b63bf6851ca912f4750076f159cb7aac1b91f00877a10f43f3b3a7086119af4b5881390fb06c7c8534a273193731f4939148ce5b0d37
6
+ metadata.gz: a639d3260ba7b4dec631e22c30295114736be5ac3065ef15198e411fe56493983f2784e5e676a724203eb94bcd920e2a0d4ec0a7d18f3590e7bf8992c6200866
7
+ data.tar.gz: 9cca04e89cf82bf3736a0b1667dd8b69166b29d6d77c6ac754da6166b875f51ae815efa26a491c3548b052e10568b69b546f4712c5ff03a4f2d39c38d6890c81
data/README.md CHANGED
@@ -3,10 +3,6 @@
3
3
 
4
4
  ruby-lol is a wrapper to the [Riot Games API](https://developer.riotgames.com).
5
5
 
6
- ## IMPORTANT NOTICE
7
-
8
- An important piece of refactoring is happening in the *refactoring* branch. Check it out for updated docs. I plan to merge it in this week.
9
-
10
6
  ## Installation
11
7
 
12
8
  Add this line to your application's Gemfile:
@@ -66,15 +62,15 @@ Or install it yourself as:
66
62
  # => Lol::RankedStats
67
63
 
68
64
  client.summoner.masteries(summoner_id)
69
- # => Lol::Masteries
65
+ # => [Lol::Masterypage]
70
66
  client.summoner.runes(summoner_id)
71
- # => Lol::Runes
67
+ # => [Lol::Runepage]
72
68
  client.summoner.by_name(name)
73
69
  # => Lol::Summoner
74
70
  client.summoner.get(summoner_id)
75
71
  # => Lol::Summoner
76
72
  client.summoner.name(summoner_ids)
77
- # => Array
73
+ # => [Hash]
78
74
 
79
75
  client.team.get(summoner_id)
80
76
  # => Array
data/Rakefile CHANGED
@@ -2,7 +2,9 @@ require "bundler/setup"
2
2
  require "bundler/gem_tasks"
3
3
  require "rspec/core/rake_task"
4
4
 
5
- RSpec::Core::RakeTask.new(:spec)
5
+ RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args|
6
+ t.rspec_opts = "--tag #{task_args[:tag]}" if task_args[:tag]
7
+ end
6
8
 
7
9
  task :default => :spec
8
10
 
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(__dir__ + "/../lib")
2
+
3
+ require "rubygems"
4
+ require "ap"
5
+ require "lol"
6
+
7
+ include Lol
8
+
9
+ client = Client.new "18b7c486-0d5a-459f-9d60-cf8776b154c6"
10
+ intinig = client.summoner.by_name "intinig"
11
+ leagues = client.league.get intinig.id
12
+ my_league = leagues.first
13
+
14
+ my_league.entries.select {|entry| entry.player_or_team_name == "intinig"}.each do |entry|
15
+ ap entry
16
+ end
data/lib/lol.rb CHANGED
@@ -6,12 +6,19 @@ require "lol/game_request"
6
6
  require "lol/stats_request"
7
7
  require "lol/team_request"
8
8
  require "lol/league_request"
9
+ require "lol/summoner_request"
9
10
 
10
11
  require "lol/model"
11
12
  require "lol/champion"
12
13
  require "lol/game"
13
14
  require "lol/league"
14
15
  require "lol/player"
16
+ require "lol/summoner"
17
+ require "lol/rune_page"
18
+ require "lol/rune_slot"
19
+ require "lol/rune"
20
+ require "lol/mastery_page"
21
+ require "lol/talent"
15
22
  require "lol/raw_statistic"
16
23
  require "lol/player_statistic"
17
24
  require "lol/aggregated_statistic"
@@ -2,8 +2,6 @@ require 'httparty'
2
2
  require 'uri'
3
3
 
4
4
  module Lol
5
- class InvalidAPIResponse < StandardError; end
6
-
7
5
  class Client
8
6
 
9
7
  # @!attribute [rw] region
@@ -39,6 +37,11 @@ module Lol
39
37
  @team_request ||= TeamRequest.new(api_key, region)
40
38
  end
41
39
 
40
+ # @return [SummonerRequest]
41
+ def summoner
42
+ @summoner_request ||= SummonerRequest.new(api_key, region)
43
+ end
44
+
42
45
  # Initializes a Lol::Client
43
46
  # @param api_key [String]
44
47
  # @param options [Hash]
@@ -5,7 +5,7 @@ module Lol
5
5
  # @return [Array] an array of games
6
6
  def recent summoner_id
7
7
  summoner_api_path = "game/by-summoner/#{summoner_id}/recent"
8
- perform_request(api_url("v1.1", summoner_api_path))["games"].map do |game_data|
8
+ perform_request(api_url("v1.2", summoner_api_path))["games"].map do |game_data|
9
9
  Game.new game_data
10
10
  end
11
11
  end
@@ -3,7 +3,7 @@ module Lol
3
3
  # Retrieves leagues data for summoner, including leagues for all of summoner's teams, v2.1
4
4
  # @return [Array] an array of champions
5
5
  def get summoner_id
6
- response = perform_request(api_url("v2.1", "league/by-summoner/#{summoner_id}"))[summoner_id]
6
+ response = perform_request(api_url("v2.1", "league/by-summoner/#{summoner_id}"))[summoner_id.to_s]
7
7
  response.is_a?(Hash) ? [League.new(response)] : response.map {|l| League.new l}
8
8
  end
9
9
 
@@ -0,0 +1,28 @@
1
+ module Lol
2
+ class MasteryPage < Model
3
+
4
+ # @!attribute [r] id
5
+ # @return [Fixnum] id of summoner
6
+ attr_reader :summoner_id
7
+
8
+ # @!attribute [r] talents
9
+ # @return [Array] array of Lol::Talent
10
+ attr_reader :talents
11
+
12
+ # @!attribute [r] name
13
+ # @return [String] name of mastery page
14
+ attr_reader :name
15
+
16
+ # @!attribute [r] current
17
+ # @return [Boolean] is it the current mastery page?
18
+ attr_reader :current
19
+
20
+ private
21
+
22
+ attr_writer :summoner_id, :name, :current
23
+
24
+ def talents= new_talents
25
+ @talents = new_talents.map {|t| Talent.new t}
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,7 @@
1
1
  module Lol
2
+ class InvalidAPIResponse < StandardError; end
3
+ class NotFound < StandardError; end
4
+
2
5
  # Encapsulates common methods for all requests
3
6
  # Request classes inherit from this
4
7
  class Request
@@ -18,7 +21,7 @@ module Lol
18
21
  # @param path [String] API path to call
19
22
  # @return [String] full fledged url
20
23
  def api_url version, path, params = {}
21
- lol = version == "v1.1" ? "lol" : ""
24
+ lol = version == "v2.1" ? "" : "lol"
22
25
  query_string = URI.encode_www_form params.merge api_key: api_key
23
26
  File.join "http://prod.api.pvp.net/api/", lol, "/#{region}/#{version}/", "#{path}?#{query_string}"
24
27
  end
@@ -28,24 +31,16 @@ module Lol
28
31
  # @return [String] raw response of the call
29
32
  def perform_request url
30
33
  response = self.class.get(url)
31
- if response.is_a?(Hash) && response["status"]
32
- raise InvalidAPIResponse.new(response["status"]["message"])
33
- else
34
- response
35
- end
34
+ raise NotFound.new("404 Not Found") if response.respond_to?(:code) && response.not_found?
35
+ raise InvalidAPIResponse.new(response["status"]["message"]) if response.is_a?(Hash) && response["status"]
36
+
37
+ response
36
38
  end
37
39
 
38
40
  def initialize api_key, region
39
41
  @api_key = api_key
40
42
  @region = region
41
43
  end
42
- private
43
44
 
44
- # Sets api_key to new_key
45
- # @param new_key [String] a Riot Games API key
46
- # @return [String] new_key
47
- def api_key= new_key
48
- @api_key = new_key
49
- end
50
45
  end
51
46
  end
@@ -0,0 +1,23 @@
1
+ module Lol
2
+ class Rune < Model
3
+ # @!attribute [r] id
4
+ # @return [Fixnum] Rune id
5
+ attr_reader :id
6
+
7
+ # @!attribute [r] name
8
+ # @return [String] Rune name
9
+ attr_reader :name
10
+
11
+ # @!attribute [r] description
12
+ # @return [String] Rune description
13
+ attr_reader :description
14
+
15
+ # @!attribute [r] tier
16
+ # @return [Fixnum] Rune tier
17
+ attr_reader :tier
18
+
19
+ private
20
+
21
+ attr_writer :id, :name, :description, :tier
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Lol
2
+ class RunePage < Model
3
+ # @!attribute [r] id
4
+ # @return [Fixnum] id of Runepage
5
+ attr_reader :id
6
+
7
+ # @!attribute [r] name
8
+ # @return [String] name of Runepage
9
+ attr_reader :name
10
+
11
+ # @!attribute [r] current
12
+ # @return [Boolean] is the Runepage currently active?
13
+ attr_reader :current
14
+
15
+
16
+ # @!attribute [r] current
17
+ # @return [Array] array of Lol::RuneSlot
18
+ attr_reader :slots
19
+ end
20
+
21
+ private
22
+
23
+ attr_writer :id, :name, :current
24
+
25
+ def slots= *runeslots
26
+ @slots = runeslots.flatten.map {|slot| RuneSlot.new slot}
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ module Lol
2
+ class RuneSlot < Model
3
+ # @!attribute [r] id
4
+ # @return [Fixnum] id of RuneSlot
5
+ def id
6
+ @rune_slot_id
7
+ end
8
+
9
+ # @!attribute [r] rune
10
+ # @return [Rune] rune placed in the slot
11
+ attr_reader :rune
12
+
13
+ private
14
+
15
+ def rune= rune_data
16
+ @rune = Rune.new rune_data
17
+ end
18
+
19
+ def id= new_id
20
+ @rune_slot_id = new_id
21
+ end
22
+
23
+ def rune_slot_id= new_id
24
+ @rune_slot_id = new_id
25
+ end
26
+ end
27
+ end
File without changes
@@ -0,0 +1,36 @@
1
+ module Lol
2
+ class Summoner < Model
3
+ # @!attribute [r] id
4
+ # @return [String]
5
+ attr_reader :id
6
+
7
+ # @!attribute [r] name
8
+ # @return [String] Summoner Name
9
+ attr_reader :name
10
+
11
+ # @!attribute [r] profile_icon_id
12
+ # @return [String] Id of the profile icon. No way to get the icon out for now
13
+ attr_reader :profile_icon_id
14
+
15
+ # @!attribute [r] revision_date
16
+ # @return [Time] Last date of summoner profile revision
17
+ attr_reader :revision_date
18
+
19
+ # @!attribute [r] revision_date_str
20
+ # @return [String] Human readable string representing date of summoner profile revision
21
+ attr_reader :revision_date_str
22
+
23
+ # @!attribute [r] summoner_level
24
+ # @return [Numeric] 1-30
25
+ attr_reader :summoner_level
26
+
27
+ private
28
+
29
+ attr_writer :id, :name, :profile_icon_id, :summoner_level, :revision_date_str
30
+
31
+ def revision_date= value
32
+ @revision_date = value.is_a?(Numeric) && Time.at(value / 1000) || value
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module Lol
2
+ class SummonerRequest < Request
3
+ # Looks for a summoner name and returns the associated summoner
4
+ # @param [String] name Summoner name
5
+ # @return [Summoner] matching summoner
6
+ def by_name name
7
+ Summoner.new perform_request(api_url("v1.1", "summoner/by-name/#{name}"))
8
+ end
9
+
10
+ # Get list of summoner names by summoner IDs
11
+ # @param [Array] array of summoner ids
12
+ # @return [Array] array of Hash { "id" => "foo", "name" => "bar" }
13
+ def name *summoner_ids
14
+ perform_request(api_url("v1.1", "summoner/#{summoner_ids.join(",")}/name"))["summoners"].map do |summoner|
15
+ summoner
16
+ end
17
+ end
18
+
19
+ # Get summoner by summoner ID
20
+ # @param [String] summoner_id
21
+ # @return [Lol::Summoner]
22
+ def get summoner_id
23
+ Summoner.new perform_request(api_url("v1.1", "summoner/#{summoner_id}"))
24
+ end
25
+
26
+ # Get rune pages by summoner ID
27
+ # @param [String] summoner_id
28
+ # @return [Array] array of Lol::RunePage
29
+ def runes summoner_id
30
+ perform_request(api_url("v1.1", "summoner/#{summoner_id}/runes"))["pages"].map do |runepage|
31
+ RunePage.new runepage
32
+ end
33
+ end
34
+
35
+ # Get mastery pages by summoner ID
36
+ # @param [String] summoner_id
37
+ # @return [Array] array of Lol::MasteryPage
38
+ def masteries summoner_id
39
+ perform_request(api_url("v1.1", "summoner/#{summoner_id}/masteries"))["pages"].map do |masterypage|
40
+ MasteryPage.new masterypage
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ module Lol
2
+ class Talent < Model
3
+
4
+ # @!attribute [r] id
5
+ # @return [Fixnum] id of talent
6
+ attr_reader :id
7
+
8
+ # @!attribute [r] name
9
+ # @return [String] name of talent
10
+ attr_reader :name
11
+
12
+ # @!attribute [r] rank
13
+ # @return [Fixnum] rank of talent
14
+ attr_reader :rank
15
+
16
+ private
17
+
18
+ attr_writer :id, :name, :rank
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Lol
2
- VERSION = "0.0.7"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+ require "lol"
3
+ require "awesome_print"
4
+
5
+ # Requires connection
6
+ describe "Live API testing", :remote => true do
7
+ before(:all) do
8
+ VCR.configure do |c|
9
+ c.allow_http_connections_when_no_cassette = true
10
+ end
11
+ end
12
+
13
+ subject { Lol::Client.new ENV['RIOT_GAMES_API_KEY'] }
14
+ let(:na) { Lol::Client.new ENV['RIOT_GAMES_API_KEY'], :region => "na" }
15
+ let(:eune) { Lol::Client.new ENV['RIOT_GAMES_API_KEY'], :region => "eune" }
16
+ let(:br) { Lol::Client.new ENV['RIOT_GAMES_API_KEY'], :region => "br"}
17
+ let(:tr) { Lol::Client.new ENV['RIOT_GAMES_API_KEY'], :region => "tr"}
18
+
19
+ describe "champion-v1.1" do
20
+ context "working realms" do
21
+ %w(euw na eune).each do |realm|
22
+ it "works on #{realm}" do
23
+ subject.region = realm
24
+ expect { subject.champion.get }.not_to raise_error
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "game-v1.2" do
31
+ context "working realms" do
32
+ %w(euw na eune).each do |realm|
33
+ it "works on #{realm}" do
34
+ subject.region = realm
35
+ expect { subject.game.recent(summoners[realm]) }.not_to raise_error
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ after(:all) do
42
+ VCR.configure do |c|
43
+ c.allow_http_connections_when_no_cassette = true
44
+ end
45
+ end
46
+ end