riot_api 0.0.4 → 0.1.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.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +3 -2
  5. data/lib/riot_api/api.rb +5 -3
  6. data/lib/riot_api/middleware/custom_logger.rb +70 -0
  7. data/lib/riot_api/model.rb +8 -0
  8. data/lib/riot_api/model/champion.rb +17 -0
  9. data/lib/riot_api/model/champion_stat.rb +13 -0
  10. data/lib/riot_api/model/game.rb +22 -0
  11. data/lib/riot_api/model/league.rb +13 -0
  12. data/lib/riot_api/model/league_entry.rb +21 -0
  13. data/lib/riot_api/model/mastery_page.rb +11 -0
  14. data/lib/riot_api/model/match.rb +17 -0
  15. data/lib/riot_api/model/member.rb +10 -0
  16. data/lib/riot_api/model/player.rb +9 -0
  17. data/lib/riot_api/model/player_stat_summary.rb +12 -0
  18. data/lib/riot_api/model/roster.rb +10 -0
  19. data/lib/riot_api/model/rune.rb +10 -0
  20. data/lib/riot_api/model/rune_page.rb +12 -0
  21. data/lib/riot_api/model/rune_slot.rb +10 -0
  22. data/lib/riot_api/model/statistic.rb +12 -0
  23. data/lib/riot_api/model/talent.rb +9 -0
  24. data/lib/riot_api/model/team.rb +26 -0
  25. data/lib/riot_api/model/team_id.rb +7 -0
  26. data/lib/riot_api/model/team_stat_detail.rb +13 -0
  27. data/lib/riot_api/model/team_stat_summary.rb +11 -0
  28. data/lib/riot_api/resource/base.rb +10 -0
  29. data/lib/riot_api/resource/champions.rb +4 -2
  30. data/lib/riot_api/resource/game.rb +8 -2
  31. data/lib/riot_api/resource/league.rb +6 -2
  32. data/lib/riot_api/resource/stats.rb +15 -3
  33. data/lib/riot_api/resource/summoner.rb +23 -7
  34. data/lib/riot_api/resource/team.rb +8 -2
  35. data/lib/riot_api/version.rb +1 -1
  36. data/spec/api_spec.rb +111 -54
  37. data/spec/model/champion_spec.rb +14 -0
  38. data/spec/model/champion_stat_spec.rb +18 -0
  39. data/spec/model/game_spec.rb +18 -0
  40. data/spec/model/league_entry_spec.rb +13 -0
  41. data/spec/model/league_spec.rb +17 -0
  42. data/spec/model/mastery_page_spec.rb +16 -0
  43. data/spec/model/match_spec.rb +13 -0
  44. data/spec/model/member_spec.rb +13 -0
  45. data/spec/model/player_stat_summary_spec.rb +20 -0
  46. data/spec/model/roster_spec.rb +15 -0
  47. data/spec/model/rune_page_spec.rb +16 -0
  48. data/spec/model/rune_slot_spec.rb +15 -0
  49. data/spec/model/rune_spec.rb +17 -0
  50. data/spec/model/statistic_spec.rb +17 -0
  51. data/spec/model/talent_spec.rb +16 -0
  52. data/spec/model/team_id_spec.rb +13 -0
  53. data/spec/model/team_spec.rb +44 -0
  54. data/spec/model/team_stat_detail_spec.rb +20 -0
  55. data/spec/model/team_stat_summary_stat.rb +27 -0
  56. data/spec/spec_helper.rb +11 -0
  57. data/spec/vcr/cassettes/RiotApi_API/_league/_by_summoner/{should_return_leagues_data_for_summoner.yml → should_return_league_object_for_summoner.yml} +0 -0
  58. data/spec/vcr/cassettes/RiotApi_API/_new/should_output_to_stdout_with_debug_parameter.yml +41 -0
  59. data/spec/vcr/cassettes/RiotApi_API/_new/should_raise_an_error_if_the_raise_error_status_flag_is_enabled.yml +55 -0
  60. data/spec/vcr/cassettes/RiotApi_API/_summoner/_id/should_return_information_from_the_summoner_id.yml +9 -15
  61. data/spec/vcr/cassettes/RiotApi_API/_summoner/_name/should_return_information_from_the_summoner_name.yml +9 -15
  62. metadata +72 -43
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7214fe007e576b2c2b1a9ba783eac5724e604fba
4
+ data.tar.gz: e2f652f3fcfc5baeaef9bfb7f1f3d2c00db9b4d8
5
+ SHA512:
6
+ metadata.gz: 4801b1605ee7139ae8f732c952a9f0f2b91c30f31b3adb0e3379c990944877930b6cd1929b5d370500dee2de9bb10a2e4c61c8a4c4ddbd741d97cf87c00448f0
7
+ data.tar.gz: 0c73679b3532e020cab9c1a6e2fd2b6fa56c0cfd3ec8672b4c04956221be26750fd398c7e1efb128d3a7ac42efe43cce2f65a9a37bd2e9eb8a1f094439448f20
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ test/version_tmp
16
16
  tmp
17
17
  .rbenv-vars
18
18
  .coveralls.yml
19
+ .ruby-version
20
+ .ruby-gemset
@@ -1,3 +1,8 @@
1
+ ## 0.1.0
2
+ * Virtus models implemented for all end-points
3
+ * Added custom log class for debug, which redacts API keys
4
+ * Fix @raise_status_errors bug, will now raise error before trying to parse it as JSON
5
+
1
6
  ## 0.0.4
2
7
  * Yanked 0.0.3 release as Team method not implemented
3
8
  * Fixed team method
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/riot_api.png)](http://badge.fury.io/rb/riot_api)
4
4
  [![Coverage Status](https://coveralls.io/repos/petems/riot_api/badge.png)](https://coveralls.io/r/petems/riot_api)
5
5
  [![Build Status](https://travis-ci.org/petems/riot_api.png?branch=master)](https://travis-ci.org/petems/riot_api)
6
+ [![Dependency Status](https://gemnasium.com/petems/riot_api.png)](https://gemnasium.com/petems/riot_api)
6
7
 
7
8
  A Ruby wrapper around connecting to the [Riot API](https://developer.riotgames.com)
8
9
 
@@ -109,7 +110,7 @@ rspec
109
110
 
110
111
  ### Contributors
111
112
 
112
- * [pcg79](https://github.com/pcg79)
113
+ * [@pcg79](https://github.com/pcg79)
113
114
 
114
115
  For more information and a complete list see [the contributor page on GitHub](https://github.com/petems/riot_api/contributors).
115
116
 
@@ -119,5 +120,5 @@ For more information and a complete list see [the contributor page on GitHub](ht
119
120
 
120
121
  ## Thanks
121
122
 
122
- * @rmoriz - For the excellent [digital_ocean](https://github.com/rmoriz/digital_ocean) gem, which I used as a framework to setup this gem! :+1:
123
+ * [@rmoriz](https://github.com/rmoriz) - For the excellent [digital_ocean](https://github.com/rmoriz/digital_ocean) gem, which I used as a framework to setup this gem! :+1:
123
124
 
@@ -1,3 +1,5 @@
1
+ require File.expand_path('../middleware/custom_logger', __FILE__)
2
+
1
3
  module RiotApi
2
4
  class API
3
5
 
@@ -22,7 +24,7 @@ module RiotApi
22
24
  @ssl = params[:ssl] || { :verify => true }
23
25
  @base_url = params[:base_url] || "http://prod.api.pvp.net/api/"
24
26
  @faraday_adapter = params[:faraday_adapter] || Faraday.default_adapter
25
- @raise_status_errors = params[:raise_status_errors] || false
27
+ @raise_status_errors = params[:raise_status_errors] || true
26
28
  @faraday = params[:faraday] || default_faraday
27
29
  raise ArgumentError, ':api_key missing' unless @api_key
28
30
  raise ArgumentError, ':region missing' unless @region
@@ -55,11 +57,11 @@ module RiotApi
55
57
 
56
58
  def default_faraday
57
59
  Faraday.new(:url => @base_url, :ssl => @ssl) do |faraday|
58
- faraday.use Faraday::Response::RaiseError if @raise_status_errors
60
+ faraday.use CustomLogger if @debug
59
61
  faraday.request :url_encoded
60
62
  faraday.response :rashify
61
63
  faraday.response :json
62
- faraday.response(:logger) if @debug
64
+ faraday.use Faraday::Response::RaiseError if @raise_status_errors
63
65
  faraday.adapter @faraday_adapter
64
66
  faraday.params['api_key'] = @api_key
65
67
  faraday.headers['User-Agent'] = "riot_api rubygem v#{RiotApi::VERSION}"
@@ -0,0 +1,70 @@
1
+ module RiotApi
2
+ class CustomLogger < Faraday::Middleware
3
+ extend Forwardable
4
+ def_delegators :@logger, :debug, :info, :warn, :error, :fatal
5
+
6
+ def initialize(app, options = {})
7
+ @app = app
8
+ @logger = options.fetch(:logger) {
9
+ require 'logger'
10
+ ::Logger.new($stdout)
11
+ }
12
+ end
13
+
14
+ def call(env)
15
+ start_time = Time.now
16
+ info { request_info(env) }
17
+ debug { request_debug(env) }
18
+ @app.call(env).on_complete do
19
+ end_time = Time.now
20
+ response_time = end_time - start_time
21
+ info { response_info(env, response_time) }
22
+ debug { response_debug(env) }
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def filter(output)
29
+ unless ENV['DEBUG'] == '2'
30
+ output = output.to_s.gsub(/api_key=[a-zA-Z0-9-]*/,'api_key=[API-KEY]')
31
+ else
32
+ output
33
+ end
34
+ end
35
+
36
+ def request_info(env)
37
+ "Started %s request to: %s" % [ env[:method].to_s.upcase, filter(env[:url]) ]
38
+ end
39
+
40
+ def response_info(env, response_time)
41
+ "Response from %s; Status: %d; Time: %.1fms" % [ filter(env[:url]), env[:status], (response_time * 1_000.0) ]
42
+ end
43
+
44
+ def request_debug(env)
45
+ debug_message("Request", env[:request_headers], env[:body])
46
+ end
47
+
48
+ def response_debug(env)
49
+ debug_message("Response", env[:response_headers], env[:body])
50
+ end
51
+
52
+ def debug_message(name, headers, body)
53
+ <<-MESSAGE.gsub(/^ +([^ ])/m, '\\1')
54
+ #{name} Headers:
55
+ ----------------
56
+ #{format_headers(headers)}
57
+
58
+ #{name} Body:
59
+ -------------
60
+ #{body}
61
+ MESSAGE
62
+ end
63
+
64
+ def format_headers(headers)
65
+ length = headers.map {|k,v| k.to_s.size }.max
66
+ headers.map { |name, value| "#{name.to_s.ljust(length)} : #{filter(value)}" }.join("\n")
67
+ end
68
+
69
+ end
70
+ end
@@ -1,5 +1,13 @@
1
1
  require 'riot_api/model/base'
2
+ require 'riot_api/model/champion'
3
+ require 'riot_api/model/champion_stat'
4
+ require 'riot_api/model/game'
5
+ require 'riot_api/model/league'
6
+ require 'riot_api/model/mastery_page'
7
+ require 'riot_api/model/player_stat_summary'
8
+ require 'riot_api/model/rune_page'
2
9
  require 'riot_api/model/summoner'
10
+ require 'riot_api/model/team'
3
11
 
4
12
  module RiotApi
5
13
  module Model
@@ -0,0 +1,17 @@
1
+ module RiotApi
2
+ module Model
3
+ class Champion < Base
4
+ attribute :id, Integer
5
+ attribute :name, String
6
+ attribute :active, Boolean
7
+ attribute :attack_rank, Integer
8
+ attribute :bot_enabled, Boolean
9
+ attribute :bot_mm_enabled, Boolean
10
+ attribute :defense_rank, Integer
11
+ attribute :difficulty_rank, Integer
12
+ attribute :free_to_play, Boolean
13
+ attribute :magic_rank, Integer
14
+ attribute :ranked_play_enabled, Boolean
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ require 'riot_api/model/statistic'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class ChampionStat < Base
6
+ attribute :id, Integer
7
+ attribute :name, String
8
+ attribute :stats, Array[RiotApi::Model::Statistic]
9
+
10
+ alias :statistics :stats
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ require 'riot_api/model/player'
2
+ require 'riot_api/model/statistic'
3
+
4
+ module RiotApi
5
+ module Model
6
+ class Game < Base
7
+ attribute :champion_id, Integer
8
+ attribute :create_date, String
9
+ attribute :create_date_str, String
10
+ attribute :fellow_players, Array[RiotApi::Model::Player]
11
+ attribute :game_id, Integer
12
+ attribute :game_mode, String
13
+ attribute :level, Integer
14
+ attribute :map_id, Integer
15
+ attribute :spell1, Integer
16
+ attribute :spell2, Integer
17
+ attribute :statistics, Array[RiotApi::Model::Statistic]
18
+ attribute :sub_type, String
19
+ attribute :team_id, Integer
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'riot_api/model/league_entry'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class League < Base
6
+ attribute :timestamp, Integer
7
+ attribute :name, String
8
+ attribute :tier, String
9
+ attribute :queue, String
10
+ attribute :entries, Array[RiotApi::Model::LeagueEntry]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module RiotApi
2
+ module Model
3
+ class LeagueEntry < Base
4
+ attribute :is_fresh_blood, Boolean
5
+ attribute :is_hot_streak, Boolean
6
+ attribute :is_inactive, Boolean
7
+ attribute :is_veteran, Boolean
8
+ attribute :last_played, Integer
9
+ attribute :league_name, String
10
+ attribute :league_points, Integer
11
+ attribute :losses, Integer
12
+ attribute :player_or_team_id, String
13
+ attribute :player_or_team_name, String
14
+ attribute :queue_type, String
15
+ attribute :rank, String
16
+ attribute :tier, String
17
+ attribute :time_until_decay, Integer
18
+ attribute :wins, Integer
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'riot_api/model/talent'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class MasteryPage < Base
6
+ attribute :current, Boolean
7
+ attribute :name, String
8
+ attribute :talents, Array[RiotApi::Model::Talent]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module RiotApi
2
+ module Model
3
+ class Match < Base
4
+ attribute :assists, Integer
5
+ attribute :date, Integer
6
+ attribute :deaths, Integer
7
+ attribute :game_id, Integer
8
+ attribute :game_mode, String
9
+ attribute :invalid, Boolean
10
+ attribute :kills, Integer
11
+ attribute :map_id, Integer
12
+ attribute :opposing_team_kills, Integer
13
+ attribute :opposing_team_name, String
14
+ attribute :win, Boolean
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module RiotApi
2
+ module Model
3
+ class Member < Base
4
+ attribute :invite_date, Integer
5
+ attribute :join_date, Integer
6
+ attribute :player_id, Integer
7
+ attribute :status, String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module RiotApi
2
+ module Model
3
+ class Player < Base
4
+ attribute :summoner_id, Integer
5
+ attribute :team_id, Integer
6
+ attribute :champion_id, Integer
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module RiotApi
2
+ module Model
3
+ class PlayerStatSummary < Base
4
+ attribute :aggregated_stats, Array[RiotApi::Model::Statistic]
5
+ attribute :losses, Integer
6
+ attribute :modify_date, Integer
7
+ attribute :modify_date_str, String
8
+ attribute :player_stat_summary_type, String
9
+ attribute :wins, Integer
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'riot_api/model/member'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class Roster < Base
6
+ attribute :member_list, Array[RiotApi::Model::Member]
7
+ attribute :owner_id, Integer
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module RiotApi
2
+ module Model
3
+ class Rune < Base
4
+ attribute :id, Integer
5
+ attribute :name, String
6
+ attribute :description, String
7
+ attribute :tier, Integer
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'riot_api/model/rune_slot'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class RunePage < Base
6
+ attribute :current, Boolean
7
+ attribute :id, Integer
8
+ attribute :name, String
9
+ attribute :slots, Array[RiotApi::Model::RuneSlot]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'riot_api/model/rune'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class RuneSlot < Base
6
+ attribute :rune, RiotApi::Model::Rune
7
+ attribute :rune_slot_id, Integer
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module RiotApi
2
+ module Model
3
+ class Statistic < Base
4
+ attribute :c, Integer
5
+ attribute :id, Integer
6
+ attribute :name, String
7
+ attribute :value, Integer
8
+
9
+ alias :count :c
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module RiotApi
2
+ module Model
3
+ class Talent < Base
4
+ attribute :id, Integer
5
+ attribute :name, String
6
+ attribute :rank, Integer
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'riot_api/model/match'
2
+ require 'riot_api/model/roster'
3
+ require 'riot_api/model/team_id'
4
+ require 'riot_api/model/team_stat_summary'
5
+
6
+ module RiotApi
7
+ module Model
8
+ class Team < Base
9
+ attribute :create_date, Integer
10
+ attribute :last_game_date, Integer
11
+ attribute :last_join_date, Integer
12
+ attribute :last_joined_ranked_team_queue_date, Integer
13
+ attribute :match_history, Array[RiotApi::Model::Match]
14
+ attribute :modify_date, Integer
15
+ attribute :name, String
16
+ attribute :roster, RiotApi::Model::Roster
17
+ attribute :second_last_join_date, Integer
18
+ attribute :status, String
19
+ attribute :tag, String
20
+ attribute :team_id, RiotApi::Model::TeamId
21
+ attribute :team_stat_summary, RiotApi::Model::TeamStatSummary
22
+ attribute :third_last_join_date, Integer
23
+ attribute :timestamp, Integer
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module RiotApi
2
+ module Model
3
+ class TeamId < Base
4
+ attribute :full_id, String
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'riot_api/model/team_id'
2
+
3
+ module RiotApi
4
+ module Model
5
+ class TeamStatDetail < Base
6
+ attribute :average_games_played, Integer
7
+ attribute :losses, Integer
8
+ attribute :team_id, RiotApi::Model::TeamId
9
+ attribute :team_stat_type, String
10
+ attribute :wins, Integer
11
+ end
12
+ end
13
+ end