lolbase 0.1.0

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: c8749694dc4664005095b8ec196c017c35797d53
4
+ data.tar.gz: 23756e8276524d3827086e87b2225afb757c3442
5
+ SHA512:
6
+ metadata.gz: 8a85f88ec28b3dbc6b1bad3f216fd0f83433a4ad02bd87b3e9e877c9ad1a676209160b0e84e2cd2e9101246417a9a2fb79fb62c068e0c14076ef2209579483ca
7
+ data.tar.gz: fdf05afe3b1a90aedbe785ab7589c7806756afb76f8b988607ebfe39fc31bc539005ab05387b6d18bf663c9b1f21f813ec14a8498bea640da76eb6ef8ff99c9c
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lolbase.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Regan Chan
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,73 @@
1
+ # LoLBase
2
+
3
+ A basic Ruby wrapper for the League of Legends API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'lolbase', :github => 'illianthe/lolbase'
10
+
11
+ And in the console, execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ ### 1. Configuration
18
+
19
+ LoLBase can be globally configured through the *LoLBase::configure* method. The values shown are the defaults set by the gem.
20
+
21
+ LoLBase.configure do |config|
22
+ config.default_region = "na"
23
+ config.default_key = nil
24
+ config.version_champion = "1.1"
25
+ config.version_game = "1.1"
26
+ config.version_league = "2.1"
27
+ config.version_stats = "1.1"
28
+ config.version_summoner = "1.1"
29
+ config.version_team = "2.1"
30
+ end
31
+
32
+ ### 2. Connection
33
+
34
+ connection = LoLBase.new "your-api-key-here"
35
+
36
+ All connections begin by calling *LoLBase::new* which takes an API key as an argument (this can be left blank if it was provided in the config). Multiple connections can be used if you have more than one key available to you.
37
+
38
+ ### 3. Data Retrieval
39
+
40
+ #### 3.1 Summoner
41
+
42
+ # Fetch a summoner by their name...
43
+ summoner = connection.summoner("A Summoner Name", "na")
44
+
45
+ # ...or by their ID
46
+ summoner = connection.summoner(12345, "euw")
47
+
48
+ # Retrieve data associated to the summoner
49
+ summoner.id
50
+ summoner.name
51
+ summoner.region
52
+ summoner.profileIconId
53
+ summoner.revisionDate
54
+ summoner.revisionDateStr
55
+ summoner.summonerLevel
56
+
57
+ ## To Do
58
+
59
+ This gem is still missing a lot of functionality, but most of it will be added over time.
60
+
61
+ * Champion list
62
+ * Recent games
63
+ * League data
64
+ * Stats
65
+ * Summary
66
+ * Ranked
67
+ * Summoner
68
+ * Masteries
69
+ * Runes
70
+ * ~~Find by name~~
71
+ * ~~Find by ID~~
72
+ * List of names by ID
73
+ * Teams
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ module LoLBase
2
+ class << self
3
+ attr_reader :config
4
+
5
+ def configure(&block)
6
+ yield @config ||= Configuration.new
7
+ end
8
+ end
9
+
10
+ class Configuration
11
+ attr_accessor :default_region,
12
+ :default_key,
13
+ :version_champion,
14
+ :version_game,
15
+ :version_league,
16
+ :version_stats,
17
+ :version_summoner,
18
+ :version_team
19
+ end
20
+
21
+ # Default config values
22
+ configure do |config|
23
+ config.default_region = "na"
24
+
25
+ config.version_champion = "1.1"
26
+ config.version_game = "1.1"
27
+ config.version_league = "2.1"
28
+ config.version_stats = "1.1"
29
+ config.version_summoner = "1.1"
30
+ config.version_team = "2.1"
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ require 'httparty'
2
+
3
+ module LoLBase
4
+ def self.new(key = nil)
5
+ return Connection.new(key)
6
+ end
7
+
8
+ class Connection
9
+ include HTTParty
10
+ base_uri "https://prod.api.pvp.net"
11
+
12
+ # Override HTTParty's get method to append the API key and to process errors returned from request
13
+ def get(path, options = {})
14
+ if options[:query].nil?
15
+ options.merge!({ query: { api_key: @key } })
16
+ else
17
+ options[:query].merge!({ api_key: @key })
18
+ end
19
+
20
+ response = self.class.get path, options
21
+ raise LoLBaseError, response.message if response.code != 200
22
+ response.body
23
+ end
24
+
25
+ def initialize(key = nil)
26
+ @key = key || LoLBase.config.default_key
27
+ self
28
+ end
29
+
30
+ # Syntactic sugar: lookup summoner by name or by ID
31
+ def summoner(identifier, region = LoLBase.config.default_region)
32
+ if identifier.is_a? String
33
+ return summoner_by_name(identifier, region)
34
+ else
35
+ return summoner_by_id(identifier, region)
36
+ end
37
+ end
38
+
39
+ def summoner_by_name(name, region = LoLBase.config.default_region)
40
+ return Summoner.new({ name: name, region: region }, self)
41
+ end
42
+
43
+ def summoner_by_id(id, region = LoLBase.config.default_region)
44
+ return Summoner.new({ id: id, region: region }, self)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ require "json"
2
+
3
+ module LoLBase
4
+ class Summoner
5
+ attr_reader :id, :name, :profileIconId, :revisionDate, :revisionDateStr, :summonerLevel, :region
6
+
7
+ # Input
8
+ # - params - A hash containing either a summoner name or ID and the region that they belong to
9
+ # (e.g. { id: 123, region: "na" })
10
+ # - connection - Current connection to the Riot API
11
+ #
12
+ # Effects: Calls the Riot API to retrieve data for the given summoner
13
+ #
14
+ # Output: Returns the Summoner class for further chaining
15
+ def initialize(params, connection)
16
+ @id = params[:id]
17
+ @name = params[:name]
18
+ @region = params[:region]
19
+ @connection = connection
20
+
21
+ response =
22
+ if !@id.nil?
23
+ # Find summoner by ID
24
+ connection.get "/api/lol/#{@region}/v#{LoLBase.config.version_summoner}/summoner/#{@id}"
25
+ else
26
+ # Find summoner by name
27
+ connection.get "/api/lol/#{@region}/v#{LoLBase.config.version_summoner}/summoner/by-name/#{@name}"
28
+ end
29
+
30
+ # Populate object with response data
31
+ data = JSON.parse(response)
32
+ @id = data["id"]
33
+ @name = data["name"]
34
+ @profileIconId = data["profileIconId"]
35
+ @revisionDate = data["revisionDate"]
36
+ @revisionDateStr = data["revisionDateStr"]
37
+ @summonerLevel = data["summonerLevel"]
38
+
39
+ self
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,4 @@
1
+ module LoLBase
2
+ class LoLBaseError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module LoLBase
2
+ VERSION = "0.1.0"
3
+ end
data/lib/lolbase.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "lolbase/configuration"
2
+ require "lolbase/connection"
3
+ require "lolbase/error"
4
+
5
+ require "lolbase/data/summoner"
data/lolbase.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "lolbase/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lolbase"
8
+ spec.version = LoLBase::VERSION
9
+ spec.authors = ["Regan Chan"]
10
+ spec.email = [""]
11
+ spec.description = %q{A basic Ruby wrapper for the League of Legends API.}
12
+ spec.summary = %q{A basic Ruby wrapper for the League of Legends API.}
13
+ spec.homepage = "https://github.com/Illianthe/lolbase"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+
26
+ spec.add_runtime_dependency "httparty"
27
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe LoLBase::Connection do
4
+ before do
5
+ @connection = LoLBase.new "random-key"
6
+ end
7
+
8
+ it "rejects requests with an invalid API key" do
9
+ stub_request(:get, "http://www.irythia.com/invalid_api_key").with(query: { api_key: "random-key" }).to_return(status: 400)
10
+ expect { @connection.get "http://www.irythia.com/invalid_api_key" }.to raise_error(LoLBase::LoLBaseError)
11
+ end
12
+
13
+ it "returns an error if rate limits were reached" do
14
+ stub_request(:get, "http://www.irythia.com/rate_limited").with(query: { api_key: "random-key" }).to_return(status: 429)
15
+ expect { @connection.get "http://www.irythia.com/rate_limited" }.to raise_error(LoLBase::LoLBaseError)
16
+ end
17
+
18
+ it "returns an error if request can not be processed (data not found, etc.)" do
19
+ stub_request(:get, "http://www.irythia.com/not_found").with(query: { api_key: "random-key" }).to_return(status: 404)
20
+ expect { @connection.get "http://www.irythia.com/not_found" }.to raise_error(LoLBase::LoLBaseError)
21
+ end
22
+
23
+ it "returns an error if the API server is experiencing issues" do
24
+ stub_request(:get, "http://www.irythia.com/server_error").with(query: { api_key: "random-key" }).to_return(status: 500)
25
+ expect { @connection.get "http://www.irythia.com/server_error" }.to raise_error(LoLBase::LoLBaseError)
26
+ end
27
+
28
+ it "should allow for multiple connections using differing API keys" do
29
+ stub_request(:get, "http://www.irythia.com/ok").with(query: { api_key: "random-key" }).to_return(status: 200, body: "random-key")
30
+ stub_request(:get, "http://www.irythia.com/ok").with(query: { api_key: "random-key-2" }).to_return(status: 200, body: "random-key-2")
31
+
32
+ @connection2 = LoLBase.new "random-key-2"
33
+
34
+ expect(@connection.get "http://www.irythia.com/ok").to eq("random-key")
35
+ expect(@connection2.get "http://www.irythia.com/ok").to eq("random-key-2")
36
+ end
37
+
38
+ it "should create a connection using the default key if none specified" do
39
+ LoLBase.configure do |config|
40
+ config.default_key = "blah"
41
+ end
42
+
43
+ stub_request(:get, "http://www.irythia.com/ok").with(query: { api_key: "blah" }).to_return(status: 200, body: "blah")
44
+ connection = LoLBase.new
45
+ expect(connection.get "http://www.irythia.com/ok").to eq("blah")
46
+ end
47
+ end
data/spec/data_spec.rb ADDED
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe "LoLBase Data" do
4
+ before do
5
+ @connection = LoLBase.new "random-key"
6
+ end
7
+
8
+ context "Summoner" do
9
+ it "should return summoner data when requested" do
10
+ file = File.read(File.expand_path("../json/summoner.json", __FILE__))
11
+ stub_request(:get, "https://prod.api.pvp.net/api/lol/na/v1.1/summoner/by-name/illianthe?api_key=random-key").to_return(status: 200, body: file)
12
+
13
+ illianthe = @connection.summoner("illianthe")
14
+ expect(illianthe.id).to eq(19578577)
15
+ expect(illianthe.name).to eq("Illianthe")
16
+ expect(illianthe.profileIconId).to eq(539)
17
+ expect(illianthe.revisionDate).to eq(1386988105000)
18
+ expect(illianthe.revisionDateStr).to eq("12/14/2013 02:28 AM UTC")
19
+ expect(illianthe.summonerLevel).to eq(30)
20
+ expect(illianthe.region).to eq("na")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "revisionDateStr": "12/14/2013 02:28 AM UTC",
3
+ "id": 19578577,
4
+ "name": "Illianthe",
5
+ "profileIconId": 539,
6
+ "revisionDate": 1386988105000,
7
+ "summonerLevel": 30
8
+ }
@@ -0,0 +1,2 @@
1
+ require "webmock/rspec"
2
+ require "lolbase"
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolbase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Regan Chan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A basic Ruby wrapper for the League of Legends API.
84
+ email:
85
+ - ''
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/lolbase.rb
96
+ - lib/lolbase/configuration.rb
97
+ - lib/lolbase/connection.rb
98
+ - lib/lolbase/data/summoner.rb
99
+ - lib/lolbase/error.rb
100
+ - lib/lolbase/version.rb
101
+ - lolbase.gemspec
102
+ - spec/connection_spec.rb
103
+ - spec/data_spec.rb
104
+ - spec/json/summoner.json
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/Illianthe/lolbase
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A basic Ruby wrapper for the League of Legends API.
130
+ test_files:
131
+ - spec/connection_spec.rb
132
+ - spec/data_spec.rb
133
+ - spec/json/summoner.json
134
+ - spec/spec_helper.rb
135
+ has_rdoc: