starcraft2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ module SC2
2
+ class Achievement
3
+ attr_accessor :title, :description, :achievement_id, :category_id, :points, :icon
4
+
5
+ def initialize(options = {})
6
+ options.each do |k,v|
7
+ self.send(:"#{k}=", v)
8
+ end
9
+ end
10
+
11
+ def self.build_achievements(raw_data)
12
+ data = JSON.parse(raw_data)
13
+ data['achievements'].map do |achievement|
14
+ achievement['achievement_id'] = achievement.delete('achievementId')
15
+ achievement['category_id'] = achievement.delete('categoryId')
16
+ new(achievement)
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/sc2/client.rb ADDED
@@ -0,0 +1,28 @@
1
+ module SC2
2
+ class Client
3
+ ACHIEVEMENTS_PATH = "/api/sc2/data/achievements"
4
+
5
+ attr_accessor :locale, :host
6
+
7
+ def initialize(options)
8
+ options.each do |k,v|
9
+ self.send(:"#{k}=", v)
10
+ end
11
+ end
12
+
13
+ def achievements
14
+ Achievement.build_achievements(achievements_data)
15
+ end
16
+
17
+ private
18
+
19
+ def achievements_data
20
+ HTTParty.get(achievements_url).body
21
+ end
22
+
23
+ def achievements_url
24
+ current_locale = locale.nil? ? '' : "?locale=#{locale}"
25
+ "http://" + host + ACHIEVEMENTS_PATH + current_locale
26
+ end
27
+ end
28
+ end
data/lib/sc2/loader.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require File.join('sc2', 'client')
4
+ require File.join('sc2', 'achievement')
5
+ require File.join('sc2', 'reward')
data/lib/sc2/reward.rb ADDED
@@ -0,0 +1,20 @@
1
+ module SC2
2
+ class Reward
3
+ attr_accessor :title, :id, :icon, :achievement_id
4
+
5
+ def initialize(options = {})
6
+ options.each do |k,v|
7
+ self.send(:"#{k}=", v)
8
+ end
9
+ end
10
+
11
+ def self.build_rewards(raw_data)
12
+ data = JSON.parse(raw_data)
13
+ data['portraits'].map do |reward|
14
+ reward['achievement_id'] = reward.delete('achievementId')
15
+ new(reward)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
data/lib/starcraft2.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join('sc2', 'loader.rb')
data/sc2.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.add_dependency 'httparty'
4
+
5
+ gem.authors = ["Josh Ellithorpe", "James Fickel", "Jan Hein Hoogstad"]
6
+ gem.email = ["quest@mac.com"]
7
+ gem.description = %q{A small SC2 api wrapper}
8
+ gem.summary = %q{A small SC2 api wrapper}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
14
+ gem.name = "starcraft2"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = "0.0.1"
17
+
18
+ gem.add_development_dependency 'rspec', '~> 2.6.0'
19
+ gem.add_development_dependency 'rake'
20
+ gem.add_development_dependency 'vcr'
21
+ gem.add_development_dependency 'webmock', '1.11'
22
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe SC2::Achievement do
4
+ describe '#build_achievements' do
5
+ let(:achievements) { SC2::Achievement.build_achievements(@raw_achievement_data)}
6
+
7
+ before do
8
+ VCR.use_cassette('achievements') do
9
+ @raw_achievement_data = HTTParty.get('http://us.battle.net/api/sc2/data/achievements').body
10
+ end
11
+ end
12
+
13
+ it 'should build an array of achievements' do
14
+ achievements.class.should == Array
15
+ achievements.each do |a|
16
+ a.class.should == SC2::Achievement
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '.initialize' do
22
+ let(:achievement) {SC2::Achievement.new(@options)}
23
+
24
+ before do
25
+ @options = {}
26
+ end
27
+
28
+ it 'should store the title' do
29
+ @options = {:title => 'Test Title'}
30
+ achievement.title.should == 'Test Title'
31
+ end
32
+
33
+ it 'should store the description' do
34
+ @options = {:description => 'Description'}
35
+ achievement.description.should == 'Description'
36
+ end
37
+
38
+ it 'should store the achievement id' do
39
+ @options = {:achievement_id => 5}
40
+ achievement.achievement_id.should == 5
41
+ end
42
+
43
+ it 'should store the category id' do
44
+ @options = {:category_id => 10}
45
+ achievement.category_id.should == 10
46
+ end
47
+
48
+ it 'should store the points' do
49
+ @options = {:points => 5}
50
+ achievement.points.should == 5
51
+ end
52
+
53
+ it 'should store the icon data' do
54
+ @options = {:icon => {:x => 1, :y => 2, :w => 3, :h => 4, :offset => 0, :url => 'http://example.com'}}
55
+ achievement.icon.should == {:x => 1, :y => 2, :w => 3, :h => 4, :offset => 0, :url => 'http://example.com'}
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe SC2::Client do
4
+ let(:client) { SC2::Client.new(@options)}
5
+
6
+ before do
7
+ @options = {:host => 'us.battle.net'}
8
+ end
9
+
10
+ context 'url constants' do
11
+ it 'should store the achievements url' do
12
+ SC2::Client::ACHIEVEMENTS_PATH.should == '/api/sc2/data/achievements'
13
+ end
14
+ end
15
+
16
+ it 'should store the locale' do
17
+ @options = { :locale => 'en_US' }
18
+ client.locale.should == 'en_US'
19
+ end
20
+
21
+ it 'should store the host' do
22
+ @options = { :host => 'someserver.com'}
23
+ client.host.should == 'someserver.com'
24
+ end
25
+
26
+ it 'should return an array of achievements' do
27
+ VCR.use_cassette('achievements') do
28
+ client.achievements.class.should == Array
29
+ end
30
+ end
31
+
32
+ it 'should return items of type SC2::Achievement' do
33
+ VCR.use_cassette('achievements') do
34
+ client.achievements.first.class.should == SC2::Achievement
35
+ end
36
+ end
37
+
38
+ it "should return achievements in the correct locale" do
39
+ @options.merge!({:locale => "pt_BR"})
40
+
41
+ VCR.use_cassette('achievements') do
42
+ client.achievements.first.title.should == "TCT Destruidor"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe SC2::Reward do
4
+ describe '#build_rewards' do
5
+ let(:rewards) { SC2::Reward.build_rewards(@raw_reward_data)}
6
+
7
+ before do
8
+ VCR.use_cassette('rewards') do
9
+ @raw_reward_data = HTTParty.get('http://us.battle.net/api/sc2/data/rewards').body
10
+ end
11
+ end
12
+
13
+ it 'should build an array of rewards' do
14
+ rewards.class.should == Array
15
+ rewards.each do |r|
16
+ r.class.should == SC2::Reward
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '.initialize' do
22
+ let(:reward) {SC2::Reward.new(@options)}
23
+
24
+ before do
25
+ @options = {}
26
+ end
27
+
28
+ it 'should store the title' do
29
+ @options = {:title => 'Test Title'}
30
+ reward.title.should == 'Test Title'
31
+ end
32
+
33
+ it 'should store the id' do
34
+ @options = {:id => 3}
35
+ reward.id.should == 3
36
+ end
37
+
38
+ it 'should store the icon data' do
39
+ @options = {:icon => {:x => 1, :y => 2, :w => 3, :h => 4, :offset => 0, :url => 'http://example.com'}}
40
+ reward.icon.should == {:x => 1, :y => 2, :w => 3, :h => 4, :offset => 0, :url => 'http://example.com'}
41
+ end
42
+
43
+ it "should store the achievement id" do
44
+ @options = {:achievement_id => 5}
45
+ reward.achievement_id.should == 5
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,10 @@
1
+ require File.join('bundler', 'setup')
2
+ require 'rspec'
3
+ require 'vcr'
4
+ require 'starcraft2'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
8
+ c.hook_into :webmock
9
+ c.default_cassette_options = { :record => :new_episodes, :erb => true }
10
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: starcraft2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Ellithorpe
9
+ - James Fickel
10
+ - Jan Hein Hoogstad
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-08-07 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 2.6.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: vcr
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: webmock
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - '='
86
+ - !ruby/object:Gem::Version
87
+ version: '1.11'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - '='
94
+ - !ruby/object:Gem::Version
95
+ version: '1.11'
96
+ description: A small SC2 api wrapper
97
+ email:
98
+ - quest@mac.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .ruby-version
105
+ - .rvmrc
106
+ - .travis.yml
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - fixtures/vcr_cassettes/achievements.yml
111
+ - fixtures/vcr_cassettes/rewards.yml
112
+ - lib/sc2/achievement.rb
113
+ - lib/sc2/client.rb
114
+ - lib/sc2/loader.rb
115
+ - lib/sc2/reward.rb
116
+ - lib/starcraft2.rb
117
+ - sc2.gemspec
118
+ - spec/sc2/achievement_spec.rb
119
+ - spec/sc2/client_spec.rb
120
+ - spec/sc2/reward_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: ''
123
+ licenses: []
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: -2271089934831786972
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: -2271089934831786972
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.25
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: A small SC2 api wrapper
152
+ test_files: []