sightstone 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,205 +1,205 @@
1
- require 'sightstone/modules/sightstone_base_module'
2
- require 'sightstone/summoner'
3
- require 'sightstone/masterybook'
4
- require 'sightstone/runebook'
5
- require 'open-uri'
6
-
7
- module Sightstone
8
- # Module to provide calls to the summoner api
9
- class SummonerModule < SightstoneBaseModule
10
-
11
- def initialize(sightstone)
12
- @sightstone = sightstone
13
- end
14
-
15
- # returns a summoner object
16
- # @param name_or_id [Integer, String] name or id of the summoner
17
- # @param optional [Hash] optional arguments: :region => replaces default region
18
- # @ return [Summoner] summoner
19
- def summoner(name_or_id, optional={})
20
- region = optional[:region] || @sightstone.region
21
- uri = if name_or_id.is_a? Integer
22
- "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{name_or_id}"
23
- else
24
- "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/by-name/#{URI::encode(name_or_id)}"
25
- end
26
-
27
- response = _get_api_response(uri)
28
- _parse_response(response) { |resp|
29
- data = JSON.parse(resp)
30
- s = Summoner.new(data.values[0])
31
- if block_given?
32
- yield s
33
- else
34
- return s
35
- end
36
- }
37
- end
38
-
39
- # returns an array of summoner objects
40
- # @param names_or_ids [Array<Integer, String>] names or ids of summoners
41
- # @param optional [Hash] optional arguments: :region => replaces default region
42
- # @return [Hash<(String or Integer), Summoner>] A Hash mapping summoner ids or names to summoner objects
43
- def summoners(names_or_ids, optional={})
44
- return {} if names_or_ids.empty?
45
-
46
- region = optional[:region] || @sightstone.region
47
-
48
- uri = if !names_or_ids[0].is_a? String
49
- "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{names_or_ids.join(',')}"
50
- else
51
- "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/by-name/#{URI::encode(names_or_ids.join(','))}"
52
- end
53
-
54
- response = _get_api_response(uri)
55
- _parse_response(response) { |resp|
56
- data = JSON.parse(resp)
57
- summoners = {}
58
- data.each do |id_or_name, raw_summoner|
59
- summoners[id_or_name] = Summoner.new(raw_summoner)
60
- end
61
-
62
- if block_given?
63
- yield summoners
64
- else
65
- return summoners
66
- end
67
- }
68
- end
69
-
70
-
71
- # returns the names for the ids
72
- # @param ids [Array<Numeric>] ids
73
- # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
74
- # @return [Hash<Numeric, String>] a hash matching each id to the summoners name
75
- def names(ids, optional={})
76
- region = optional[:region] || @sightstone.region
77
- ids = ids.join(',')
78
- uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids}/name"
79
- response = _get_api_response(uri)
80
- _parse_response(response) { |resp|
81
- data = JSON.parse(resp)
82
-
83
- names_hash = Hash.new
84
- data.each do |id, name|
85
- names_hash[id.to_i] = name
86
- end
87
- if block_given?
88
- yield names_hash
89
- else
90
- return names_hash
91
- end
92
- }
93
- end
94
-
95
- # returns the runebook of a summoner
96
- # @param summoner [Summoner, id] summoner object or id of a summoner
97
- # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
98
- # @return [Runebook] runebook of the summoner
99
- def runebook(summoner, optional={})
100
- region = optional[:region] || @sightstone.region
101
- id = if summoner.is_a? Summoner
102
- summoner.id
103
- else
104
- summoner
105
- end
106
- uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/runes"
107
- response = _get_api_response(uri)
108
- _parse_response(response) { |resp|
109
- data = JSON.parse(resp)
110
- book = RuneBook.new(data.values[0])
111
- if block_given?
112
- yield book
113
- else
114
- return book
115
- end
116
- }
117
- end
118
-
119
- # returns the runebook for multiple summoners
120
- # @param summoners [Array<(Summoner, Integer)>] list of summoner objects or ids of summoners
121
- # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
122
- # @return [Hash<Integer, Runebook>] A hash mapping runebooks to the ids of summoners
123
- def runebooks(summoners, optional={})
124
- return {} if summoners.empty?
125
-
126
- region = optional[:region] || @sightstone.region
127
- ids = summoners.collect { |summoner|
128
- if summoner.is_a? Summoner
129
- summoner.id
130
- else
131
- summoner
132
- end
133
- }
134
- uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/runes"
135
- response = _get_api_response(uri)
136
- _parse_response(response) { |resp|
137
- data = JSON.parse(resp)
138
- books = {}
139
- data.each do |key, raw_book|
140
- books[key] = RuneBook.new(raw_book)
141
- end
142
- if block_given?
143
- yield books
144
- else
145
- return books
146
- end
147
- }
148
- end
149
-
150
- # returns the masterybook of a summoner
151
- # @param summoner [Summoner, id] summoner object or id of a summoner
152
- # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
153
- # @return [Masterybook] masterybook of the summoner
154
- def masterybook(summoner, optional={})
155
- region = optional[:region] || @sightstone.region
156
- id = if summoner.is_a? Summoner
157
- summoner.id
158
- else
159
- summoner
160
- end
161
- uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/masteries"
162
- response = _get_api_response(uri)
163
- _parse_response(response) { |resp|
164
- data = JSON.parse(resp)
165
- book = MasteryBook.new(data.values[0])
166
- if block_given?
167
- yield book
168
- else
169
- return book
170
- end
171
- }
172
- end
173
-
174
- # returns the masterybooks for multiple summoners
175
- # @param summoners [Array<(Summoner, Integer)>] list of summoner objects or ids of summoners
176
- # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
177
- # @return [Hash<Integer, Masterybook>] A hash mapping masterybooks to the ids of summoners
178
- def masterybooks(summoners, optional={})
179
- return {} if summoners.empty?
180
- region = optional[:region] || @sightstone.region
181
- ids = summoners.collect { |summoner|
182
- if summoner.is_a? Summoner
183
- summoner.id
184
- else
185
- summoner
186
- end
187
- }
188
-
189
- uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/masteries"
190
- response = _get_api_response(uri)
191
- _parse_response(response) { |resp|
192
- data = JSON.parse(resp)
193
- books = {}
194
- data.each do |key, raw_book|
195
- books[key] = MasteryBook.new(raw_book)
196
- end
197
- if block_given?
198
- yield books
199
- else
200
- return books
201
- end
202
- }
203
- end
204
- end
205
- end
1
+ require 'sightstone/modules/sightstone_base_module'
2
+ require 'sightstone/summoner'
3
+ require 'sightstone/masterybook'
4
+ require 'sightstone/runebook'
5
+ require 'open-uri'
6
+
7
+ module Sightstone
8
+ # Module to provide calls to the summoner api
9
+ class SummonerModule < SightstoneBaseModule
10
+
11
+ def initialize(sightstone)
12
+ @sightstone = sightstone
13
+ end
14
+
15
+ # returns a summoner object
16
+ # @param name_or_id [Integer, String] name or id of the summoner
17
+ # @param optional [Hash] optional arguments: :region => replaces default region
18
+ # @ return [Summoner] summoner
19
+ def summoner(name_or_id, optional={})
20
+ region = optional[:region] || @sightstone.region
21
+ uri = if name_or_id.is_a? Integer
22
+ "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{name_or_id}"
23
+ else
24
+ "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/by-name/#{URI::encode(name_or_id)}"
25
+ end
26
+
27
+ response = _get_api_response(uri)
28
+ _parse_response(response) { |resp|
29
+ data = JSON.parse(resp)
30
+ s = Summoner.new(data.values[0])
31
+ if block_given?
32
+ yield s
33
+ else
34
+ return s
35
+ end
36
+ }
37
+ end
38
+
39
+ # returns an array of summoner objects
40
+ # @param names_or_ids [Array<Integer, String>] names or ids of summoners
41
+ # @param optional [Hash] optional arguments: :region => replaces default region
42
+ # @return [Hash<(String or Integer), Summoner>] A Hash mapping summoner ids or names to summoner objects
43
+ def summoners(names_or_ids, optional={})
44
+ return {} if names_or_ids.empty?
45
+
46
+ region = optional[:region] || @sightstone.region
47
+
48
+ uri = if !names_or_ids[0].is_a? String
49
+ "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{names_or_ids.join(',')}"
50
+ else
51
+ "https://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/by-name/#{URI::encode(names_or_ids.join(','))}"
52
+ end
53
+
54
+ response = _get_api_response(uri)
55
+ _parse_response(response) { |resp|
56
+ data = JSON.parse(resp)
57
+ summoners = {}
58
+ data.each do |id_or_name, raw_summoner|
59
+ summoners[id_or_name] = Summoner.new(raw_summoner)
60
+ end
61
+
62
+ if block_given?
63
+ yield summoners
64
+ else
65
+ return summoners
66
+ end
67
+ }
68
+ end
69
+
70
+
71
+ # returns the names for the ids
72
+ # @param ids [Array<Numeric>] ids
73
+ # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
74
+ # @return [Hash<Numeric, String>] a hash matching each id to the summoners name
75
+ def names(ids, optional={})
76
+ region = optional[:region] || @sightstone.region
77
+ ids = ids.join(',')
78
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids}/name"
79
+ response = _get_api_response(uri)
80
+ _parse_response(response) { |resp|
81
+ data = JSON.parse(resp)
82
+
83
+ names_hash = Hash.new
84
+ data.each do |id, name|
85
+ names_hash[id.to_i] = name
86
+ end
87
+ if block_given?
88
+ yield names_hash
89
+ else
90
+ return names_hash
91
+ end
92
+ }
93
+ end
94
+
95
+ # returns the runebook of a summoner
96
+ # @param summoner [Summoner, id] summoner object or id of a summoner
97
+ # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
98
+ # @return [Runebook] runebook of the summoner
99
+ def runebook(summoner, optional={})
100
+ region = optional[:region] || @sightstone.region
101
+ id = if summoner.is_a? Summoner
102
+ summoner.id
103
+ else
104
+ summoner
105
+ end
106
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/runes"
107
+ response = _get_api_response(uri)
108
+ _parse_response(response) { |resp|
109
+ data = JSON.parse(resp)
110
+ book = RuneBook.new(data.values[0])
111
+ if block_given?
112
+ yield book
113
+ else
114
+ return book
115
+ end
116
+ }
117
+ end
118
+
119
+ # returns the runebook for multiple summoners
120
+ # @param summoners [Array<(Summoner, Integer)>] list of summoner objects or ids of summoners
121
+ # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
122
+ # @return [Hash<Integer, Runebook>] A hash mapping runebooks to the ids of summoners
123
+ def runebooks(summoners, optional={})
124
+ return {} if summoners.empty?
125
+
126
+ region = optional[:region] || @sightstone.region
127
+ ids = summoners.collect { |summoner|
128
+ if summoner.is_a? Summoner
129
+ summoner.id
130
+ else
131
+ summoner
132
+ end
133
+ }
134
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/runes"
135
+ response = _get_api_response(uri)
136
+ _parse_response(response) { |resp|
137
+ data = JSON.parse(resp)
138
+ books = {}
139
+ data.each do |key, raw_book|
140
+ books[key] = RuneBook.new(raw_book)
141
+ end
142
+ if block_given?
143
+ yield books
144
+ else
145
+ return books
146
+ end
147
+ }
148
+ end
149
+
150
+ # returns the masterybook of a summoner
151
+ # @param summoner [Summoner, id] summoner object or id of a summoner
152
+ # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
153
+ # @return [Masterybook] masterybook of the summoner
154
+ def masterybook(summoner, optional={})
155
+ region = optional[:region] || @sightstone.region
156
+ id = if summoner.is_a? Summoner
157
+ summoner.id
158
+ else
159
+ summoner
160
+ end
161
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{id}/masteries"
162
+ response = _get_api_response(uri)
163
+ _parse_response(response) { |resp|
164
+ data = JSON.parse(resp)
165
+ book = MasteryBook.new(data.values[0])
166
+ if block_given?
167
+ yield book
168
+ else
169
+ return book
170
+ end
171
+ }
172
+ end
173
+
174
+ # returns the masterybooks for multiple summoners
175
+ # @param summoners [Array<(Summoner, Integer)>] list of summoner objects or ids of summoners
176
+ # @param optional [Hash<Symbol, String>] optional arguments: :region => replaces default region
177
+ # @return [Hash<Integer, Masterybook>] A hash mapping masterybooks to the ids of summoners
178
+ def masterybooks(summoners, optional={})
179
+ return {} if summoners.empty?
180
+ region = optional[:region] || @sightstone.region
181
+ ids = summoners.collect { |summoner|
182
+ if summoner.is_a? Summoner
183
+ summoner.id
184
+ else
185
+ summoner
186
+ end
187
+ }
188
+
189
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.3/summoner/#{ids.join(',')}/masteries"
190
+ response = _get_api_response(uri)
191
+ _parse_response(response) { |resp|
192
+ data = JSON.parse(resp)
193
+ books = {}
194
+ data.each do |key, raw_book|
195
+ books[key] = MasteryBook.new(raw_book)
196
+ end
197
+ if block_given?
198
+ yield books
199
+ else
200
+ return books
201
+ end
202
+ }
203
+ end
204
+ end
205
+ end
@@ -1,42 +1,42 @@
1
- require 'sightstone/modules/sightstone_base_module'
2
- require 'sightstone/summoner'
3
- require 'sightstone/team'
4
-
5
- module Sightstone
6
- # module to make calls to the team api
7
- class TeamModule < SightstoneBaseModule
8
- def initialize(sightstone)
9
- @sightstone = sightstone
10
- end
11
-
12
- # call to receive all teams for a summoner
13
- # @param [Summoner, Fixnum] summoner summoner object or id of a summoner
14
- # @param optional [Hash] optional arguments: :region => replaces default region
15
- # @ return [Array<Team>] An array containing all teams of the given summoner
16
- def teams(summoner, optional={})
17
- region = optional[:region] || @sightstone.region
18
- id = if summoner.is_a? Summoner
19
- summoner.id
20
- else
21
- summoner
22
- end
23
-
24
- uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.2/team/by-summoner/#{id}"
25
-
26
- response = _get_api_response(uri)
27
- _parse_response(response) { |resp|
28
- data = JSON.parse(resp)
29
- teams = []
30
- data.each do |team|
31
- teams << Team.new(team)
32
- end
33
- if block_given?
34
- yield teams
35
- else
36
- return teams
37
- end
38
- }
39
- end
40
-
41
- end
42
- end
1
+ require 'sightstone/modules/sightstone_base_module'
2
+ require 'sightstone/summoner'
3
+ require 'sightstone/team'
4
+
5
+ module Sightstone
6
+ # module to make calls to the team api
7
+ class TeamModule < SightstoneBaseModule
8
+ def initialize(sightstone)
9
+ @sightstone = sightstone
10
+ end
11
+
12
+ # call to receive all teams for a summoner
13
+ # @param [Summoner, Fixnum] summoner summoner object or id of a summoner
14
+ # @param optional [Hash] optional arguments: :region => replaces default region
15
+ # @ return [Array<Team>] An array containing all teams of the given summoner
16
+ def teams(summoner, optional={})
17
+ region = optional[:region] || @sightstone.region
18
+ id = if summoner.is_a? Summoner
19
+ summoner.id
20
+ else
21
+ summoner
22
+ end
23
+
24
+ uri = "https://prod.api.pvp.net/api/lol/#{region}/v2.2/team/by-summoner/#{id}"
25
+
26
+ response = _get_api_response(uri)
27
+ _parse_response(response) { |resp|
28
+ data = JSON.parse(resp)
29
+ teams = []
30
+ data.each do |team|
31
+ teams << Team.new(team)
32
+ end
33
+ if block_given?
34
+ yield teams
35
+ else
36
+ return teams
37
+ end
38
+ }
39
+ end
40
+
41
+ end
42
+ end