sightstone 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 587af5785d237527f2a8e316356ce84b8c39e544
4
- data.tar.gz: 3a2cb00c736b6deb110b2f395a0d737e69e689fe
3
+ metadata.gz: 1566ea45d97a16bfb02822e9296b299eac3652ec
4
+ data.tar.gz: db3c4c40c0118e3f40ad8248a74cfc60deb7436b
5
5
  SHA512:
6
- metadata.gz: e1e208bec4e4c1621cab7a4715ce688e49070366186e7a8d08b7d92039e153643f2ddcbb25b79a8777eed6c8961790531f6516a4ecb44fed4f8938e6047f5008
7
- data.tar.gz: b4f3c49ea4792c541c5531e576ecc3128b47fd6c7ba19dd7b84f20ad294a002fd011d0f35e565f402f5801043531850795f10b1da80577d0e692abf00dcd98ec
6
+ metadata.gz: c4e405bead9f20bd1d485975f671adedb8aea7ee5c10e7b60a6f4428293a3689f4c5d85fe86d1e3dc124cb0839a8bea3efa8cac60dd0f8401d2069b4163728d3
7
+ data.tar.gz: 0c18e8f96c8a328ccc2aea80cf463be5ec6c18c82a5c8a91639bf9ae5a76da11ebe71d3c0a1aa757ba2f5b0fe7a5b3c41ab29850f8024f22d15049b56d997cfb
@@ -1,13 +1,16 @@
1
1
  require 'sightstone/champion'
2
+ require 'sightstone/modules/sightstone_base_module'
2
3
 
3
- class ChampionModule
4
+ class ChampionModule < SightstoneBaseModule
4
5
 
5
6
  def initialize(sightstone)
6
7
  @sightstone = sightstone
7
8
  end
8
9
 
9
- def champions(free_to_play=false)
10
- uri = "https://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/champion"
10
+ def champions(, optional={})
11
+ region = optional[:region] || @sightstone.region
12
+ free_to_play = optional[:free_to_play]
13
+ uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/champion"
11
14
  response = _get_api_response(uri, {'freeToPlay' => free_to_play})
12
15
  puts response
13
16
 
@@ -20,28 +23,4 @@ class ChampionModule
20
23
  return champions
21
24
  }
22
25
  end
23
-
24
- private
25
- def _get_api_response(uri, headers={})
26
- params = {'api_key' => @sightstone.api_key}.merge headers
27
- RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
28
- rescue SocketError => e
29
- nil
30
-
31
- end
32
-
33
- def _parse_response(response, &block)
34
- response_code = if response.nil?
35
- 500
36
- else
37
- response.code
38
- end
39
-
40
- if response_code == 200
41
- block.call(response.body)
42
- elsif response_code == 500
43
- raise Sightstone::SightstoneConnectionException
44
- end
45
- end
46
-
47
26
  end
@@ -1,19 +1,21 @@
1
+ require 'sightstone/modules/sightstone_base_module'
1
2
  require 'sightstone/summoner'
2
3
  require 'sightstone/match_history'
3
4
 
4
- class GameModule
5
+ class GameModule < SightstoneBaseModule
5
6
 
6
7
  def initialize(sightstone)
7
8
  @sightstone = sightstone
8
9
  end
9
10
 
10
- def recent(summoner)
11
+ def recent(summoner, optional={})
12
+ region = optional[:region] || @sightstone.region
11
13
  id = if summoner.is_a? Summoner
12
14
  summoner.id
13
15
  else
14
16
  summoner
15
17
  end
16
- uri = "http://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/game/by-summoner/#{id}/recent"
18
+ uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/game/by-summoner/#{id}/recent"
17
19
 
18
20
  response = _get_api_response(uri)
19
21
  _parse_response(response) { |resp|
@@ -22,29 +24,5 @@ class GameModule
22
24
  }
23
25
  end
24
26
 
25
- private
26
-
27
- def _get_api_response(uri)
28
- params = {'api_key' => @sightstone.api_key}
29
- RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
30
- rescue SocketError => e
31
- nil
32
-
33
- end
34
-
35
- def _parse_response(response, &block)
36
- response_code = if response.nil?
37
- 500
38
- else
39
- response.code
40
- end
41
-
42
- if response_code == 200
43
- block.call(response.body)
44
- elsif response_code == 404
45
- raise Sightstone::SummonerNotFoundException
46
- elsif response_code == 500
47
- raise Sightstone::SightstoneConnectionException
48
- end
49
- end
27
+
50
28
  end
@@ -1,19 +1,21 @@
1
+ require 'sightstone/modules/sightstone_base_module'
1
2
  require 'sightstone/summoner'
2
3
  require 'sightstone/league'
3
4
 
4
- class LeagueModule
5
+ class LeagueModule < SightstoneBaseModule
5
6
  def initialize(sightstone)
6
7
  @sightstone = sightstone
7
8
  end
8
9
 
9
- def league(summoner)
10
+ def league(summoner, optional={})
11
+ region = optional[:region] || @sightstone.region
10
12
  id = if summoner.is_a? Summoner
11
13
  summoner.id
12
14
  else
13
15
  summoner
14
16
  end
15
17
 
16
- uri = "http://prod.api.pvp.net/api/#{@sightstone.region}/v2.1/league/by-summoner/#{id}"
18
+ uri = "https://prod.api.pvp.net/api/#{region}/v2.1/league/by-summoner/#{id}"
17
19
  response = _get_api_response(uri)
18
20
  _parse_response(response) { |resp|
19
21
  data = JSON.parse(resp)
@@ -26,28 +28,4 @@ class LeagueModule
26
28
  }
27
29
  end
28
30
 
29
- private
30
-
31
- def _get_api_response(uri)
32
- params = {'api_key' => @sightstone.api_key}
33
- RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
34
- rescue SocketError => e
35
- nil
36
-
37
- end
38
-
39
- def _parse_response(response, &block)
40
- response_code = if response.nil?
41
- 500
42
- else
43
- response.code
44
- end
45
- if response_code == 200
46
- block.call(response.body)
47
- elsif response_code == 404
48
- raise Sightstone::SummonerNotFoundException
49
- elsif response_code == 500
50
- raise Sightstone::SightstoneConnectionException
51
- end
52
- end
53
31
  end
@@ -0,0 +1,36 @@
1
+ require 'open-uri'
2
+
3
+ # Base class of the api modules
4
+ # @abstract
5
+ class SightstoneBaseModule
6
+
7
+ protected
8
+ def _get_api_response(uri, header={})
9
+ params = {'api_key' => @sightstone.api_key}.merge header
10
+ RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
11
+ rescue SocketError => e
12
+ nil
13
+
14
+ end
15
+
16
+ def _parse_response(response, &block)
17
+ response_code = if response.nil?
18
+ 500
19
+ else
20
+ response.code
21
+ end
22
+
23
+ if response_code == 200
24
+ block.call(response.body)
25
+ elsif response_code == 404
26
+ raise Sightstone::SummonerNotFoundException
27
+ elsif response_code == 500
28
+ raise Sightstone::SightstoneConnectionException
29
+ elsif response_code == 429
30
+ raise Sightstone::RateLimitExceededException
31
+ else
32
+ raise Sightstone::SightstoneApiException 'Unknown error occured'
33
+ end
34
+ end
35
+
36
+ end
@@ -1,19 +1,23 @@
1
+ require 'sightstone/modules/sightstone_base_module'
1
2
  require 'sightstone/summoner'
2
3
  require 'sightstone/player_stats_summary'
3
4
  require 'sightstone/ranked_stats'
4
5
 
5
- class StatsModule
6
+ class StatsModule < SightstoneBaseModule
6
7
  def initialize(sightstone)
7
8
  @sightstone = sightstone
8
9
  end
9
10
 
10
- def summary(summoner, season=nil)
11
+ def summary(summoner, , optional={})
12
+ region = optional[:region] || @sightstone.region)
13
+ season = optional[:season]
14
+
11
15
  id = if summoner.is_a? Summoner
12
16
  summoner.id
13
17
  else
14
18
  summoner
15
19
  end
16
- uri = "https://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/stats/by-summoner/#{id}/summary"
20
+ uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/stats/by-summoner/#{id}/summary"
17
21
  response = if season.nil?
18
22
  _get_api_response(uri)
19
23
  else
@@ -27,13 +31,15 @@ class StatsModule
27
31
 
28
32
  end
29
33
 
30
- def ranked(summoner, season=nil)
34
+ def ranked(summoner, optional={})
35
+ region = optional[:region] || @sightstone.region
36
+ season = optional[:season]
31
37
  id = if summoner.is_a? Summoner
32
38
  summoner.id
33
39
  else
34
40
  summoner
35
41
  end
36
- uri = "https://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/stats/by-summoner/#{id}/ranked"
42
+ uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.1/stats/by-summoner/#{id}/ranked"
37
43
  response = if season.nil?
38
44
  _get_api_response(uri)
39
45
  else
@@ -46,29 +52,4 @@ class StatsModule
46
52
  }
47
53
 
48
54
  end
49
-
50
- def _get_api_response(uri, header={})
51
- params = {'api_key' => @sightstone.api_key}.merge header
52
- RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
53
- rescue SocketError => e
54
- nil
55
-
56
- end
57
-
58
- def _parse_response(response, &block)
59
- response_code = if response.nil?
60
- 500
61
- else
62
- response.code
63
- end
64
-
65
- if response_code == 200
66
- block.call(response.body)
67
- elsif response_code == 404
68
- raise Sightstone::SummonerNotFoundException
69
- elsif response_code == 500
70
- raise Sightstone::SightstoneConnectionException
71
- end
72
- end
73
-
74
55
  end
@@ -1,17 +1,20 @@
1
+ require 'sightstone/modules/sightstone_base_module'
1
2
  require 'sightstone/summoner'
2
3
  require 'sightstone/masterybook'
3
4
  require 'sightstone/runebook'
5
+ require 'open-uri'
4
6
 
5
- class SummonerModule
7
+ class SummonerModule < SightstoneBaseModule
6
8
  def initialize(sightstone)
7
9
  @sightstone = sightstone
8
10
  end
9
11
 
10
- def summoner(name_or_id)
12
+ def summoner(name_or_id, optional={})
13
+ region = optional[:region] || @sightstone.region
11
14
  uri = if name_or_id.is_a? Integer
12
- "http://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/summoner/#{name_or_id}"
15
+ "https://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{name_or_id}"
13
16
  else
14
- "http://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/summoner/by-name/#{name_or_id}"
17
+ "https://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/by-name/#{URI::encode(name_or_id)}"
15
18
  end
16
19
 
17
20
  response = _get_api_response(uri)
@@ -22,9 +25,10 @@ class SummonerModule
22
25
  end
23
26
 
24
27
 
25
- def names(ids)
28
+ def names(ids, optional={})
29
+ region = optional[:region] || @sightstone.region
26
30
  ids = ids.join(',')
27
- uri = "http://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/summoner/#{ids}/name"
31
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{ids}/name"
28
32
  response = _get_api_response(uri)
29
33
  _parse_response(response) { |resp|
30
34
  data = JSON.parse(resp)
@@ -32,13 +36,14 @@ class SummonerModule
32
36
  }
33
37
  end
34
38
 
35
- def runes(summoner)
39
+ def runes(summoner, optional={})
40
+ region = optional[:region] || @sightstone.region
36
41
  id = if summoner.is_a? Summoner
37
42
  summoner.id
38
43
  else
39
44
  summoner
40
45
  end
41
- uri = "http://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/summoner/#{id}/runes"
46
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{id}/runes"
42
47
  response = _get_api_response(uri)
43
48
  _parse_response(response) { |resp|
44
49
  data = JSON.parse(resp)
@@ -46,43 +51,18 @@ class SummonerModule
46
51
  }
47
52
  end
48
53
 
49
- def masteries(summoner)
54
+ def masteries(summoner, optional={})
55
+ region = optional[:region] || @sightstone.region
50
56
  id = if summoner.is_a? Summoner
51
57
  summoner.id
52
58
  else
53
59
  summoner
54
60
  end
55
- uri = "http://prod.api.pvp.net/api/lol/#{@sightstone.region}/v1.1/summoner/#{id}/masteries"
61
+ uri = "http://prod.api.pvp.net/api/lol/#{region}/v1.1/summoner/#{id}/masteries"
56
62
  response = _get_api_response(uri)
57
63
  _parse_response(response) { |resp|
58
64
  data = JSON.parse(resp)
59
65
  return MasteryBook.new(data)
60
66
  }
61
67
  end
62
-
63
- private
64
-
65
- def _get_api_response(uri)
66
- params = {'api_key' => @sightstone.api_key}
67
- RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
68
- rescue SocketError => e
69
- nil
70
-
71
- end
72
-
73
- def _parse_response(response, &block)
74
- response_code = if response.nil?
75
- 500
76
- else
77
- response.code
78
- end
79
-
80
- if response_code == 200
81
- block.call(response.body)
82
- elsif response_code == 404
83
- raise Sightstone::SummonerNotFoundException
84
- elsif response_code == 500
85
- raise Sightstone::SightstoneConnectionException
86
- end
87
- end
88
68
  end
@@ -1,19 +1,21 @@
1
+ require 'sightstone/modules/sightstone_base_module'
1
2
  require 'sightstone/summoner'
2
3
  require 'sightstone/team'
3
4
 
4
- class TeamModule
5
+ class TeamModule < SightstoneBaseModule
5
6
  def initialize(sightstone)
6
7
  @sightstone = sightstone
7
8
  end
8
9
 
9
- def teams(summoner)
10
+ def teams(summoner, optional={})
11
+ region = optional[:region] || @sightstone.region
10
12
  id = if summoner.is_a? Summoner
11
13
  summoner.id
12
14
  else
13
15
  summoner
14
16
  end
15
17
 
16
- uri = "http://prod.api.pvp.net/api/#{@sightstone.region}/v2.1/team/by-summoner/#{id}"
18
+ uri = "https://prod.api.pvp.net/api/#{region}/v2.1/team/by-summoner/#{id}"
17
19
 
18
20
  response = _get_api_response(uri)
19
21
  _parse_response(response) { |resp|
@@ -26,31 +28,4 @@ class TeamModule
26
28
  }
27
29
  end
28
30
 
29
-
30
-
31
- private
32
-
33
- def _get_api_response(uri)
34
- params = {'api_key' => @sightstone.api_key}
35
- RestClient.get(uri, headers={:params => params}) {|response, request, result| response }
36
- rescue SocketError => e
37
- nil
38
-
39
- end
40
-
41
- def _parse_response(response, &block)
42
- response_code = if response.nil?
43
- 500
44
- else
45
- response.code
46
- end
47
-
48
- if response_code == 200
49
- block.call(response.body)
50
- elsif response_code == 404
51
- raise Sightstone::SummonerNotFoundException
52
- elsif response_code == 500
53
- raise Sightstone::SightstoneConnectionException
54
- end
55
- end
56
31
  end
@@ -1,9 +1,14 @@
1
-
2
-
1
+ # Class to represent a summoner
2
+ # @attr [String] name name
3
+ # @attr [Long] id summoner id (used for other calls)
4
+ # @attr [Integer] profileIconId profile icon id of the summoner
5
+ # @attr [long] revisionDate timestamp of latest data change
6
+ # @attr [Integer] level summoner level
3
7
  class Summoner
4
8
 
5
9
  attr_accessor :name, :id, :profileIconId, :revisionDate, :level
6
10
 
11
+ # @param data [Hash] json hash representation of the summoner
7
12
  def initialize(data)
8
13
  @name = data['name']
9
14
  @id = data['id']
data/lib/sightstone.rb CHANGED
@@ -7,11 +7,24 @@ require 'sightstone/modules/league_module'
7
7
  require 'sightstone/modules/stats_module'
8
8
  require 'sightstone/modules/team_module'
9
9
 
10
+ # This is the main class of the Sightstone gem. All calls should be perfomrmed through this class.
11
+ # @attr [String] region The default region
12
+ # @attr [String] api_key Your api key
13
+ # @attr [SummonerModule] summoner Module to call the summoners api
14
+ # @attr [ChampionModule] Champion module to call the champion api
15
+ # @attr [GameModule] Game module to call the game api
16
+ # @attr [LeagueModule] League module to call the leagues api
17
+ # @attr [StatsModule] Stats module to call the stats api
18
+ # @attr [TeamModule] Team module to call the team api
10
19
  class Sightstone
11
- attr_accessor :region, :api_key
20
+
21
+ attr_accessor :region
22
+ attr_accessor :api_key
12
23
  attr_accessor :summoner, :champion, :game, :league, :stats, :team
13
24
 
14
- def initialize(api_key, region)
25
+ # @param api_key [String] Riot developer api key
26
+ # @param region [String] The default region to be used. See riots dev. page for supported regions.
27
+ def initialize(api_key, region='euw')
15
28
  @api_key = api_key
16
29
  @region = region
17
30
 
@@ -24,9 +37,14 @@ class Sightstone
24
37
  end
25
38
  end
26
39
 
27
- # Error classes
40
+ # Base class for exceptions raised by the gem
28
41
  class SightstoneApiException < Exception; end
29
42
 
43
+ # Raised if the given developer cannot be found (api returns http error code 404)
30
44
  class SummonerNotFoundException < SightstoneApiException; end
31
45
 
46
+ # Raised if the connection to the api failed
32
47
  class SightstoneConnectionException < SightstoneApiException; end
48
+
49
+ # Raised when the RateLimit has been exceeded (api returns http error code 429)
50
+ class RateLimitExceededException < SightstoneApiException; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sightstone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2012-12-12 00:00:00.000000000 Z
11
+ date: 2012-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -51,6 +51,7 @@ files:
51
51
  - lib/sightstone/modules/champion_module.rb
52
52
  - lib/sightstone/modules/game_module.rb
53
53
  - lib/sightstone/modules/league_module.rb
54
+ - lib/sightstone/modules/sightstone_base_module.rb
54
55
  - lib/sightstone/modules/stats_module.rb
55
56
  - lib/sightstone/modules/summoner_module.rb
56
57
  - lib/sightstone/modules/team_module.rb
@@ -86,3 +87,4 @@ signing_key:
86
87
  specification_version: 4
87
88
  summary: Ruby wrapper for riots league of legends api
88
89
  test_files: []
90
+ has_rdoc: