vigor 0.3.1 → 0.4.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.
- data/lib/vigor.rb +1 -0
- data/lib/vigor/client.rb +9 -0
- data/lib/vigor/error.rb +34 -0
- data/spec/cassettes/Vigor_Client/raises_an_exception_when_no_summoner_id_exists.yml +89 -0
- data/spec/cassettes/Vigor_Client/raises_an_exception_when_no_summoner_name_exists.yml +53 -0
- data/spec/cassettes/Vigor_Client/raises_an_exception_when_using_a_bad_key.yml +53 -0
- data/spec/client_spec.rb +23 -0
- data/spec/spec_helper.rb +1 -0
- metadata +8 -1
data/lib/vigor.rb
CHANGED
data/lib/vigor/client.rb
CHANGED
@@ -17,5 +17,14 @@ module Vigor
|
|
17
17
|
return Summoner.new(self.class.get("/summoner/" + lookup_value.to_s))
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.get(path)
|
24
|
+
response = super
|
25
|
+
raise Vigor::Error.from_status(response.code), response.message unless response.code == 200
|
26
|
+
return response
|
27
|
+
end
|
28
|
+
|
20
29
|
end
|
21
30
|
end
|
data/lib/vigor/error.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Vigor
|
2
|
+
module Error
|
3
|
+
|
4
|
+
def self.from_status(status)
|
5
|
+
case status
|
6
|
+
when 400
|
7
|
+
BadRequest
|
8
|
+
when 401
|
9
|
+
Unauthorized
|
10
|
+
when 404
|
11
|
+
SummonerNotFound
|
12
|
+
when 500
|
13
|
+
InternalServerError
|
14
|
+
else
|
15
|
+
ApiError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ApiError < StandardError; end
|
20
|
+
|
21
|
+
# 400 response - invalid API endpoint. Should never be raised if gem build is stable,
|
22
|
+
class BadRequest < ApiError; end
|
23
|
+
|
24
|
+
# 401 response - when API_KEY is missing or invalid,
|
25
|
+
class Unauthorized < ApiError; end
|
26
|
+
|
27
|
+
# 404 response - no summoner found,
|
28
|
+
class SummonerNotFound < ApiError; end
|
29
|
+
|
30
|
+
# 500 response - when Riot's API is down.
|
31
|
+
class InternalServerError < ApiError; end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://prod.api.pvp.net/api/lol/na/v1.1/summoner/31640240?api_key=<API_KEY>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Access-Control-Allow-Headers:
|
16
|
+
- Content-Type
|
17
|
+
Access-Control-Allow-Methods:
|
18
|
+
- GET, POST, DELETE, PUT
|
19
|
+
Access-Control-Allow-Origin:
|
20
|
+
- ! '*'
|
21
|
+
Content-Type:
|
22
|
+
- application/json;charset=UTF-8
|
23
|
+
Date:
|
24
|
+
- Sat, 14 Dec 2013 00:40:19 GMT
|
25
|
+
Server:
|
26
|
+
- Jetty(9.1.0.v20131115)
|
27
|
+
X-Newrelic-App-Data:
|
28
|
+
- PxQFWFFSDwQTVVdUBAgAVkYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOA0dYa0kIXlpvTR0RB1cLVwxFZBtEAksIPR4SRg8JWVkEFD8XSEMRDA9YX1IULVVLE0ohJjYZQBRSFggYAh1VCVIDUwpSXAcbTFdPGgcIBQNVAVQGBFMEDgNTBFpAbQ==
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
body:
|
34
|
+
encoding: US-ASCII
|
35
|
+
string: ! '{"id":31640240,"name":"IS11f9c710874850c9b7b3c","profileIconId":9,"summonerLevel":1,"revisionDate":1371607602000,"revisionDateStr":"06/19/2013
|
36
|
+
02:06 AM UTC"}'
|
37
|
+
http_version:
|
38
|
+
recorded_at: Sat, 14 Dec 2013 00:40:03 GMT
|
39
|
+
- request:
|
40
|
+
method: get
|
41
|
+
uri: http://prod.api.pvp.net/api/lol/na/v1.1/summoner/0?api_key=<API_KEY>
|
42
|
+
body:
|
43
|
+
encoding: US-ASCII
|
44
|
+
string: ''
|
45
|
+
headers: {}
|
46
|
+
response:
|
47
|
+
status:
|
48
|
+
code: 404
|
49
|
+
message: Not Found
|
50
|
+
headers:
|
51
|
+
Access-Control-Allow-Headers:
|
52
|
+
- Content-Type
|
53
|
+
Access-Control-Allow-Methods:
|
54
|
+
- GET, POST, DELETE, PUT
|
55
|
+
Access-Control-Allow-Origin:
|
56
|
+
- ! '*'
|
57
|
+
Cache-Control:
|
58
|
+
- must-revalidate,no-cache,no-store
|
59
|
+
Content-Type:
|
60
|
+
- text/html; charset=UTF-8
|
61
|
+
Date:
|
62
|
+
- Sat, 14 Dec 2013 01:11:39 GMT
|
63
|
+
Server:
|
64
|
+
- Jetty(9.1.0.v20131115)
|
65
|
+
X-Newrelic-App-Data:
|
66
|
+
- PxQFWFFSDwQTVVdUBAgAVkYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOA0dYa0kIXlpvTR0RB1cLVwxFZBtEAksIPR4SRg8JWVkEFD8XSEMRDA9YX1IULVVLE0ohJjYZQBRSFggYAh1VDlMJVQNWVhoaUEpBD1YFXVFWUgBVUQdQAVZWAkE/
|
67
|
+
Transfer-Encoding:
|
68
|
+
- chunked
|
69
|
+
Connection:
|
70
|
+
- keep-alive
|
71
|
+
body:
|
72
|
+
encoding: US-ASCII
|
73
|
+
string: ! "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;
|
74
|
+
charset=ISO-8859-1\"/>\n<title>Error 404 Not Found</title>\n</head>\n<body><h2>HTTP
|
75
|
+
ERROR 404</h2>\n<p>Problem accessing /api/lol/na/v1.1/summoner/0. Reason:\n<pre>
|
76
|
+
\ Not Found</pre></p><br/> \n<br/>
|
77
|
+
\ \n<br/> \n<br/>
|
78
|
+
\ \n<br/> \n<br/>
|
79
|
+
\ \n<br/> \n<br/>
|
80
|
+
\ \n<br/> \n<br/>
|
81
|
+
\ \n<br/> \n<br/>
|
82
|
+
\ \n<br/> \n<br/>
|
83
|
+
\ \n<br/> \n<br/>
|
84
|
+
\ \n<br/> \n<br/>
|
85
|
+
\ \n<br/> \n<br/>
|
86
|
+
\ \n\n</body>\n</html>\n"
|
87
|
+
http_version:
|
88
|
+
recorded_at: Sat, 14 Dec 2013 01:11:23 GMT
|
89
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://prod.api.pvp.net/api/lol/na/v1.1/summoner/by-name/invalid1234?api_key=<API_KEY>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 404
|
13
|
+
message: Not Found
|
14
|
+
headers:
|
15
|
+
Access-Control-Allow-Headers:
|
16
|
+
- Content-Type
|
17
|
+
Access-Control-Allow-Methods:
|
18
|
+
- GET, POST, DELETE, PUT
|
19
|
+
Access-Control-Allow-Origin:
|
20
|
+
- ! '*'
|
21
|
+
Cache-Control:
|
22
|
+
- must-revalidate,no-cache,no-store
|
23
|
+
Content-Type:
|
24
|
+
- text/html; charset=UTF-8
|
25
|
+
Date:
|
26
|
+
- Sat, 14 Dec 2013 00:38:22 GMT
|
27
|
+
Server:
|
28
|
+
- Jetty(9.1.0.v20131115)
|
29
|
+
X-Newrelic-App-Data:
|
30
|
+
- PxQFWFFSDwQTVVdUBAgAVkYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOA0dYa0kIXlpvTR0RB1cLVwxFZBtEAksIPR4SRg8JWVkEFD8XUUlJDwNaVGtJH19XXgcbQ0p3J2xLGhQEHANJCU8BVApQVgMCU1BPFQIcRgRXAQhRUVRTU1EGV1ABCQMaPw==
|
31
|
+
Content-Length:
|
32
|
+
- '1362'
|
33
|
+
Connection:
|
34
|
+
- keep-alive
|
35
|
+
body:
|
36
|
+
encoding: US-ASCII
|
37
|
+
string: ! "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;
|
38
|
+
charset=ISO-8859-1\"/>\n<title>Error 404 Not Found</title>\n</head>\n<body><h2>HTTP
|
39
|
+
ERROR 404</h2>\n<p>Problem accessing /api/lol/na/v1.1/summoner/by-name/invalid1234.
|
40
|
+
Reason:\n<pre> Not Found</pre></p><br/> \n<br/>
|
41
|
+
\ \n<br/> \n<br/>
|
42
|
+
\ \n<br/> \n<br/>
|
43
|
+
\ \n<br/> \n<br/>
|
44
|
+
\ \n<br/> \n<br/>
|
45
|
+
\ \n<br/> \n<br/>
|
46
|
+
\ \n<br/> \n<br/>
|
47
|
+
\ \n<br/> \n<br/>
|
48
|
+
\ \n<br/> \n<br/>
|
49
|
+
\ \n<br/> \n<br/>
|
50
|
+
\ \n\n</body>\n</html>\n"
|
51
|
+
http_version:
|
52
|
+
recorded_at: Sat, 14 Dec 2013 00:38:06 GMT
|
53
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,53 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://prod.api.pvp.net/api/lol/na/v1.1/summoner/by-name/Semiel?api_key=bad_key
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 401
|
13
|
+
message: Unauthorized
|
14
|
+
headers:
|
15
|
+
Content-Type:
|
16
|
+
- application/json;charset=UTF-8
|
17
|
+
Server:
|
18
|
+
- Jetty(9.1.0.v20131115)
|
19
|
+
Content-Length:
|
20
|
+
- '60'
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
body:
|
24
|
+
encoding: US-ASCII
|
25
|
+
string: ! '{"status": {"message": "Access denied", "status_code": 401}}'
|
26
|
+
http_version:
|
27
|
+
recorded_at: Sat, 14 Dec 2013 00:36:15 GMT
|
28
|
+
- request:
|
29
|
+
method: get
|
30
|
+
uri: http://prod.api.pvp.net/api/lol/na/v1.1/summoner/by-name/semiel?api_key=bad_key
|
31
|
+
body:
|
32
|
+
encoding: US-ASCII
|
33
|
+
string: ''
|
34
|
+
headers: {}
|
35
|
+
response:
|
36
|
+
status:
|
37
|
+
code: 401
|
38
|
+
message: Unauthorized
|
39
|
+
headers:
|
40
|
+
Content-Type:
|
41
|
+
- application/json;charset=UTF-8
|
42
|
+
Server:
|
43
|
+
- Jetty(9.1.0.v20131115)
|
44
|
+
Content-Length:
|
45
|
+
- '60'
|
46
|
+
Connection:
|
47
|
+
- keep-alive
|
48
|
+
body:
|
49
|
+
encoding: US-ASCII
|
50
|
+
string: ! '{"status": {"message": "Access denied", "status_code": 401}}'
|
51
|
+
http_version:
|
52
|
+
recorded_at: Sat, 14 Dec 2013 01:13:19 GMT
|
53
|
+
recorded_with: VCR 2.8.0
|
data/spec/client_spec.rb
CHANGED
@@ -32,4 +32,27 @@ describe Vigor::Client, :vcr do
|
|
32
32
|
summoner.name.should == "Best Riven NA"
|
33
33
|
summoner.level.should == 30
|
34
34
|
end
|
35
|
+
|
36
|
+
it "raises an exception when using a bad key" do
|
37
|
+
vigor = Vigor::Client.new("bad_key")
|
38
|
+
lambda { vigor.summoner("semiel") }.should raise_error(Vigor::Error::Unauthorized)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an exception when no summoner name exists" do
|
42
|
+
vigor = Vigor::Client.new(ENV["API_KEY"])
|
43
|
+
lambda { vigor.summoner("invalid1234") }.should raise_error(Vigor::Error::SummonerNotFound)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raises an exception when no summoner id exists" do
|
47
|
+
vigor = Vigor::Client.new(ENV["API_KEY"])
|
48
|
+
lambda { vigor.summoner(0)}.should raise_error(Vigor::Error::SummonerNotFound)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raises an exception when the API is down" do
|
52
|
+
stub_request(:get, "http://prod.api.pvp.net/api/lol/na/v1.1/summoner/by-name/semiel?api_key=#{ENV["API_KEY"]}").
|
53
|
+
to_return(:status => 500, :body => "", :headers => {})
|
54
|
+
vigor = Vigor::Client.new(ENV["API_KEY"])
|
55
|
+
lambda { vigor.summoner("semiel") }.should raise_error(Vigor::Error::InternalServerError)
|
56
|
+
end
|
57
|
+
|
35
58
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vigor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/vigor/client.rb
|
86
86
|
- lib/vigor/summoner.rb
|
87
87
|
- lib/vigor/rune_page.rb
|
88
|
+
- lib/vigor/error.rb
|
88
89
|
- lib/vigor/page.rb
|
89
90
|
- lib/vigor/talent.rb
|
90
91
|
- lib/vigor/mastery_page.rb
|
@@ -95,7 +96,10 @@ files:
|
|
95
96
|
- spec/cassettes/Vigor_Client/works_on_servers_other_than_NA.yml
|
96
97
|
- spec/cassettes/Vigor_Client/can_find_a_summoner_by_name.yml
|
97
98
|
- spec/cassettes/Vigor_Client/can_find_a_summoner_by_id.yml
|
99
|
+
- spec/cassettes/Vigor_Client/raises_an_exception_when_no_summoner_id_exists.yml
|
100
|
+
- spec/cassettes/Vigor_Client/raises_an_exception_when_no_summoner_name_exists.yml
|
98
101
|
- spec/cassettes/Vigor_Client/can_find_summoners_whose_names_have_whitespace.yml
|
102
|
+
- spec/cassettes/Vigor_Client/raises_an_exception_when_using_a_bad_key.yml
|
99
103
|
- spec/cassettes/Vigor_Summoner/can_fetch_runes.yml
|
100
104
|
- spec/cassettes/Vigor_Summoner/can_fetch_masteries.yml
|
101
105
|
- spec/client_spec.rb
|
@@ -130,7 +134,10 @@ test_files:
|
|
130
134
|
- spec/cassettes/Vigor_Client/works_on_servers_other_than_NA.yml
|
131
135
|
- spec/cassettes/Vigor_Client/can_find_a_summoner_by_name.yml
|
132
136
|
- spec/cassettes/Vigor_Client/can_find_a_summoner_by_id.yml
|
137
|
+
- spec/cassettes/Vigor_Client/raises_an_exception_when_no_summoner_id_exists.yml
|
138
|
+
- spec/cassettes/Vigor_Client/raises_an_exception_when_no_summoner_name_exists.yml
|
133
139
|
- spec/cassettes/Vigor_Client/can_find_summoners_whose_names_have_whitespace.yml
|
140
|
+
- spec/cassettes/Vigor_Client/raises_an_exception_when_using_a_bad_key.yml
|
134
141
|
- spec/cassettes/Vigor_Summoner/can_fetch_runes.yml
|
135
142
|
- spec/cassettes/Vigor_Summoner/can_fetch_masteries.yml
|
136
143
|
- spec/client_spec.rb
|