starcraft2 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/starcraft2/achievement.rb +1 -2
- data/lib/starcraft2/client.rb +38 -6
- data/lib/starcraft2/errors/api_error.rb +4 -0
- data/lib/starcraft2/errors/not_found_error.rb +4 -0
- data/lib/starcraft2/ladder.rb +1 -2
- data/lib/starcraft2/loader.rb +2 -0
- data/lib/starcraft2/profile/match.rb +1 -2
- data/lib/starcraft2/profile.rb +2 -3
- data/lib/starcraft2/reward.rb +1 -2
- data/spec/starcraft2/achievement_spec.rb +3 -3
- data/spec/starcraft2/client_spec.rb +0 -4
- data/spec/starcraft2/ladder_spec.rb +1 -1
- data/spec/starcraft2/profile_spec.rb +2 -2
- data/spec/starcraft2/reward_spec.rb +2 -2
- data/starcraft2.gemspec +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae4ebd851c581a60a04334ee02445b8f53d0f8a6
|
4
|
+
data.tar.gz: 86579b56eedd10f2ba72309c6b52d13dc9aa0a9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eed2a2067825ae0df56f0029512cff259839b9e941520d6ceeede9af6c412d036c0203f3a656bf296a539d39e61a8e521f353ec078a2e939163d72ef4548d30c
|
7
|
+
data.tar.gz: 9ddac4a3333d6bd492555122c064b33b3afe1c50d7f1baa3ec9bd56f10fc16541c113bf064317cf1da7098cca087ff0142b97fdba4994cefc669bee5b48cad05
|
data/lib/starcraft2/client.rb
CHANGED
@@ -42,14 +42,16 @@ module Starcraft2
|
|
42
42
|
ladder('grandmaster')
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
45
|
+
def last_grandmaster_ladder
|
46
46
|
ladder('grandmaster/last')
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
51
|
def profile_json(options)
|
52
|
-
|
52
|
+
get_body do
|
53
|
+
HTTParty.get(profile_url(options))
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
def profile_url(options)
|
@@ -61,7 +63,9 @@ module Starcraft2
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def match_json(options)
|
64
|
-
|
66
|
+
get_body do
|
67
|
+
HTTParty.get(match_url(options))
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
71
|
def match_url(options)
|
@@ -69,7 +73,9 @@ module Starcraft2
|
|
69
73
|
end
|
70
74
|
|
71
75
|
def achievements_json
|
72
|
-
|
76
|
+
get_body do
|
77
|
+
HTTParty.get(achievements_url)
|
78
|
+
end
|
73
79
|
end
|
74
80
|
|
75
81
|
def achievements_url
|
@@ -77,7 +83,9 @@ module Starcraft2
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def rewards_json
|
80
|
-
|
86
|
+
get_body do
|
87
|
+
HTTParty.get(rewards_url)
|
88
|
+
end
|
81
89
|
end
|
82
90
|
|
83
91
|
def rewards_url
|
@@ -85,7 +93,9 @@ module Starcraft2
|
|
85
93
|
end
|
86
94
|
|
87
95
|
def ladder_json(id)
|
88
|
-
|
96
|
+
get_body do
|
97
|
+
HTTParty.get(ladder_url(id))
|
98
|
+
end
|
89
99
|
end
|
90
100
|
|
91
101
|
def ladder_url(id)
|
@@ -95,5 +105,27 @@ module Starcraft2
|
|
95
105
|
def locale_param
|
96
106
|
locale.nil? ? '' : "?locale=#{locale}"
|
97
107
|
end
|
108
|
+
|
109
|
+
def get_body
|
110
|
+
response = yield
|
111
|
+
case response.code
|
112
|
+
when 200
|
113
|
+
body = JSON.parse(response.body)
|
114
|
+
case body['code']
|
115
|
+
when 200
|
116
|
+
body
|
117
|
+
when 404
|
118
|
+
raise Starcraft2::NotFoundError, body['message'] || body['reason']
|
119
|
+
when 500
|
120
|
+
raise Starcraft2::ApiError, body['message'] || body['reason']
|
121
|
+
else
|
122
|
+
body
|
123
|
+
end
|
124
|
+
when 404
|
125
|
+
raise Starcraft2::NotFoundError, 'Record not found.'
|
126
|
+
when 500
|
127
|
+
raise Starcraft2::ApiError, 'An API error occurred.'
|
128
|
+
end
|
129
|
+
end
|
98
130
|
end
|
99
131
|
end
|
data/lib/starcraft2/ladder.rb
CHANGED
data/lib/starcraft2/loader.rb
CHANGED
@@ -3,6 +3,8 @@ require 'httparty'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
require File.join('starcraft2', 'errors', 'missing_arguments_error')
|
6
|
+
require File.join('starcraft2', 'errors', 'api_error')
|
7
|
+
require File.join('starcraft2', 'errors', 'not_found_error')
|
6
8
|
require File.join('starcraft2', 'utils')
|
7
9
|
require File.join('starcraft2', 'icon')
|
8
10
|
require File.join('starcraft2', 'client')
|
data/lib/starcraft2/profile.rb
CHANGED
data/lib/starcraft2/reward.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Starcraft2::Achievement do
|
4
4
|
describe '#build' do
|
5
|
-
let(:achievements) { Starcraft2::Achievement.build(@
|
5
|
+
let(:achievements) { Starcraft2::Achievement.build(@achievements) }
|
6
6
|
|
7
7
|
before do
|
8
8
|
VCR.use_cassette('achievements') do
|
9
|
-
@
|
9
|
+
@achievements = JSON.parse(HTTParty.get('https://us.battle.net/api/sc2/data/achievements').body)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -27,7 +27,7 @@ describe Starcraft2::Achievement do
|
|
27
27
|
|
28
28
|
it 'should import the first achievement' do
|
29
29
|
VCR.use_cassette('achievements') do
|
30
|
-
@achievement = Starcraft2::Achievement.build(HTTParty.get('https://us.battle.net/api/sc2/data/achievements').body).first
|
30
|
+
@achievement = Starcraft2::Achievement.build(JSON.parse(HTTParty.get('https://us.battle.net/api/sc2/data/achievements').body)).first
|
31
31
|
end
|
32
32
|
|
33
33
|
@achievement.title.should == 'FFA Destroyer'
|
@@ -52,10 +52,6 @@ describe Starcraft2::Client do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
VCR.use_cassette("profile_#{999000}") do
|
56
|
-
@profile_json = HTTParty.get('https://us.battle.net/api/sc2/profile/999000/1/DayNine/').body
|
57
|
-
end
|
58
|
-
|
59
55
|
describe '.achievements' do
|
60
56
|
it 'should return an array of achievements' do
|
61
57
|
VCR.use_cassette('achievements') do
|
@@ -8,7 +8,7 @@ describe Starcraft2::Ladder do
|
|
8
8
|
|
9
9
|
before do
|
10
10
|
VCR.use_cassette("ladder_#{id}") do
|
11
|
-
@raw_ladder_data = HTTParty.get("https://us.battle.net/api/sc2/ladder/#{id}").body
|
11
|
+
@raw_ladder_data = JSON.parse(HTTParty.get("https://us.battle.net/api/sc2/ladder/#{id}").body)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -5,11 +5,11 @@ describe Starcraft2::Profile do
|
|
5
5
|
let(:profile) { Starcraft2::Profile.new(@options) }
|
6
6
|
|
7
7
|
describe '#build' do
|
8
|
-
let(:profile) { Starcraft2::Profile.build(client, @
|
8
|
+
let(:profile) { Starcraft2::Profile.build(client, @profile) }
|
9
9
|
|
10
10
|
before do
|
11
11
|
VCR.use_cassette("profile_999000") do
|
12
|
-
@
|
12
|
+
@profile = JSON.parse(HTTParty.get('https://us.battle.net/api/sc2/profile/999000/1/DayNine/').body)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -6,7 +6,7 @@ describe Starcraft2::Reward do
|
|
6
6
|
|
7
7
|
before do
|
8
8
|
VCR.use_cassette('rewards') do
|
9
|
-
@raw_reward_data = HTTParty.get('https://us.battle.net/api/sc2/data/rewards').body
|
9
|
+
@raw_reward_data = JSON.parse(HTTParty.get('https://us.battle.net/api/sc2/data/rewards').body)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -27,7 +27,7 @@ describe Starcraft2::Reward do
|
|
27
27
|
|
28
28
|
it 'should import the first reward' do
|
29
29
|
VCR.use_cassette('rewards') do
|
30
|
-
@reward = Starcraft2::Reward.build(HTTParty.get('https://us.battle.net/api/sc2/data/rewards').body).first
|
30
|
+
@reward = Starcraft2::Reward.build(JSON.parse(HTTParty.get('https://us.battle.net/api/sc2/data/rewards').body)).first
|
31
31
|
end
|
32
32
|
|
33
33
|
@reward.title.should == 'Kachinsky'
|
data/starcraft2.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
15
15
|
gem.name = "starcraft2"
|
16
16
|
gem.require_paths = ["lib"]
|
17
|
-
gem.version = "0.1.
|
17
|
+
gem.version = "0.1.1"
|
18
18
|
|
19
19
|
gem.add_development_dependency 'rspec', '~> 2.6.0'
|
20
20
|
gem.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starcraft2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Ellithorpe
|
@@ -136,7 +136,9 @@ files:
|
|
136
136
|
- lib/starcraft2/achievement.rb
|
137
137
|
- lib/starcraft2/character.rb
|
138
138
|
- lib/starcraft2/client.rb
|
139
|
+
- lib/starcraft2/errors/api_error.rb
|
139
140
|
- lib/starcraft2/errors/missing_arguments_error.rb
|
141
|
+
- lib/starcraft2/errors/not_found_error.rb
|
140
142
|
- lib/starcraft2/icon.rb
|
141
143
|
- lib/starcraft2/ladder.rb
|
142
144
|
- lib/starcraft2/loader.rb
|