league_of_legends 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69d531bb9522870e6d2b2f4c641fd2b8cca0f28b
4
- data.tar.gz: 63d6949c7a40c92127769f36ea0bc078fb126882
3
+ metadata.gz: 88d301f5ac4bd1cbfce2d325c27fc7b812e9c6fc
4
+ data.tar.gz: 95bc9470c025d4d4c878b07d3094504fd1354f03
5
5
  SHA512:
6
- metadata.gz: c26c44e5243efe607d6a462d4e477cae4f18e1c1f80794001e5275193e1ee6199e932943aceb60671cd67330b8f276d2fabb4b2f1e13787d01d9ad6480699159
7
- data.tar.gz: a783c48faa899654dd5f5ab616a8603cfba113815617ae027dafc00b0adba94ec0762f0cb913daf4c1770f51750ffc76565d210569235f153696adc483f79b47
6
+ metadata.gz: 20670ef360d1c4bc57658e49234f2d2c99f3ed832ac42cc47e2a3cc5445aef0f5c6645f3088f7e0c3b4d2c6ad2dadab560d08ccccfe0846161c7e92c04f5b4db
7
+ data.tar.gz: 26b7b4a92f6eb33ce2f7fe4383d536287ade407ced096cedfa78ba58e2130f022c35aafeee9cf3223133f0b3eafafd9e8916b3539c10af10f4ff18bca76be130
data/README.md CHANGED
@@ -20,14 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- The gem is still not (properly) usable at this point. It is a work in progress! :)
23
+ The gem is still a work in progress and has limited functionality.
24
24
 
25
- To work with it (until the next version comes out!), change the code in lib/league_of_legends/api.rb to return your actual API key.
25
+ # create a new instance of the API
26
+ lol_api = ::LeagueOfLegends::Api.new <api key>
26
27
 
27
- Then you can do:
28
+ # get all available request types
29
+ lol_api.available_request
28
30
 
29
- sss_request = ::LeagueOfLegends::Request::Stats::BySummoner::Summary.new <summoner_id>
30
- sss_request.response # => ::LeagueOfLegends::DTO::PlayerStatsSummaryList
31
+ # execute a request
32
+ result_dto = lol_api.get(:summoner_stats_summary, <summoner id>)
33
+
34
+
35
+ In this example, the DTO returned is a `::LeagueOfLegends::DTO::PlayerStatsSummaryList`.
31
36
 
32
37
  You can read about each Request and DTO at http://developer.riotgames.com/api/methods
33
38
 
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["francisco.orvalho@gmail.com"]
11
11
  spec.summary = %q{Implementation of the LoL API}
12
12
  spec.description = %q{This gem implements the League Of Legends API (currently in open beta). It will continue to be updated as the API evolves.
13
+ Please see the README at https://github.com/forvalho/league_of_legends/blob/master/README.md
13
14
 
14
15
  This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.}
15
16
  spec.homepage = "http://github.com/forvalho/league_of_legends"
@@ -1,12 +1,66 @@
1
+ require 'league_of_legends/request/all'
2
+
1
3
  module ::LeagueOfLegends
2
4
  class Api
3
5
 
4
- def self.key
5
- 'a1a1a1-b2b2b2-c3c3c3-d4d4d4-e5e5e5e5'
6
+ attr_reader :key, :base_url
7
+
8
+ def initialize options = {}
9
+ case options
10
+ when Hash
11
+ opt = self.class.default_options.merge(options)
12
+ set_key(opt[:key])
13
+ set_base_url(opt[:base_url])
14
+ when String
15
+ set_key(options)
16
+ set_base_url(self.class.default_options[:base_url])
17
+ else
18
+ raise ArgumentError.new 'expected a Hash or a String'
19
+ end
20
+ end
21
+
22
+ def self.default_options
23
+ {
24
+ key: nil,
25
+ base_url: 'https://prod.api.pvp.net/api/lol'
26
+ }
27
+ end
28
+
29
+ def get request, *arguments
30
+ req_class = ::LeagueOfLegends::Request::Mapper.get(request.to_sym)
31
+ request = req_class.new self, *arguments
32
+ request.response
6
33
  end
7
34
 
8
- def self.base_url
9
- 'https://prod.api.pvp.net/api/lol'
35
+ def available_requests
36
+ ::LeagueOfLegends::Request::Mapper.available
37
+ end
38
+
39
+ private
40
+
41
+ def set_key key = nil
42
+ case key
43
+ when nil
44
+ raise ArgumentError.new 'wrong number of arguments (0 for 1)'
45
+ when String
46
+ if key =~ /^\h{8}(-\h{4}){3}-\h{12}$/
47
+ @key = key
48
+ else
49
+ raise ArgumentError.new 'key with incorrect format'
50
+ end
51
+ else
52
+ raise ArgumentError.new 'expected a String'
53
+ end
54
+ end
55
+
56
+ def set_base_url base_url
57
+ require 'uri'
58
+
59
+ if base_url =~ /^#{URI::regexp}$/o
60
+ @base_url = base_url
61
+ else
62
+ raise ArgumentError.new 'expected a valid URL'
63
+ end
10
64
  end
11
65
 
12
66
  end
@@ -0,0 +1,3 @@
1
+ require 'league_of_legends/request/mapper'
2
+ require 'league_of_legends/request/base'
3
+ require 'league_of_legends/request/stats/by_summoner/summary'
@@ -6,9 +6,8 @@ module ::LeagueOfLegends
6
6
  class Base
7
7
  require 'net/http'
8
8
 
9
- def self.options
10
- @options ||= default_options
11
- end
9
+
10
+ attr_reader :options
12
11
 
13
12
  def self.default_options
14
13
  {
@@ -25,15 +24,16 @@ module ::LeagueOfLegends
25
24
  dto_class.version
26
25
  end
27
26
 
28
- def self.region
27
+ def region
29
28
  options[:region]
30
29
  end
31
30
 
32
- def self.api_key
33
- ::LeagueOfLegends::Api.key
31
+ def api_key
32
+ api.key
34
33
  end
35
34
 
36
- def initialize options = {}
35
+ def initialize api, options = {}
36
+ @api = api
37
37
  @options = self.class.default_options.merge(options)
38
38
  end
39
39
 
@@ -50,25 +50,26 @@ module ::LeagueOfLegends
50
50
 
51
51
  protected
52
52
 
53
+ attr_reader :api
54
+
53
55
  def base_url
54
56
  [
55
- ::LeagueOfLegends::Api.base_url,
56
- self.class.region,
57
+ api.base_url,
58
+ region,
57
59
  self.class.version
58
- ].join('/')
60
+ ]
59
61
  end
60
62
 
61
63
  def url_parameters
62
64
  [
63
- "?api_key=#{self.class.api_key}"
64
- ].join('&')
65
+ "api_key=#{api_key}"
66
+ ]
65
67
  end
66
68
 
67
-
68
69
  private
69
70
 
70
71
  def url
71
- base_url + url_parameters
72
+ "#{base_url.join('/')}?#{url_parameters.join('&')}"
72
73
  end
73
74
 
74
75
  def send_request
@@ -0,0 +1,37 @@
1
+ module ::LeagueOfLegends
2
+ module Request
3
+ class Mapper
4
+
5
+ class << self
6
+
7
+ def get request_name
8
+ get_info(request_name)[:class]
9
+ end
10
+
11
+ def get_info request_name
12
+ map[request_name.to_sym]
13
+ end
14
+
15
+ def available? request_name
16
+ map.has_key? request_name
17
+ end
18
+
19
+ def available
20
+ map.keys
21
+ end
22
+
23
+ private
24
+
25
+ def map
26
+ @map ||= {
27
+ summoner_stats_summary: {
28
+ class: ::LeagueOfLegends::Request::Stats::BySummoner::Summary,
29
+ },
30
+ }
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -7,10 +7,10 @@ module ::LeagueOfLegends
7
7
  module BySummoner
8
8
  class Summary < ::LeagueOfLegends::Request::Base
9
9
 
10
- attr_reader :summoner_id, :options
10
+ attr_reader :summoner_id
11
11
 
12
- def initialize summoner_id, options = {}
13
- super(options)
12
+ def initialize api, summoner_id, options = {}
13
+ super(api, options)
14
14
  @summoner_id = summoner_id
15
15
  end
16
16
 
@@ -21,7 +21,7 @@ module ::LeagueOfLegends
21
21
  protected
22
22
 
23
23
  def base_url
24
- super + "/stats/by-summoner/#{summoner_id}/summary"
24
+ super << "stats/by-summoner/#{summoner_id}/summary"
25
25
  end
26
26
 
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module LeagueOfLegends
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,13 +2,25 @@ require 'league_of_legends/api'
2
2
 
3
3
  describe ::LeagueOfLegends::Api do
4
4
 
5
- it "has an API key" do
6
- expect(described_class.key).to be_an_instance_of String
7
- expect(described_class.key.length).to eq 36
5
+ let(:api) { ::LeagueOfLegends::Api.new '0c78469b-b773-4b35-9f6a-00d7fe964290
6
+ ' }
7
+
8
+ it "has access to an API key" do
9
+ pending "testing with real key"
10
+ expect(api.key).to eq 'a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1'
8
11
  end
9
12
 
10
13
  it "has a base url" do
11
- expect(described_class.base_url).to eq 'https://prod.api.pvp.net/api/lol'
14
+ expect(api.base_url).to eq 'https://prod.api.pvp.net/api/lol'
15
+ end
16
+
17
+ it "can get a list of available requests" do
18
+ expect(api.available_requests).to be_kind_of Enumerable
19
+ end
20
+
21
+ it "can send requests and receive a response" do
22
+ pending "requires internet connection"
23
+ expect(api.get(:summoner_stats_summary, 12345)).to be_an_instance_of ::LeagueOfLegends::DTO::PlayerStatsSummaryList
12
24
  end
13
25
 
14
26
  end
@@ -2,19 +2,21 @@ require 'league_of_legends/request/base'
2
2
 
3
3
  describe ::LeagueOfLegends::Request::Base do
4
4
 
5
+ let(:api) { ::LeagueOfLegends::Api.new 'a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1' }
6
+
5
7
  it "exposes methods to it's children" do
6
8
  class ReqTest < described_class
7
9
  def self.version; 'xx'; end
8
10
  def self.dto_class; ReqTest; end
9
11
  end
10
- req_test = ReqTest.new
12
+ req_test = ReqTest.new api
11
13
 
12
- expect(ReqTest.respond_to? :options).to be_true
13
14
  expect(ReqTest.respond_to? :default_options).to be_true
14
15
  expect(ReqTest.respond_to? :dto_class).to be_true
15
16
  expect(ReqTest.respond_to? :version).to be_true
16
- expect(ReqTest.respond_to? :region).to be_true
17
- expect(ReqTest.respond_to? :api_key).to be_true
17
+ expect(req_test.respond_to? :options).to be_true
18
+ expect(req_test.respond_to? :region).to be_true
19
+ expect(req_test.respond_to? :api_key).to be_true
18
20
  expect(req_test.respond_to? :response).to be_true
19
21
 
20
22
  expect(req_test.respond_to? :url).to be_false
@@ -0,0 +1,10 @@
1
+ require 'league_of_legends/request/mapper'
2
+
3
+ describe ::LeagueOfLegends::Request::Mapper do
4
+
5
+ it "knows the class for certain requests" do
6
+ req = described_class.get :summoner_stats_summary
7
+ expect(req).to eq ::LeagueOfLegends::Request::Stats::BySummoner::Summary
8
+ end
9
+
10
+ end
@@ -2,19 +2,22 @@ require 'league_of_legends/request/stats/by_summoner/summary'
2
2
 
3
3
  describe ::LeagueOfLegends::Request::Stats::BySummoner::Summary do
4
4
 
5
- let(:request) { described_class.new 50519866 }
5
+ let(:api) { ::LeagueOfLegends::Api.new 'a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1' }
6
+
7
+ let(:request) { described_class.new api, 50519866 }
6
8
 
7
9
  it "has the required parameters" do
8
10
  expect(described_class.dto_class).to eq ::LeagueOfLegends::DTO::PlayerStatsSummaryList
9
- expect(described_class.region).to eq 'euw'
10
11
  expect(described_class.version).to eq 'v1.2'
11
- expect(described_class.api_key).to be_an_instance_of String
12
- expect(described_class.api_key.length).to eq 36
12
+ expect(request.region).to eq 'euw'
13
+ expect(request.api_key).to be_an_instance_of String
14
+ expect(request.api_key.length).to eq 36
13
15
 
14
16
  expect(request.summoner_id).to eq 50519866
15
17
  end
16
18
 
17
19
  it "can be sent and get a response" do
20
+ pending "requires internet connection"
18
21
  expect(request.response).to be_an_instance_of ::LeagueOfLegends::DTO::PlayerStatsSummaryList
19
22
  end
20
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: league_of_legends
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Orvalho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-25 00:00:00.000000000 Z
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -40,6 +40,7 @@ dependencies:
40
40
  version: '0'
41
41
  description: |-
42
42
  This gem implements the League Of Legends API (currently in open beta). It will continue to be updated as the API evolves.
43
+ Please see the README at https://github.com/forvalho/league_of_legends/blob/master/README.md
43
44
 
44
45
  This product is not endorsed, certified or otherwise approved in any way by Riot Games, Inc. or any of its affiliates.
45
46
  email:
@@ -62,7 +63,9 @@ files:
62
63
  - lib/league_of_legends/dto/champion_list.rb
63
64
  - lib/league_of_legends/dto/player_stats_summary.rb
64
65
  - lib/league_of_legends/dto/player_stats_summary_list.rb
66
+ - lib/league_of_legends/request/all.rb
65
67
  - lib/league_of_legends/request/base.rb
68
+ - lib/league_of_legends/request/mapper.rb
66
69
  - lib/league_of_legends/request/stats/by_summoner/summary.rb
67
70
  - lib/league_of_legends/version.rb
68
71
  - spec/league_of_legends/api_spec.rb
@@ -73,6 +76,7 @@ files:
73
76
  - spec/league_of_legends/dto/player_stats_summary_list_spec.rb
74
77
  - spec/league_of_legends/dto/player_stats_summary_spec.rb
75
78
  - spec/league_of_legends/request/base_spec.rb
79
+ - spec/league_of_legends/request/mapper_spec.rb
76
80
  - spec/league_of_legends/request/stats/by_summoner/summary_spec.rb
77
81
  homepage: http://github.com/forvalho/league_of_legends
78
82
  licenses:
@@ -107,4 +111,6 @@ test_files:
107
111
  - spec/league_of_legends/dto/player_stats_summary_list_spec.rb
108
112
  - spec/league_of_legends/dto/player_stats_summary_spec.rb
109
113
  - spec/league_of_legends/request/base_spec.rb
114
+ - spec/league_of_legends/request/mapper_spec.rb
110
115
  - spec/league_of_legends/request/stats/by_summoner/summary_spec.rb
116
+ has_rdoc: