starcraft2 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/starcraft2/client.rb +7 -7
- data/lib/starcraft2/loader.rb +5 -3
- data/lib/starcraft2/web_resource.rb +33 -0
- data/spec/starcraft2/achievement_spec.rb +1 -1
- data/spec/starcraft2/ladder_spec.rb +1 -1
- data/spec/starcraft2/profile_spec.rb +1 -1
- data/spec/starcraft2/reward_spec.rb +1 -1
- data/spec/starcraft2/utils_spec.rb +1 -1
- data/starcraft2.gemspec +2 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb15e20a90aea49a917b6a8a61c916d2d0e4058e
|
4
|
+
data.tar.gz: e4e8f2dedc8737c76735f0441a7f3b42f7fbdb14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88c2ab90efde9b8b816577212ab1a5d0bcf9f9055f616d23741073c17fa495827bc8d1920809ba861b42028c5ae5c5dd090344f36236dbd37661b63d9c732766
|
7
|
+
data.tar.gz: 7185e84ae6b5a64f8eef4b86ae3165c25cc4406fbacd693f2233b675eef6a9aa8e9aa22ecf613c2f071fe815e110a18bd0450c580d46b2cded2a4fd2aef36726
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ client = Starcraft2::Client.new(:host => 'us.battle.net', :locale => 'en_US')
|
|
25
25
|
`Starcraft2::Profile` contains all profile information. Realm, character name and id can all be found in a player's profile url.
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
profile = client.profile(realm
|
28
|
+
profile = client.profile(:realm => 1, :character_name => "Minigun", :id => 288081)
|
29
29
|
```
|
30
30
|
|
31
31
|
**Call a player's league**
|
@@ -60,6 +60,16 @@ client.achievements
|
|
60
60
|
client.rewards
|
61
61
|
```
|
62
62
|
|
63
|
+
### Authorization
|
64
|
+
|
65
|
+
If you require authorization then the changes are very simple. Just set the following two ENV variables.
|
66
|
+
|
67
|
+
```
|
68
|
+
STARCRAFT2_API_PRIVATE_KEY = <YOUR_PRIVATE_KEY>
|
69
|
+
STARCRAFT2_API_PUBLIC_KEY = <YOUR_PUBLIC_KEY>
|
70
|
+
```
|
71
|
+
|
72
|
+
Once those are set, the gem will take care of the rest for you.
|
63
73
|
|
64
74
|
## Build Status
|
65
75
|
[![Build Status](https://travis-ci.org/zquestz/starcraft2.png)](https://travis-ci.org/zquestz/starcraft2)
|
data/lib/starcraft2/client.rb
CHANGED
@@ -59,7 +59,7 @@ module Starcraft2
|
|
59
59
|
def profile_data(options)
|
60
60
|
memoize(:profile_data, options) do
|
61
61
|
Utils.get_json do
|
62
|
-
|
62
|
+
WebResource.get(profile_url(options))
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -75,7 +75,7 @@ module Starcraft2
|
|
75
75
|
def match_data(options)
|
76
76
|
memoize(:match_data, options) do
|
77
77
|
Utils.get_json do
|
78
|
-
|
78
|
+
WebResource.get(match_url(options))
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -83,7 +83,7 @@ module Starcraft2
|
|
83
83
|
def ladders_data(options)
|
84
84
|
memoize(:ladders_data, options) do
|
85
85
|
Utils.get_json do
|
86
|
-
|
86
|
+
WebResource.get(ladders_url(options))
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -99,7 +99,7 @@ module Starcraft2
|
|
99
99
|
def achievements_data
|
100
100
|
memoize(:achievements_data) do
|
101
101
|
Utils.get_json do
|
102
|
-
|
102
|
+
WebResource.get(achievements_url)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -111,7 +111,7 @@ module Starcraft2
|
|
111
111
|
def rewards_data
|
112
112
|
memoize(:rewards_data) do
|
113
113
|
Utils.get_json do
|
114
|
-
|
114
|
+
WebResource.get(rewards_url)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
@@ -123,7 +123,7 @@ module Starcraft2
|
|
123
123
|
def ladder_data(id)
|
124
124
|
memoize(:ladder_data, id) do
|
125
125
|
Utils.get_json do
|
126
|
-
|
126
|
+
WebResource.get(ladder_url(id))
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -146,4 +146,4 @@ module Starcraft2
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
149
|
-
end
|
149
|
+
end
|
data/lib/starcraft2/loader.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
4
|
+
base = File.expand_path File.dirname(__FILE__)
|
5
|
+
|
6
|
+
Dir[File.join(base, 'errors', '*.rb')].each do |file|
|
5
7
|
require file
|
6
8
|
end
|
7
9
|
|
8
|
-
Dir[File.join(
|
10
|
+
Dir[File.join(base, 'profile', '*.rb')].each do |file|
|
9
11
|
require file
|
10
12
|
end
|
11
13
|
|
12
|
-
Dir[File.join(
|
14
|
+
Dir[File.join(base, '*.rb')].each do |file|
|
13
15
|
require file
|
14
16
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'hmac-sha1'
|
3
|
+
require 'addressable/uri'
|
4
|
+
|
5
|
+
class WebResource
|
6
|
+
def self.get(url)
|
7
|
+
private_key = ENV['STARCRAFT2_API_PRIVATE_KEY']
|
8
|
+
public_key = ENV['STARCRAFT2_API_PUBLIC_KEY']
|
9
|
+
date = Time.now.gmtime.rfc2822.gsub("-0000", "GMT")
|
10
|
+
response = if public_key && private_key
|
11
|
+
HTTParty.get(url,
|
12
|
+
:headers => { "Date" => date,
|
13
|
+
"Authorization" => "BNET #{public_key}:#{signature(url, private_key, date)}"})
|
14
|
+
else
|
15
|
+
HTTParty.get(url)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.signature(url, private_key, date)
|
20
|
+
url_path = ::Addressable::URI.parse(url).path
|
21
|
+
|
22
|
+
signature = <<-EOF
|
23
|
+
GET
|
24
|
+
#{date}
|
25
|
+
#{url_path}
|
26
|
+
EOF
|
27
|
+
|
28
|
+
hmac = HMAC::SHA1.new(private_key.encode('UTF-8'))
|
29
|
+
hmac.update(signature)
|
30
|
+
|
31
|
+
Base64.encode64(hmac.digest)
|
32
|
+
end
|
33
|
+
end
|
@@ -59,7 +59,7 @@ describe Starcraft2::Achievement do
|
|
59
59
|
|
60
60
|
it 'should import the achievements from blizzard' do
|
61
61
|
VCR.use_cassette('achievements') do
|
62
|
-
@achievement = Starcraft2::Achievement.build(JSON.parse(
|
62
|
+
@achievement = Starcraft2::Achievement.build(JSON.parse(WebResource.get('https://us.battle.net/api/sc2/data/achievements').body)).first
|
63
63
|
end
|
64
64
|
|
65
65
|
@achievement.title.should == 'FFA Destroyer'
|
@@ -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 = JSON.parse(
|
11
|
+
@raw_ladder_data = JSON.parse(WebResource.get("https://us.battle.net/api/sc2/ladder/#{id}").body)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -9,7 +9,7 @@ describe Starcraft2::Profile do
|
|
9
9
|
|
10
10
|
before do
|
11
11
|
VCR.use_cassette('profile_999000') do
|
12
|
-
@profile = JSON.parse(
|
12
|
+
@profile = JSON.parse(WebResource.get('https://us.battle.net/api/sc2/profile/999000/1/DayNine/').body)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -32,7 +32,7 @@ describe Starcraft2::Reward do
|
|
32
32
|
|
33
33
|
before do
|
34
34
|
VCR.use_cassette('rewards') do
|
35
|
-
@rewards = JSON.parse(
|
35
|
+
@rewards = JSON.parse(WebResource.get('https://us.battle.net/api/sc2/data/rewards').body)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
data/starcraft2.gemspec
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.add_dependency 'httparty'
|
4
4
|
gem.add_dependency 'json'
|
5
|
+
gem.add_dependency 'ruby-hmac'
|
5
6
|
|
6
7
|
gem.authors = ["Josh Ellithorpe", "James Fickel", "Jan Hein Hoogstad"]
|
7
8
|
gem.email = ["quest@mac.com"]
|
@@ -14,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
14
15
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
15
16
|
gem.name = "starcraft2"
|
16
17
|
gem.require_paths = ["lib"]
|
17
|
-
gem.version = "0.
|
18
|
+
gem.version = "0.3.0"
|
18
19
|
|
19
20
|
gem.add_development_dependency 'rspec', '~> 2.6.0'
|
20
21
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Ellithorpe
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: ruby-hmac
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rspec
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +175,7 @@ files:
|
|
161
175
|
- lib/starcraft2/profile/swarm_race.rb
|
162
176
|
- lib/starcraft2/reward.rb
|
163
177
|
- lib/starcraft2/utils.rb
|
178
|
+
- lib/starcraft2/web_resource.rb
|
164
179
|
- spec/spec_helper.rb
|
165
180
|
- spec/starcraft2/achievement_spec.rb
|
166
181
|
- spec/starcraft2/character_spec.rb
|
@@ -206,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
221
|
version: '0'
|
207
222
|
requirements: []
|
208
223
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.0.
|
224
|
+
rubygems_version: 2.0.6
|
210
225
|
signing_key:
|
211
226
|
specification_version: 4
|
212
227
|
summary: A small SC2 api wrapper
|