demacia 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Demacia.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+ require 'openssl'
4
+ require 'htmlentities'
5
+ require 'demacia/Summoner.rb'
6
+
7
+ module Demacia
8
+ class Caller
9
+ attr_accessor :api_key, :entry_point, :api_suffix, :region
10
+
11
+ # Initializes the Caller with an api key (needed)
12
+ # Params:
13
+ # +key+:: the api key provided by riot
14
+ # +region+:: the region where the requests have to be made. Can be one of the following : tr,br,na,euw,eune
15
+ def initialize(key, region)
16
+ @api_key = key
17
+ @region = region
18
+ @api_suffix = "?api_key=" + @api_key
19
+ @entry_point = "http://prod.api.pvp.net/api/lol/" + @region +"/v1.1/"
20
+ end
21
+
22
+ # Gets a summoner's info from riot's API based on its name
23
+ # Params:
24
+ # +name+:: The summoner name (nickname). NOT the account name
25
+ def summoner_by_name(name)
26
+ encoded_name = HTMLEntities.new.encode name
27
+ summoner = Demacia::Summoner.new(@entry_point+"summoner/by-name/"+encoded_name+@api_suffix)
28
+ end
29
+
30
+ # Gets a summoner's info from riot's API based on its id
31
+ # Params:
32
+ # +id+:: The summoner id from riot's api
33
+ def summoner_by_id(id)
34
+ summoner = Demacia::Summoner.new(@entry_point+"summoner/"+id+@api_suffix)
35
+ end
36
+
37
+ # Gets a summoner's info and masteries from riot's API based on its name
38
+ # Params:
39
+ # +name+:: The summoner name from riot's api
40
+ def summoner_masteries_by_name(name)
41
+ summoner = summoner_by_name(name)
42
+ summoner.load_masteries(@entry_point+"summoner/"+summoner.id.to_s+"/masteries"+@api_suffix)
43
+ summoner
44
+ end
45
+
46
+ # Gets a summoner's info and masteries from riot's API based on its id
47
+ # Params:
48
+ # +id+:: The summoner id from riot's api
49
+ def summoner_masteries_by_id(id)
50
+ summoner = summoner_by_id(id)
51
+ summoner.load_masteries(@entry_point+"summoner/"+summoner.id.to_s+"/masteries"+@api_suffix)
52
+ summoner
53
+ end
54
+
55
+ # Gets a summoner's info and runes from riot's API based on its name
56
+ # Params:
57
+ # +name+:: The summoner name from riot's api
58
+ def summoner_runes_by_name(name)
59
+ summoner = summoner_by_name(name)
60
+ summoner.load_runes(@entry_point+"summoner/"+summoner.id.to_s+"/runes"+@api_suffix)
61
+ summoner
62
+ end
63
+
64
+ # Gets a summoner's info and runes from riot's API based on its id
65
+ # Params:
66
+ # +id+:: The summoner id from riot's api
67
+ def summoner_runes_by_id(id)
68
+ summoner = summoner_by_id(id)
69
+ summoner.load_runes(@entry_point+"summoner/"+summoner.id.to_s+"/runes"+@api_suffix)
70
+ summoner
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ module Demacia
2
+ # Represents a rune page
3
+ class Page
4
+ attr_accessor :name, :current, :talents
5
+
6
+ # Constructor, initializes the page with a name and a current
7
+ # Params:
8
+ # +name+:: The page's name
9
+ # +current+:: A boolean that tells us if this is the currently used page
10
+ def initialize(name, current)
11
+ @name = name
12
+ @current = current
13
+ talents = Array.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Demacia
2
+ class Rune
3
+ attr_accessor :id, :description, :name, :tier, :slot_id
4
+
5
+ def initialize(id, description, name, tier, slot_id)
6
+ @id = id
7
+ @name = name
8
+ @tier = tier
9
+ @description = description
10
+ @slot_id = slot_id
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+ require 'openssl'
4
+ require 'Page'
5
+ require 'Talent'
6
+ require 'Rune'
7
+
8
+ module Demacia
9
+ class Summoner
10
+ attr_accessor :masteries, :runes, :profile_icon, :name, :id, :level
11
+
12
+ # Class constructor, gets the basic Summoner info from riot api. Does not auto load the masteries nor runes
13
+ # Params:
14
+ # +query_string+:: The full query string forged from name, entry point and method
15
+ def initialize(query_string)
16
+ answer_string = open(query_string).read
17
+ parsed_answer = JSON.parse(answer_string)
18
+ puts parsed_answer
19
+ @level = parsed_answer["summonerLevel"]
20
+ @profile_icon = parsed_answer["profileIconId"]
21
+ @name = parsed_answer["name"]
22
+ @id = parsed_answer["id"]
23
+ puts parsed_answer["id"]
24
+ end
25
+
26
+ # Loads masteries based on a query to query string.
27
+ # Params:
28
+ # +query_string+:: the full query string forged from name, entry point and method
29
+ def load_masteries(query_string)
30
+ @masteries = Array.new
31
+ answer_string = open(query_string).read
32
+ parsed_answer = JSON.parse(answer_string)
33
+ parsed_answer["pages"].each do |key, page|
34
+ page_buffer = Demacia::Page.new(page["name"], page["current"])
35
+ page["talents"].each do |talent_key, talent|
36
+ talent_buffer = Demacia::Talent.new(talent["id"], talent["name"], talent["rank"])
37
+ page_buffer.talents << talent_buffer
38
+ end
39
+ @masteries << page_buffer
40
+ end
41
+ end
42
+
43
+ # Loads runes based on a query to query string. The runes are sorted by their slot id
44
+ # Params:
45
+ # +query_string+:: the full query string forged from name, entry point and method
46
+ def load_runes(query_string)
47
+ @runes = Array.new
48
+ answer_string = open(query_string).read
49
+ parsed_answer = JSON.parse(answer_string)
50
+
51
+ parsed_answer["pages"].each do |key, page|
52
+ rune_buffer = page["rune"]
53
+ rune_out = Rune.new(rune_buffer["id"],rune_buffer["description"],rune_buffer["name"],rune_buffer["tier"], page["runeSlotId"])
54
+ @runes << rune_out
55
+ end
56
+ @runes.sort { |a, b| a.slot_id <=> b.slot_id }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ module Demacia
2
+ # Represents a LoL talent in a page
3
+ class Talent
4
+ attr_accessor :id, :name, :rank
5
+
6
+ # Constructor, initializes the talent
7
+ # Params:
8
+ # +id+:: The talent's internal id provided by riot
9
+ # +name+:: The talent's name
10
+ # +rank+:: The talent's rank, aka its level in the talents page (1-2-3-4)
11
+ def initialize(id, name, rank)
12
+ @id = id
13
+ @name = name
14
+ @rank = rank
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: demacia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paul Forti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: For Demacia!
15
+ email: paul.forti@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/Demacia.rb
21
+ - lib/demacia/Page.rb
22
+ - lib/demacia/Rune.rb
23
+ - lib/demacia/Summoner.rb
24
+ - lib/demacia/Talent.rb
25
+ homepage: http://rubygems.org/gems/demacia
26
+ licenses:
27
+ - MIT
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.24
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Demacia helps ruby devs get data from the League of Legends API
50
+ test_files: []