ruby-lol 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b867ffb05c47098f45beea30f1e091db52ac4fce
4
+ data.tar.gz: fa6668a7f1777938f9487bbdbc6b2cebbb57645f
5
+ SHA512:
6
+ metadata.gz: 560e480835130b3e3a50f58e996d5e1aba42b908786d830671b2959dfc038185a6249d8092fb212213ec915d9bbfcdfba2fb0f4a253fe8b06701da8010055e86
7
+ data.tar.gz: a063f0f21d6ed47c5e9d64144b424b17cbe0ce29034c4cf399da46e8bd341bd670ba98b4080e624a158782e8846aac80aadc5b9fb2485ab50e6748ae95e9dc30
data/.autotest ADDED
@@ -0,0 +1,2 @@
1
+ require 'autotest/fsevent'
2
+ require 'autotest/growl'
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
File without changes
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm: 2.0.0
2
+ addons:
3
+ code_climate:
4
+ repo_token: c98576197ae22bdd3bede9cd3cdfdad33fac26bfdddb1e5f2bbc4fb535812185
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-lol.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Giovanni Intini
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # ruby-lol
2
+ [![Coverage Status](https://coveralls.io/repos/mikamai/ruby-lol/badge.png)](https://coveralls.io/r/mikamai/ruby-lol) [![Build Status](https://travis-ci.org/mikamai/ruby-lol.png?branch=master)](https://travis-ci.org/mikamai/ruby-lol) [![Code Climate](https://codeclimate.com/repos/52a9908c56b102320a0166a4/badges/7e5d4ea4fe9e562f8e4d/gpa.png)](https://codeclimate.com/repos/52a9908c56b102320a0166a4/feed)
3
+
4
+ ruby-lol is a wrapper to the [Riot Games API](https://developer.riotgames.com).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'ruby-lol'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install ruby-lol
19
+
20
+ ## Usage
21
+
22
+ require 'lol'
23
+
24
+ # defaults to euw
25
+ client = Lol::Client.new "my_api_key"
26
+ #<Lol::Client:0x007fd09d1abb00 @api_key="my_api_key", @region="euw">
27
+
28
+ # na
29
+ na_client = Lol::Client.new "my_api_key", :region => "na"
30
+ # => <Lol::Client:0x007fd09d1abb00 @api_key="my_api_key", @region="na">
31
+
32
+ # gets all champions
33
+ champions = client.champion
34
+ # => Array of Lol::Champion
35
+
36
+ # let's play a bit, who is free to play?
37
+ client.champion.select {|c| c.free_to_play }.map {|c| c.name}
38
+ # => %w(Aatrox Cassiopeia Lux Malphite MissFortune MonkeyKing Nautilus Sivir Talon Taric)
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/setup"
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ desc "Open an irb session preloaded with this library"
10
+ task :console do
11
+ sh "irb -rubygems -I . -r lib/lol.rb"
12
+ end
data/lib/lol.rb ADDED
@@ -0,0 +1,6 @@
1
+ require __dir__ + "/lol/client"
2
+ require __dir__ + "/lol/champion"
3
+ require __dir__ + "/lol/game"
4
+ require __dir__ + "/lol/league"
5
+ require __dir__ + "/lol/player"
6
+ require __dir__ + "/lol/statistic"
@@ -0,0 +1,64 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class Champion < Lol::Model
5
+ # @!attribute [r] raw
6
+ # @return [String] raw version of options Hash used to initialize Champion
7
+ attr_reader :raw
8
+
9
+ # @!attribute [r] id
10
+ # @return [Fixnum] id of Champion
11
+ attr_reader :id
12
+
13
+ # @!attribute [r] name
14
+ # @return [String] name of Champion
15
+ attr_reader :name
16
+
17
+ # @!attribute [r] active
18
+ # @return [true] if the Champion is active
19
+ # @return [false] if the Champion is disabled
20
+ attr_reader :active
21
+
22
+ # @!attribute [r] attack_rank
23
+ # @return [Fixnum] attack rank of Champion
24
+ attr_reader :attack_rank
25
+
26
+ # @!attribute [r] defense_rank
27
+ # @return [Fixnum] defense rank of Champion
28
+ attr_reader :defense_rank
29
+
30
+ # @!attribute [r] magic_rank
31
+ # @return [Fixnum] magic rank of Champion
32
+ attr_reader :magic_rank
33
+
34
+ # @!attribute [r] difficulty_rank
35
+ # @return [Fixnum] difficulty rank of Champion
36
+ attr_reader :difficulty_rank
37
+
38
+ # @!attribute [r] bot_enabled
39
+ # @return [true] if the Champion is enabled in custom bot games
40
+ # @return [false] if the Champion is disabled in custom bot games
41
+ attr_reader :bot_enabled
42
+
43
+ # @!attribute [r] free_to_play
44
+ # @return [true] if the Champion is currently free to play
45
+ # @return [false] if the Champion isn't currently free to play
46
+ attr_reader :free_to_play
47
+
48
+ # @!attribute [r] bot_mm_enabled
49
+ # @return [true] if the Champion is enabled in match made bot games
50
+ # @return [false] if the Champion is disabled in match made bot games
51
+ attr_reader :bot_mm_enabled
52
+
53
+ # @!attribute [r] ranked_play_enabled
54
+ # @return [true] if the Champion is enabled in ranked play
55
+ # @return [false] if the Champion is disabled in ranked play
56
+ attr_reader :ranked_play_enabled
57
+
58
+ private
59
+
60
+ attr_writer :id, :name, :active, :attack_rank, :defense_rank, :magic_rank,
61
+ :difficulty_rank, :bot_enabled, :free_to_play, :bot_mm_enabled,
62
+ :ranked_play_enabled
63
+ end
64
+ end
data/lib/lol/client.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'httparty'
2
+
3
+ module Lol
4
+ class InvalidAPIResponse < StandardError; end
5
+
6
+ class Client
7
+ include HTTParty
8
+
9
+ # @!attribute [rw] region
10
+ # @return [String] name of region
11
+ attr_accessor :region
12
+
13
+ # @!attribute [r] api_key
14
+ # @return [String] the API key that has been used
15
+ attr_reader :api_key
16
+
17
+ # Returns a full url for an API call
18
+ # @param version [String] API version to call
19
+ # @param path [String] API path to call
20
+ # @return [String] full fledged url
21
+ def api_url version, path
22
+ lol = version == "v1.1" ? "lol" : ""
23
+ File.join "http://prod.api.pvp.net/api/", lol, "/#{region}/#{version}/", "#{path}?api_key=#{api_key}"
24
+ end
25
+
26
+ # Calls the API via HTTParty and handles errors
27
+ #
28
+ def get url
29
+ response = self.class.get(url)
30
+ if response["status"]
31
+ raise InvalidAPIResponse.new(response["status"]["message"])
32
+ else
33
+ response
34
+ end
35
+ end
36
+
37
+ # Calls the latest API version of champion
38
+ def champion
39
+ champion11
40
+ end
41
+
42
+ # Retrieve all champions, v1.1
43
+ # @return [Array] an array of champions
44
+ def champion11
45
+ get(api_url("v1.1", "champion"))["champions"].map {|c| Champion.new(c)}
46
+ end
47
+
48
+ # Calls the latest API version of game returning the list of
49
+ # recent games played by a summoner
50
+ def game *args
51
+ game11 *args
52
+ end
53
+
54
+ # Returns a list of the recent games played by a summoner
55
+ # @param summoner_id [Fixnum] Summoner id
56
+ # @return [Array] an array of games
57
+ def game11 summoner_id
58
+ summoner_api_path = "game/by-summoner/#{summoner_id}/recent"
59
+ get(api_url("v1.1", summoner_api_path))["games"].map do |game_data|
60
+ Game.new game_data
61
+ end
62
+ end
63
+
64
+ # Calls the latest API version of league
65
+ def league summoner_id
66
+ league21 summoner_id
67
+ end
68
+
69
+ # Retrieves leagues data for summoner, including leagues for all of summoner's teams, v2.1
70
+ # @return [Array] an array of champions
71
+ def league21 summoner_id
72
+ get(api_url("v2.1", "league/by-summoner/#{summoner_id}"))[summoner_id].map {|l| League.new}
73
+ end
74
+
75
+
76
+ # Initializes a Lol::Client
77
+ # @param api_key [String]
78
+ # @param options [Hash]
79
+ # @option options [String] :region ("EUW") The region on which the requests will be made
80
+ # @return [Lol::Client]
81
+ def initialize api_key, options = {}
82
+ @api_key = api_key
83
+ @region = options.delete(:region) || "euw"
84
+ end
85
+
86
+ end
87
+ end
data/lib/lol/game.rb ADDED
@@ -0,0 +1,92 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class Game < Lol::Model
5
+ # @!attribute [r] raw
6
+ # @return [Hash] raw version of options Hash used to initialize Game
7
+ attr_reader :raw
8
+
9
+ # @!attribute [r] id
10
+ # @return [Fixnum] Game Id
11
+ attr_reader :game_id
12
+
13
+ # @!attribute [r] champion_id
14
+ # @return [Fixnum] Champion Id associated with this game
15
+ attr_reader :champion_id
16
+
17
+ # @!attribute [r] create_date
18
+ # @return [DateTime] Date game was played
19
+ attr_reader :create_date
20
+
21
+ # @!attribute [r] create_date_str
22
+ # @return [String] Human readable string representing date game was played
23
+ attr_reader :create_date_str
24
+
25
+ # @!attribute [r] fellow_players
26
+ # @return [Array] list of players associated with this game
27
+ attr_reader :fellow_players
28
+
29
+ # @!attribute [r] game_mode
30
+ # @return [String] Game Mode
31
+ attr_reader :game_mode
32
+
33
+ # @!attribute [r] game_type
34
+ # @return [String] Game Type
35
+ attr_reader :game_type
36
+
37
+ # @!attribute [r] invalid
38
+ # @return [true] if the game is invalid
39
+ # @return [false] if the game is valid
40
+ attr_reader :invalid
41
+
42
+ # @!attribute [r] level
43
+ # @return [Fixnum] Level
44
+ attr_reader :level
45
+
46
+ # @!attribute [r] map_id
47
+ # @return [Fixnum] Map Id
48
+ attr_reader :map_id
49
+
50
+ # @!attribute [r] spell1
51
+ # @return [Fixnum] Summoner first spell id
52
+ attr_reader :spell1
53
+
54
+ # @!attribute [r] spell2
55
+ # @return [Fixnum] Summoner second spell id
56
+ attr_reader :spell2
57
+
58
+ # @!attribute [r] statistics
59
+ # @return [Array] Statistics associated with the game for this summoner
60
+ attr_reader :statistics
61
+
62
+ # @!attribute [r] sub_type
63
+ # @return [String] Game sub-type
64
+ attr_reader :sub_type
65
+
66
+ # @!attribute [r] team_id
67
+ # @return [Fixnum] Team Id associated with game
68
+ attr_reader :team_id
69
+
70
+ private
71
+
72
+ attr_writer :champion_id, :game_id, :game_mode, :game_type, :invalid,
73
+ :level, :map_id, :spell1, :spell2, :sub_type, :team_id,
74
+ :create_date_str
75
+
76
+ def create_date= value
77
+ @create_date = value.is_a?(DateTime) && value || DateTime.strptime(value.to_s, '%s')
78
+ end
79
+
80
+ def fellow_players= collection
81
+ @fellow_players = collection.map do |c|
82
+ c.respond_to?(:[]) && Player.new(c) || c
83
+ end
84
+ end
85
+
86
+ def statistics= collection
87
+ @statistics = collection.map do |c|
88
+ c.respond_to?(:[]) && Statistic.new(c) || c
89
+ end
90
+ end
91
+ end
92
+ end
data/lib/lol/league.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Lol
2
+ class League
3
+ end
4
+ end
data/lib/lol/model.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+
3
+ module Lol
4
+ class Model
5
+ # Initializes a Lol::Model
6
+ # @param options [Hash]
7
+ # @return [Lol::Model]
8
+ def initialize options = {}
9
+ @raw = options
10
+ options.each do |attribute_name, value|
11
+ send "#{attribute_name.to_s.underscore}=", value
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/lol/player.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class Player < Lol::Model
5
+ # @!attribute [r] raw
6
+ # @return [Hash] raw version of options Hash used to initialize Player
7
+ attr_reader :raw
8
+
9
+ # @!attribute [r] champion_id
10
+ # @return [Fixnum] Champion Id associated with player
11
+ attr_reader :champion_id
12
+
13
+ # @!attribute [r] summoner_id
14
+ # @return [Fixnum] Summoner Id associated with player
15
+ attr_reader :summoner_id
16
+
17
+ # @!attribute [r] team_id
18
+ # @return [Fixnum] Team Id associated with player
19
+ attr_reader :team_id
20
+
21
+ private
22
+
23
+ attr_writer :champion_id, :summoner_id, :team_id
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'lol/model'
2
+
3
+ module Lol
4
+ class Statistic < Lol::Model
5
+ # @!attribute [r] raw
6
+ # @return [Hash] raw version of options Hash used to initialize Statistic
7
+ attr_reader :raw
8
+
9
+ # @!attribute [r] id
10
+ # @return [Fixnum] Raw Statistic Id
11
+ attr_reader :id
12
+
13
+ # @!attribute [r] name
14
+ # @return [String] Raw Statistic name
15
+ attr_reader :name
16
+
17
+ # @!attribute [r] value
18
+ # @return [Fixnum] Raw Statistic value
19
+ attr_reader :value
20
+
21
+ private
22
+
23
+ attr_writer :id, :name, :value
24
+ end
25
+ end