lol_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.guardfile +11 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +10 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +10 -0
  9. data/lib/lol_api/client.rb +105 -0
  10. data/lib/lol_api/configuration.rb +15 -0
  11. data/lib/lol_api/connection.rb +32 -0
  12. data/lib/lol_api/types/champion.rb +95 -0
  13. data/lib/lol_api/types/dtos/image.rb +33 -0
  14. data/lib/lol_api/types/dtos/info.rb +25 -0
  15. data/lib/lol_api/types/dtos/participant.rb +419 -0
  16. data/lib/lol_api/types/dtos/participant_identity.rb +19 -0
  17. data/lib/lol_api/types/dtos/passive.rb +27 -0
  18. data/lib/lol_api/types/dtos/player.rb +22 -0
  19. data/lib/lol_api/types/dtos/recommended.rb +38 -0
  20. data/lib/lol_api/types/dtos/skin.rb +20 -0
  21. data/lib/lol_api/types/dtos/spell.rb +98 -0
  22. data/lib/lol_api/types/dtos/stat.rb +19 -0
  23. data/lib/lol_api/types/dtos/team.rb +57 -0
  24. data/lib/lol_api/types/dtos/timeline.rb +180 -0
  25. data/lib/lol_api/types/history_match.rb +61 -0
  26. data/lib/lol_api/types/item.rb +126 -0
  27. data/lib/lol_api/types/mastery.rb +39 -0
  28. data/lib/lol_api/types/match.rb +43 -0
  29. data/lib/lol_api/types/summoner.rb +26 -0
  30. data/lib/lol_api/types/summoner_masteries.rb +66 -0
  31. data/lib/lol_api/types/summoner_runes.rb +69 -0
  32. data/lib/lol_api/utils/inspectable.rb +10 -0
  33. data/lib/lol_api/version.rb +3 -0
  34. data/lib/lol_api.rb +12 -0
  35. data/lol_api.gemspec +29 -0
  36. data/spec/champion_spec.rb +48 -0
  37. data/spec/client_spec.rb +67 -0
  38. data/spec/delegation_spec.rb +5 -0
  39. data/spec/factories.rb +43 -0
  40. data/spec/fixtures/champion.json +843 -0
  41. data/spec/fixtures/history.json +127 -0
  42. data/spec/fixtures/item.json +62 -0
  43. data/spec/fixtures/mastery.json +25 -0
  44. data/spec/fixtures/match.json +12167 -0
  45. data/spec/fixtures/match_details.json +13548 -0
  46. data/spec/fixtures/summoner.json +7 -0
  47. data/spec/fixtures/summoner_masteries.json +143 -0
  48. data/spec/fixtures/summoner_runes.json +132 -0
  49. data/spec/history_spec.rb +280 -0
  50. data/spec/item_spec.rb +96 -0
  51. data/spec/mastery_spec.rb +27 -0
  52. data/spec/match_details_spec.rb +72 -0
  53. data/spec/participant_spec.rb +153 -0
  54. data/spec/participant_timeline_spec.rb +80 -0
  55. data/spec/spec_helper.rb +22 -0
  56. data/spec/summoner_spec.rb +120 -0
  57. data/spec/team_spec.rb +38 -0
  58. data/spec/timeline_spec.rb +101 -0
  59. metadata +236 -0
@@ -0,0 +1,180 @@
1
+ module LolApi
2
+ class Timeline
3
+ attr_reader :raw_timeline
4
+
5
+ def initialize(raw_timeline)
6
+ @raw_timeline = raw_timeline
7
+ end
8
+
9
+ def interval
10
+ @raw_timeline['frameInterval']
11
+ end
12
+
13
+ def frames
14
+ if frames = @raw_timeline['frames']
15
+ frames.map { |x| Frame.new(x) }
16
+ end
17
+ end
18
+ end
19
+
20
+ class Frame
21
+ attr_reader :raw_frame
22
+
23
+ def initialize(raw_frame)
24
+ @raw_frame = raw_frame
25
+ end
26
+
27
+ def events
28
+ if events = @raw_frame['events']
29
+ events.map { |x| Event.new(x) }
30
+ else
31
+ []
32
+ end
33
+ end
34
+
35
+ def participant_frames
36
+ if frames = @raw_frame['participantFrames']
37
+ frames.map{|x| ParticipantFrame.new(x[1])}
38
+ else
39
+ []
40
+ end
41
+ end
42
+
43
+ def timestamp
44
+ @raw_frame['timestamp']
45
+ end
46
+ end
47
+
48
+ class Event
49
+ attr_reader :raw_event
50
+
51
+ def initialize(raw_event)
52
+ @raw_event = raw_event
53
+ end
54
+
55
+ def assisting_participant_ids
56
+ raw_event['assistingParticipantId']
57
+ end
58
+
59
+ def building_type
60
+ raw_event['buildingType']
61
+ end
62
+
63
+ def creator_id
64
+ raw_event['creatorId']
65
+ end
66
+
67
+ def event_type
68
+ raw_event['eventType']
69
+ end
70
+
71
+ def item_after
72
+ raw_event['itemAfter']
73
+ end
74
+
75
+ def item_before
76
+ raw_event['itemBefore']
77
+ end
78
+
79
+ def item_id
80
+ raw_event['itemId']
81
+ end
82
+
83
+ def killer_id
84
+ raw_event['killerId']
85
+ end
86
+
87
+ def lane_type
88
+ raw_event['laneType']
89
+ end
90
+
91
+ def level_up_type
92
+ raw_event['levelUpType']
93
+ end
94
+
95
+ def monster_type
96
+ raw_event['monsterType']
97
+ end
98
+
99
+ def participant_id
100
+ raw_event['participantId']
101
+ end
102
+
103
+ def position
104
+ raw_event['position']
105
+ end
106
+
107
+ def skill_slot
108
+ raw_event['skillSlot']
109
+ end
110
+
111
+ def team_id
112
+ raw_event['teamId']
113
+ end
114
+
115
+ def timestamp
116
+ raw_event['timestamp']
117
+ end
118
+
119
+ def tower_type
120
+ raw_event['towerType']
121
+ end
122
+
123
+ def victim_id
124
+ raw_event['victimId']
125
+ end
126
+
127
+ def ward_type
128
+ raw_event['wardType']
129
+ end
130
+ end
131
+
132
+ class ParticipantFrame
133
+ attr_reader :raw_frame
134
+
135
+ def initialize(raw_frame)
136
+ @raw_frame = raw_frame
137
+ end
138
+
139
+ def current_gold
140
+ @raw_frame['currentGold']
141
+ end
142
+
143
+ def jungle_minions_killed
144
+ @raw_frame['jungleMinionsKilled']
145
+ end
146
+
147
+ def level
148
+ @raw_frame['level']
149
+ end
150
+
151
+ def minions_killed
152
+ @raw_frame['minionsKilled']
153
+ end
154
+
155
+ def participant_id
156
+ @raw_frame['participantId']
157
+ end
158
+
159
+ def position
160
+ Position.new(@raw_frame['position'])
161
+ end
162
+
163
+ def total_gold
164
+ @raw_frame['totalGold']
165
+ end
166
+
167
+ def xp
168
+ @raw_frame['xp']
169
+ end
170
+ end
171
+
172
+ class Position
173
+
174
+ def initialize(raw_pos)
175
+ @x = raw_pos['x']
176
+ @y = raw_pos['y']
177
+ end
178
+ end
179
+
180
+ end
@@ -0,0 +1,61 @@
1
+ require 'lol_api/types/dtos/participant_identity'
2
+ require 'lol_api/types/dtos/participant'
3
+ module LolApi
4
+ class HistoryMatch
5
+ attr_reader :raw_match
6
+
7
+ def initialize(raw_match)
8
+ @raw_match = raw_match
9
+ end
10
+
11
+ def map_id
12
+ raw_match['mapId']
13
+ end
14
+
15
+ def match_creation
16
+ raw_match['matchCreation']
17
+ end
18
+
19
+ def match_duration
20
+ raw_match['matchDuration']
21
+ end
22
+
23
+ def match_id
24
+ raw_match['matchId']
25
+ end
26
+
27
+ def match_version
28
+ raw_match['matchVersion']
29
+ end
30
+
31
+ def participant_identities
32
+ if participants = raw_match['participantIdentities']
33
+ participants.map do |participant|
34
+ ParticipantIdentity.new(participant)
35
+ end
36
+ end
37
+ end
38
+
39
+ def participants
40
+ if participants = raw_match['participants']
41
+ participants.map do |participant|
42
+ Participant.new(participant)
43
+ end
44
+ end
45
+ end
46
+
47
+ def queue_type
48
+ raw_match['queueType']
49
+ end
50
+
51
+ def region
52
+ raw_match['region']
53
+ end
54
+
55
+ def season
56
+ raw_match['season']
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,126 @@
1
+ require 'lol_api/types/dtos/image'
2
+ module LolApi
3
+ class Item
4
+ attr_reader :raw_item
5
+
6
+ def initialize(raw_item)
7
+ @raw_item = raw_item
8
+ end
9
+
10
+ def id
11
+ raw_item['id']
12
+ end
13
+
14
+ def name
15
+ raw_item['name']
16
+ end
17
+
18
+ def plain_text
19
+ raw_item['plaintext']
20
+ end
21
+
22
+ def colloq
23
+ raw_item['colloq']
24
+ end
25
+
26
+ def consume_on_full
27
+ raw_item['consumeOnFull']
28
+ end
29
+
30
+ def consumed
31
+ raw_item['consumed']
32
+ end
33
+
34
+ def depth
35
+ raw_item['depth']
36
+ end
37
+
38
+ def description
39
+ raw_item['description']
40
+ end
41
+
42
+ def from
43
+ raw_item['from']
44
+ end
45
+
46
+ def gold
47
+ LolApi::Gold.new(raw_item['gold'])
48
+ end
49
+
50
+ def group
51
+ raw_item['group']
52
+ end
53
+
54
+ def hide_from_all
55
+ raw_item['hideFromAll']
56
+ end
57
+
58
+ def image
59
+ LolApi::Image.new(raw_item['image'])
60
+ end
61
+
62
+ def in_store
63
+ raw_item['inStore']
64
+ end
65
+
66
+ def into
67
+ raw_item['into']
68
+ end
69
+
70
+ def maps
71
+ raw_item['maps']
72
+ end
73
+
74
+ def required_champion
75
+ raw_item['requiredChampion']
76
+ end
77
+
78
+ def rune
79
+ raw_item['rune']
80
+ end
81
+
82
+ def sanitized_description
83
+ raw_item['sanitizedDescription']
84
+ end
85
+
86
+ def special_recipe
87
+ raw_item['specialRecipe']
88
+ end
89
+
90
+ def stacks
91
+ raw_item['stacks']
92
+ end
93
+
94
+ def stats
95
+ raw_item['stats']
96
+ end
97
+
98
+ def tags
99
+ raw_item['tags']
100
+ end
101
+ end
102
+
103
+ class Gold
104
+ attr_reader :raw_gold
105
+
106
+ def initialize(raw_gold)
107
+ @raw_gold = raw_gold
108
+ end
109
+
110
+ def base
111
+ raw_gold['base']
112
+ end
113
+
114
+ def purchasable
115
+ raw_gold['purchasable']
116
+ end
117
+
118
+ def sell
119
+ raw_gold['sell']
120
+ end
121
+
122
+ def total
123
+ raw_gold['total']
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,39 @@
1
+ require 'lol_api/types/dtos/image'
2
+
3
+ module LolApi
4
+ class Mastery
5
+ attr_reader :raw_mastery
6
+
7
+ def initialize(raw_mastery)
8
+ @raw_mastery = raw_mastery
9
+ end
10
+
11
+ def id
12
+ raw_mastery['id']
13
+ end
14
+
15
+ def name
16
+ raw_mastery['name']
17
+ end
18
+
19
+ def description
20
+ raw_mastery['description']
21
+ end
22
+
23
+ def sanitized_description
24
+ raw_mastery['sanitizedDescription']
25
+ end
26
+
27
+ def image
28
+ Image.new(raw_mastery['image']) if raw_mastery['image']
29
+ end
30
+
31
+ def ranks
32
+ raw_mastery['ranks']
33
+ end
34
+
35
+ def prereq
36
+ raw_mastery['prereq'].to_i
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ require 'lol_api/types/dtos/team'
2
+ require 'lol_api/types/dtos/timeline'
3
+ require 'lol_api/types/history_match'
4
+
5
+ module LolApi
6
+ class Match < HistoryMatch
7
+ def match_type
8
+ raw_match['matchType']
9
+ end
10
+
11
+ def match_mode
12
+ raw_match['matchMode']
13
+ end
14
+
15
+ def teams
16
+ if teams = raw_match['teams']
17
+ teams.map { |e| Team.new(e) }
18
+ end
19
+ end
20
+
21
+ def timeline
22
+ Timeline.new(raw_match['timeline'])
23
+ end
24
+
25
+ def blue_team
26
+ [ teams[0], participants.select { |x| x.team_id == 100 } ]
27
+ end
28
+
29
+ def purple_team
30
+ [ teams[1], participants.select { |x| x.team_id == 200 } ]
31
+ end
32
+
33
+ def ward_placements
34
+ timeline.frames.map do |f|
35
+ f.events.select do |e|
36
+ e.event_type == "WARD_PLACED"
37
+ end
38
+ end.flatten
39
+ end
40
+
41
+ end
42
+ end
43
+
@@ -0,0 +1,26 @@
1
+
2
+ module LolApi
3
+ class Summoner
4
+ attr_reader :raw_summoner
5
+
6
+ def initialize(raw_summoner)
7
+ @raw_summoner = raw_summoner
8
+ end
9
+
10
+ def id
11
+ raw_summoner['id']
12
+ end
13
+ def name
14
+ raw_summoner['name']
15
+ end
16
+ def profile_icon_id
17
+ raw_summoner['profileIconId']
18
+ end
19
+ def revision_date
20
+ raw_summoner['revisionDate']
21
+ end
22
+ def level
23
+ raw_summoner['summonerLevel']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,66 @@
1
+
2
+ module LolApi
3
+ class SummonerMasteries
4
+ attr_reader :raw_masteries
5
+
6
+ def initialize(raw_masteries)
7
+ @raw_masteries = raw_masteries
8
+ end
9
+
10
+ def pages
11
+ if pages = raw_masteries['pages']
12
+ pages.map do |page|
13
+ MasteryPage.new(page)
14
+ end
15
+ end
16
+ end
17
+
18
+ def summoner_id
19
+ raw_masteries['summonerId']
20
+ end
21
+ end
22
+
23
+ class MasteryPage
24
+ attr_reader :raw_page
25
+
26
+ def initialize(raw_page)
27
+ @raw_page = raw_page
28
+ end
29
+
30
+ def current
31
+ raw_page['current']
32
+ end
33
+
34
+ def id
35
+ raw_page['id']
36
+ end
37
+
38
+ def masteries
39
+ if masteries = raw_page['masteries']
40
+ masteries.map do |mastery|
41
+ MasteryItem.new(mastery)
42
+ end
43
+ end
44
+ end
45
+
46
+ def name
47
+ raw_page['name']
48
+ end
49
+ end
50
+
51
+ class MasteryItem
52
+ attr_reader :raw_item
53
+
54
+ def initialize(raw_item)
55
+ @raw_item = raw_item
56
+ end
57
+
58
+ def id
59
+ raw_item['id']
60
+ end
61
+
62
+ def rank
63
+ raw_item['rank']
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,69 @@
1
+ module LolApi
2
+ class SummonerRunes
3
+ attr_reader :raw_runes
4
+
5
+ def initialize(raw_runes)
6
+ @raw_runes = raw_runes
7
+ end
8
+
9
+ def pages
10
+ if pages = raw_runes['pages']
11
+ pages.map do |p|
12
+ RunePage.new(p)
13
+ end
14
+ end
15
+ end
16
+
17
+ def summoner_id
18
+ raw_runes['summonerId']
19
+ end
20
+
21
+ end
22
+
23
+ class RunePage
24
+ attr_reader :raw_page
25
+
26
+ def initialize(raw_page)
27
+ @raw_page = raw_page
28
+ end
29
+
30
+ def current
31
+ raw_page['current']
32
+ end
33
+
34
+ def id
35
+ raw_page['id']
36
+ end
37
+
38
+ def name
39
+ raw_page['name']
40
+ end
41
+
42
+ def runes
43
+ if runes = raw_page['slots']
44
+ runes.map do |s|
45
+ SlottedRune.new(s)
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ class SlottedRune
52
+ attr_reader :raw_rune
53
+
54
+ def initialize(raw_rune)
55
+ @raw_rune = raw_rune
56
+ end
57
+
58
+ def id
59
+ raw_rune['runeId']
60
+ end
61
+
62
+ def slot_id
63
+ raw_rune['runeSlotId']
64
+ end
65
+
66
+ end
67
+
68
+
69
+ end
@@ -0,0 +1,10 @@
1
+ module LolApi
2
+ module Utils
3
+ module Inspectable
4
+ # @private
5
+ def inspect
6
+ "#<#{self.class.name}:0x#{(object_id << 1).to_s(16)}>"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module LolApi
2
+ VERSION = "1.0.0"
3
+ end
data/lib/lol_api.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'lol_api/version'
2
+ require 'lol_api/client'
3
+
4
+ module LolApi
5
+ extend SingleForwardable
6
+ def_delegators :client, :configure, :champion_by_id, :champions, :item_by_id, :items, :masteries, :mastery_by_id, :match_history,
7
+ :history_by_id, :match_details, :summoner_by_name, :summoner_by_id, :summoner_masteries, :summoner_runes
8
+
9
+ def self.client
10
+ @client ||= Client.new
11
+ end
12
+ end
data/lol_api.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lol_api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "lol_api"
8
+ gem.version = LolApi::VERSION
9
+ gem.authors = ["eankorins"]
10
+ gem.email = ["eankorins@gmail.com"]
11
+ gem.summary = "Gem for League of Legends API"
12
+ gem.description = "Utilizes exposed methods of the League of Legends public API"
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files -z`.split("\x0")
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'faraday', '~> 0.8.4'
22
+ gem.add_dependency 'faraday_middleware', '~> 0.9.0'
23
+ gem.add_development_dependency 'rake', '~> 10.0.3'
24
+ gem.add_development_dependency 'minitest', '~> 4.5.0'
25
+ gem.add_development_dependency 'webmock', '~> 1.9.0'
26
+ gem.add_development_dependency "rspec"
27
+ gem.add_development_dependency "guard"
28
+ gem.add_development_dependency "guard-rspec"
29
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe LolApi::Champion do
4
+ before do
5
+ @champion = FactoryGirl.build(:champion)
6
+ end
7
+ subject { @champion }
8
+
9
+ it { should be_kind_of(LolApi::Champion)}
10
+ it { should respond_to(:id) }
11
+ it { should respond_to(:name) }
12
+ it { should respond_to(:title) }
13
+ it { should respond_to(:stats) }
14
+ it { should respond_to(:key) }
15
+ it { should respond_to(:ally_tips) }
16
+ it { should respond_to(:enemy_tips) }
17
+ it { should respond_to(:blurb) }
18
+ it { should respond_to(:image) }
19
+ it { should respond_to(:info) }
20
+ it { should respond_to(:lore) }
21
+ it { should respond_to(:partype) }
22
+ it { should respond_to(:passive) }
23
+ it { should respond_to(:recommended) }
24
+ it { should respond_to(:skins) }
25
+ it { should respond_to(:spells) }
26
+ it { should respond_to(:stats) }
27
+ it { should respond_to(:tags) }
28
+
29
+ describe "must return" do
30
+ its(:id) { should eq 35}
31
+ its(:name) { should eq "Shaco" }
32
+ its(:title) {should eq "the Demon Jester"}
33
+ its(:key) { should eq "Shaco" }
34
+ its(:ally_tips) { should_not be_empty }
35
+ its(:enemy_tips) { should_not be_empty }
36
+ its(:blurb) { should include("Most would say that death isn't funny.") }
37
+ its(:image) { should be_kind_of(LolApi::Image) }
38
+ its(:info) { should be_kind_of(LolApi::Info) }
39
+ its(:lore) { should include("It isn't, unless you're Shaco - then it's hysterical.")}
40
+ its(:partype) { should eq "Mana" }
41
+ its(:passive) { should be_kind_of(LolApi::Passive) }
42
+ its(:recommended) { should_not be_empty }
43
+ its(:skins) { should_not be_empty }
44
+ its(:spells) { should_not be_empty }
45
+ its(:stats) { should_not be_empty }
46
+ its(:tags) { should include("Assassin")}
47
+ end
48
+ end