league_of_legends 0.0.1 → 0.0.2

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: ecc7dd2c6bbe476cb20c0a555a47fca80fbabbce
4
- data.tar.gz: 4f81bd5b7e31e558ea930bd7ea9e1f2e4d89f184
3
+ metadata.gz: 69d531bb9522870e6d2b2f4c641fd2b8cca0f28b
4
+ data.tar.gz: 63d6949c7a40c92127769f36ea0bc078fb126882
5
5
  SHA512:
6
- metadata.gz: 0954d361c173bb8f729d3d931362116e5c48840c20d45e4a7a64c358c2466728207a926a84aa0b9a7b8153a7e5518dc54543f7fd2166789343b8b9fa33ebb8a4
7
- data.tar.gz: 40951e499982bd5f7f9547265fb2b4337502c7e0fd254558927d42bb7c78a4545193ab017a9f8c9a140f7b599aef2d35702b0cd367b388bc7a1c7f560e8da9c5
6
+ metadata.gz: c26c44e5243efe607d6a462d4e477cae4f18e1c1f80794001e5275193e1ee6199e932943aceb60671cd67330b8f276d2fabb4b2f1e13787d01d9ad6480699159
7
+ data.tar.gz: a783c48faa899654dd5f5ab616a8603cfba113815617ae027dafc00b0adba94ec0762f0cb913daf4c1770f51750ffc76565d210569235f153696adc483f79b47
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # LeagueOfLegends
1
+ # league_of_legends
2
2
 
3
3
  This gem implements the League Of Legends API (currently in open beta). It will continue to be updated as the API evolves.
4
4
 
@@ -20,11 +20,22 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ The gem is still not (properly) usable at this point. It is a work in progress! :)
24
+
25
+ To work with it (until the next version comes out!), change the code in lib/league_of_legends/api.rb to return your actual API key.
26
+
27
+ Then you can do:
28
+
29
+ sss_request = ::LeagueOfLegends::Request::Stats::BySummoner::Summary.new <summoner_id>
30
+ sss_request.response # => ::LeagueOfLegends::DTO::PlayerStatsSummaryList
31
+
32
+ You can read about each Request and DTO at http://developer.riotgames.com/api/methods
33
+
34
+
24
35
 
25
36
  ## Contributing
26
37
 
27
- 1. Fork it ( http://github.com/<my-github-username>/league_of_legends/fork )
38
+ 1. Fork it ( http://github.com/forvalho/league_of_legends/fork )
28
39
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
40
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
41
  4. Push to the branch (`git push origin my-new-feature`)
@@ -0,0 +1,13 @@
1
+ module ::LeagueOfLegends
2
+ class Api
3
+
4
+ def self.key
5
+ 'a1a1a1-b2b2b2-c3c3c3-d4d4d4-e5e5e5e5'
6
+ end
7
+
8
+ def self.base_url
9
+ 'https://prod.api.pvp.net/api/lol'
10
+ end
11
+
12
+ end
13
+ end
@@ -2,6 +2,10 @@ module ::LeagueOfLegends
2
2
  module DTO
3
3
  class AggregatedStats
4
4
 
5
+ def self.version
6
+ ::LeagueOfLegends::DTO::PlayerStatsSummaryList.version
7
+ end
8
+
5
9
  attr_reader :average_assists, :average_champions_killed,
6
10
  :average_combat_player_score, :average_node_capture,
7
11
  :average_node_capture_assist, :average_node_neutralize,
@@ -25,7 +29,7 @@ module ::LeagueOfLegends
25
29
  :total_quadra_kills, :total_sessions_lost, :total_sessions_played,
26
30
  :total_sessions_won, :total_triple_kills, :total_turrets_killed,
27
31
  :total_unreal_kills
28
-
32
+
29
33
  def initialize attributes
30
34
  @average_assists = attributes[:averageAssists].to_i
31
35
  @average_champions_killed = attributes[:averageChampionsKilled].to_i
@@ -0,0 +1,30 @@
1
+ module ::LeagueOfLegends
2
+ module DTO
3
+ class Champion
4
+
5
+ def self.version
6
+ ::LeagueOfLegends::DTO::ChampionList.version
7
+ end
8
+
9
+ attr_reader :active, :attack_rank, :bot_enabled,
10
+ :bot_mm_enabled, :defense_rank, :difficulty_rank,
11
+ :free_to_play, :id, :magic_rank, :name,
12
+ :ranked_play_enabled
13
+
14
+ def initialize attributes
15
+ @active = attributes[:active]
16
+ @attack_rank = attributes[:attackRank]
17
+ @bot_enabled = attributes[:botEnabled]
18
+ @bot_mm_enabled = attributes[:botMmEnabled]
19
+ @defense_rank = attributes[:defenseRank]
20
+ @difficulty_rank = attributes[:difficultyRank]
21
+ @free_to_play = attributes[:freeToPlay]
22
+ @id = attributes[:id]
23
+ @magic_rank = attributes[:magicRank]
24
+ @name = attributes[:name]
25
+ @ranked_play_enabled = attributes[:rankedPlayEnabled]
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'league_of_legends/dto/base'
2
+ require 'league_of_legends/dto/champion'
3
+
4
+ module ::LeagueOfLegends
5
+ module DTO
6
+ class ChampionList < ::LeagueOfLegends::DTO::Base
7
+
8
+ def self.version
9
+ 'v1.1'
10
+ end
11
+
12
+ attr_reader :champions
13
+
14
+ def initialize json
15
+ attributes = build_attributes json
16
+ @champions = attributes[:champions].map do |champion|
17
+ ::LeagueOfLegends::DTO::Champion.new(champion)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -1,7 +1,13 @@
1
+ require 'league_of_legends/dto/aggregated_stats'
2
+
1
3
  module ::LeagueOfLegends
2
4
  module DTO
3
5
  class PlayerStatsSummary
4
6
 
7
+ def self.version
8
+ ::LeagueOfLegends::DTO::PlayerStatsSummaryList.version
9
+ end
10
+
5
11
  attr_reader :player_stat_summary_type, :wins,
6
12
  :losses, :modify_date, :aggregated_stats
7
13
 
@@ -1,21 +1,24 @@
1
+ require 'league_of_legends/dto/base'
2
+ require 'league_of_legends/dto/player_stats_summary'
3
+
1
4
  module ::LeagueOfLegends
2
5
  module DTO
3
6
  class PlayerStatsSummaryList < ::LeagueOfLegends::DTO::Base
4
7
 
8
+ def self.version
9
+ 'v1.2'
10
+ end
11
+
5
12
  attr_reader :summoner_id, :player_stat_summaries
6
13
 
7
14
  def initialize json
8
- @attributes = build_attributes json
15
+ attributes = build_attributes json
9
16
  @summoner_id = attributes[:summonerId].to_i
10
17
  @player_stat_summaries = attributes[:playerStatSummaries].map do |pss|
11
18
  ::LeagueOfLegends::DTO::PlayerStatsSummary.new(pss)
12
19
  end
13
20
  end
14
21
 
15
- private
16
-
17
- attr_reader :attributes
18
-
19
22
  end
20
23
  end
21
24
  end
@@ -0,0 +1,81 @@
1
+ require "net/http"
2
+ require "uri"
3
+
4
+ module ::LeagueOfLegends
5
+ module Request
6
+ class Base
7
+ require 'net/http'
8
+
9
+ def self.options
10
+ @options ||= default_options
11
+ end
12
+
13
+ def self.default_options
14
+ {
15
+ region: 'euw',
16
+ version: dto_class.version
17
+ }
18
+ end
19
+
20
+ def self.dto_class
21
+ raise NotImplementedError, "Children of LeagueOfLegends::Request::Base must implement ::dto_class"
22
+ end
23
+
24
+ def self.version
25
+ dto_class.version
26
+ end
27
+
28
+ def self.region
29
+ options[:region]
30
+ end
31
+
32
+ def self.api_key
33
+ ::LeagueOfLegends::Api.key
34
+ end
35
+
36
+ def initialize options = {}
37
+ @options = self.class.default_options.merge(options)
38
+ end
39
+
40
+ def response
41
+ @response ||= send_request
42
+
43
+ case @response.code.to_i
44
+ when 200 then
45
+ self.class.dto_class.new(@response.body)
46
+ else
47
+ @response.message
48
+ end
49
+ end
50
+
51
+ protected
52
+
53
+ def base_url
54
+ [
55
+ ::LeagueOfLegends::Api.base_url,
56
+ self.class.region,
57
+ self.class.version
58
+ ].join('/')
59
+ end
60
+
61
+ def url_parameters
62
+ [
63
+ "?api_key=#{self.class.api_key}"
64
+ ].join('&')
65
+ end
66
+
67
+
68
+ private
69
+
70
+ def url
71
+ base_url + url_parameters
72
+ end
73
+
74
+ def send_request
75
+ uri = URI.parse url
76
+ Net::HTTP.get_response uri
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,31 @@
1
+ require 'league_of_legends/request/base'
2
+ require 'league_of_legends/dto/player_stats_summary_list'
3
+
4
+ module ::LeagueOfLegends
5
+ module Request
6
+ module Stats
7
+ module BySummoner
8
+ class Summary < ::LeagueOfLegends::Request::Base
9
+
10
+ attr_reader :summoner_id, :options
11
+
12
+ def initialize summoner_id, options = {}
13
+ super(options)
14
+ @summoner_id = summoner_id
15
+ end
16
+
17
+ def self.dto_class
18
+ ::LeagueOfLegends::DTO::PlayerStatsSummaryList
19
+ end
20
+
21
+ protected
22
+
23
+ def base_url
24
+ super + "/stats/by-summoner/#{summoner_id}/summary"
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module LeagueOfLegends
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'league_of_legends/api'
2
+
3
+ describe ::LeagueOfLegends::Api do
4
+
5
+ it "has an API key" do
6
+ expect(described_class.key).to be_an_instance_of String
7
+ expect(described_class.key.length).to eq 36
8
+ end
9
+
10
+ it "has a base url" do
11
+ expect(described_class.base_url).to eq 'https://prod.api.pvp.net/api/lol'
12
+ end
13
+
14
+ end
@@ -18,5 +18,9 @@ describe ::LeagueOfLegends::DTO::AggregatedStats do
18
18
  expect(dto.total_neutral_minions_killed).to eq 339
19
19
  expect(dto.total_assists).to eq 75
20
20
  end
21
+
22
+ it "has a version" do
23
+ expect(described_class.version).to eq 'v1.2'
24
+ end
21
25
 
22
26
  end
@@ -2,4 +2,6 @@ require 'league_of_legends/dto/base'
2
2
 
3
3
  describe ::LeagueOfLegends::DTO::Base do
4
4
 
5
+ let(:dto) { described_class.new }
6
+
5
7
  end
@@ -0,0 +1,62 @@
1
+ require 'league_of_legends/dto/champion_list'
2
+
3
+ describe ::LeagueOfLegends::DTO::ChampionList do
4
+
5
+ json = '{"champions":
6
+ [
7
+ {
8
+ "botMmEnabled": false,
9
+ "defenseRank": 4,
10
+ "attackRank": 8,
11
+ "id": 266,
12
+ "rankedPlayEnabled": true,
13
+ "name": "Aatrox",
14
+ "botEnabled": false,
15
+ "difficultyRank": 6,
16
+ "active": true,
17
+ "freeToPlay": false,
18
+ "magicRank": 3
19
+ },
20
+ {
21
+ "botMmEnabled": false,
22
+ "defenseRank": 4,
23
+ "attackRank": 3,
24
+ "id": 103,
25
+ "rankedPlayEnabled": true,
26
+ "name": "Ahri",
27
+ "botEnabled": false,
28
+ "difficultyRank": 8,
29
+ "active": true,
30
+ "freeToPlay": false,
31
+ "magicRank": 8
32
+ },
33
+ {
34
+ "botMmEnabled": false,
35
+ "defenseRank": 3,
36
+ "attackRank": 5,
37
+ "id": 84,
38
+ "rankedPlayEnabled": true,
39
+ "name": "Akali",
40
+ "botEnabled": false,
41
+ "difficultyRank": 6,
42
+ "active": true,
43
+ "freeToPlay": false,
44
+ "magicRank": 8
45
+ }
46
+ ]}'
47
+ let(:dto){ described_class.new(json) }
48
+
49
+ it "has attributes" do
50
+ expect(dto.champions).to be_an_instance_of Array
51
+ expect(dto.champions.size).to eq 3
52
+
53
+ dto.champions.each do |champion|
54
+ expect(champion).to be_an_instance_of ::LeagueOfLegends::DTO::Champion
55
+ end
56
+ end
57
+
58
+ it "has a version" do
59
+ expect(described_class.version).to eq 'v1.1'
60
+ end
61
+
62
+ end
@@ -0,0 +1,38 @@
1
+ require 'league_of_legends/dto/champion'
2
+
3
+ describe ::LeagueOfLegends::DTO::Champion do
4
+
5
+ let(:attributes) { {
6
+ botMmEnabled: false,
7
+ defenseRank: 4,
8
+ attackRank: 3,
9
+ id: 103,
10
+ rankedPlayEnabled: true,
11
+ name: "Ahri",
12
+ botEnabled: false,
13
+ difficultyRank: 8,
14
+ active: true,
15
+ freeToPlay: false,
16
+ magicRank: 8
17
+ } }
18
+ let(:dto) { described_class.new(attributes) }
19
+
20
+ it "has attributes" do
21
+ expect(dto.bot_mm_enabled).to be_false
22
+ expect(dto.defense_rank).to eq 4
23
+ expect(dto.attack_rank).to eq 3
24
+ expect(dto.id).to eq 103
25
+ expect(dto.ranked_play_enabled).to be_true
26
+ expect(dto.name).to eq "Ahri"
27
+ expect(dto.bot_enabled).to be_false
28
+ expect(dto.difficulty_rank).to eq 8
29
+ expect(dto.active).to be_true
30
+ expect(dto.free_to_play).to be_false
31
+ expect(dto.magic_rank).to eq 8
32
+ end
33
+
34
+ it "has a version" do
35
+ expect(described_class.version).to eq 'v1.1'
36
+ end
37
+
38
+ end
@@ -1,5 +1,4 @@
1
1
  require 'league_of_legends/dto/player_stats_summary_list'
2
- require 'league_of_legends/dto/player_stats_summary_list'
3
2
 
4
3
  describe ::LeagueOfLegends::DTO::PlayerStatsSummaryList do
5
4
 
@@ -55,11 +54,15 @@ describe ::LeagueOfLegends::DTO::PlayerStatsSummaryList do
55
54
 
56
55
  it "has attributes" do
57
56
  expect(dto.summoner_id).to eq 50519866
58
- expect(dto.player_stat_summaries.is_a? Array).to eq true
57
+ expect(dto.player_stat_summaries).to be_an_instance_of Array
59
58
 
60
59
  dto.player_stat_summaries.each do |pss|
61
- expect(pss.is_a? ::LeagueOfLegends::DTO::PlayerStatsSummary).to eq true
60
+ expect(pss).to be_an_instance_of ::LeagueOfLegends::DTO::PlayerStatsSummary
62
61
  end
63
62
  end
63
+
64
+ it "has a version" do
65
+ expect(described_class.version).to eq 'v1.2'
66
+ end
64
67
 
65
68
  end
@@ -22,7 +22,11 @@ describe LeagueOfLegends::DTO::PlayerStatsSummary do
22
22
  expect(dto.wins).to eq 13
23
23
  expect(dto.losses).to eq 0
24
24
  expect(dto.modify_date).to eq Time.new(2013,11,25,14,26,36)
25
- expect(dto.aggregated_stats.is_a?(LeagueOfLegends::DTO::AggregatedStats)).to eq true
25
+ expect(dto.aggregated_stats).to be_an_instance_of ::LeagueOfLegends::DTO::AggregatedStats
26
+ end
27
+
28
+ it "has a version" do
29
+ expect(described_class.version).to eq 'v1.2'
26
30
  end
27
31
 
28
32
  end
@@ -0,0 +1,24 @@
1
+ require 'league_of_legends/request/base'
2
+
3
+ describe ::LeagueOfLegends::Request::Base do
4
+
5
+ it "exposes methods to it's children" do
6
+ class ReqTest < described_class
7
+ def self.version; 'xx'; end
8
+ def self.dto_class; ReqTest; end
9
+ end
10
+ req_test = ReqTest.new
11
+
12
+ expect(ReqTest.respond_to? :options).to be_true
13
+ expect(ReqTest.respond_to? :default_options).to be_true
14
+ expect(ReqTest.respond_to? :dto_class).to be_true
15
+ expect(ReqTest.respond_to? :version).to be_true
16
+ expect(ReqTest.respond_to? :region).to be_true
17
+ expect(ReqTest.respond_to? :api_key).to be_true
18
+ expect(req_test.respond_to? :response).to be_true
19
+
20
+ expect(req_test.respond_to? :url).to be_false
21
+ expect(req_test.respond_to? :send_request).to be_false
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'league_of_legends/request/stats/by_summoner/summary'
2
+
3
+ describe ::LeagueOfLegends::Request::Stats::BySummoner::Summary do
4
+
5
+ let(:request) { described_class.new 50519866 }
6
+
7
+ it "has the required parameters" do
8
+ expect(described_class.dto_class).to eq ::LeagueOfLegends::DTO::PlayerStatsSummaryList
9
+ expect(described_class.region).to eq 'euw'
10
+ expect(described_class.version).to eq 'v1.2'
11
+ expect(described_class.api_key).to be_an_instance_of String
12
+ expect(described_class.api_key.length).to eq 36
13
+
14
+ expect(request.summoner_id).to eq 50519866
15
+ end
16
+
17
+ it "can be sent and get a response" do
18
+ expect(request.response).to be_an_instance_of ::LeagueOfLegends::DTO::PlayerStatsSummaryList
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: league_of_legends
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Orvalho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,15 +55,25 @@ files:
55
55
  - Rakefile
56
56
  - league_of_legends.gemspec
57
57
  - lib/league_of_legends.rb
58
+ - lib/league_of_legends/api.rb
58
59
  - lib/league_of_legends/dto/aggregated_stats.rb
59
60
  - lib/league_of_legends/dto/base.rb
61
+ - lib/league_of_legends/dto/champion.rb
62
+ - lib/league_of_legends/dto/champion_list.rb
60
63
  - lib/league_of_legends/dto/player_stats_summary.rb
61
64
  - lib/league_of_legends/dto/player_stats_summary_list.rb
65
+ - lib/league_of_legends/request/base.rb
66
+ - lib/league_of_legends/request/stats/by_summoner/summary.rb
62
67
  - lib/league_of_legends/version.rb
63
- - spec/dto/aggregated_stats_spec.rb
64
- - spec/dto/base_spec.rb
65
- - spec/dto/player_stats_summary_list_spec.rb
66
- - spec/dto/player_stats_summary_spec.rb
68
+ - spec/league_of_legends/api_spec.rb
69
+ - spec/league_of_legends/dto/aggregated_stats_spec.rb
70
+ - spec/league_of_legends/dto/base_spec.rb
71
+ - spec/league_of_legends/dto/champion_list_spec.rb
72
+ - spec/league_of_legends/dto/champion_spec.rb
73
+ - spec/league_of_legends/dto/player_stats_summary_list_spec.rb
74
+ - spec/league_of_legends/dto/player_stats_summary_spec.rb
75
+ - spec/league_of_legends/request/base_spec.rb
76
+ - spec/league_of_legends/request/stats/by_summoner/summary_spec.rb
67
77
  homepage: http://github.com/forvalho/league_of_legends
68
78
  licenses:
69
79
  - MIT
@@ -89,7 +99,12 @@ signing_key:
89
99
  specification_version: 4
90
100
  summary: Implementation of the LoL API
91
101
  test_files:
92
- - spec/dto/aggregated_stats_spec.rb
93
- - spec/dto/base_spec.rb
94
- - spec/dto/player_stats_summary_list_spec.rb
95
- - spec/dto/player_stats_summary_spec.rb
102
+ - spec/league_of_legends/api_spec.rb
103
+ - spec/league_of_legends/dto/aggregated_stats_spec.rb
104
+ - spec/league_of_legends/dto/base_spec.rb
105
+ - spec/league_of_legends/dto/champion_list_spec.rb
106
+ - spec/league_of_legends/dto/champion_spec.rb
107
+ - spec/league_of_legends/dto/player_stats_summary_list_spec.rb
108
+ - spec/league_of_legends/dto/player_stats_summary_spec.rb
109
+ - spec/league_of_legends/request/base_spec.rb
110
+ - spec/league_of_legends/request/stats/by_summoner/summary_spec.rb