sc2_achievements 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'sc2_achievements/category_page'
3
+
4
+ module SC2Achievements
5
+ describe CategoryPage do
6
+ it 'returns an array with all the achievements earned in that page' do
7
+ VCR.use_cassette('mar-sara-missions') do
8
+ achievements = Page.get_achievements_for '/3396700/1/Tato', :category => 3211280
9
+ achievements.should have(5).items
10
+ achievements["Liberation Day"].should == {
11
+ :title => "Liberation Day",
12
+ :description => "Complete all mission objectives in the\302\240\342\200\234Liberation Day\342\200\235 mission.",
13
+ :category => "Mar Sara Missions",
14
+ :points => 15,
15
+ :date => "2012-09-17"
16
+ }
17
+ achievements["Hold the Line"].should == {
18
+ :title => "Hold the Line",
19
+ :description => "Complete the\302\240\342\200\234Zero Hour\342\200\235 mission on Normal difficulty without losing or salvaging a structure.",
20
+ :category => "Mar Sara Missions",
21
+ :points => 10,
22
+ :date => "2012-09-17"
23
+ }
24
+ end
25
+ end
26
+
27
+ it 'takes into account the achievements that are partially completed' do
28
+ VCR.use_cassette('solo-league') do
29
+ achievements = Page.get_achievements_for '/3396700/1/Tato', :category => 4325378
30
+ achievements.should have(1).items
31
+ achievements["Solo Hot Streak 3"].should == {
32
+ :title => "Solo Hot Streak 3",
33
+ :description => "Win 3 1v1 league Quick Match games in a row.",
34
+ :category => "Solo League",
35
+ :points => 10,
36
+ :date => "2012-05-12"
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'sc2_achievements/homepage'
3
+
4
+ module SC2Achievements
5
+ describe Homepage do
6
+ it 'returns an array with all the achievements in the homepage' do
7
+ VCR.use_cassette('achievements-homepage') do
8
+ achievements = Page.get_achievements_for '/3396700/1/Tato'
9
+ achievements.should have(6).items
10
+ achievements["That\342\200\231s Teamwork"].should == {
11
+ :title => "That\342\200\231s Teamwork",
12
+ :description => "Win 5 Team league Quick Match games.",
13
+ :date => "2012-09-20",
14
+ :recentness => 1
15
+ }
16
+ achievements["Semi-Glorious"].should == {
17
+ :title => "Semi-Glorious",
18
+ :description => "Kill 250 additional Zerg units in the\302\240\342\200\234In Utter Darkness\342\200\235 mission on Normal difficulty.",
19
+ :date => "2012-09-20",
20
+ :recentness => 6
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'sc2_achievements/page'
3
+
4
+ module SC2Achievements
5
+ describe Page do
6
+ it 'returns an array with the categories that can be accessed from the homepage' do
7
+ VCR.use_cassette('achievements-homepage') do
8
+ categories = Page.get_categories_for '/3396700/1/Tato'
9
+ categories.should have(7).items
10
+ categories[0].should == "3211280"
11
+ categories[6].should == "4325394"
12
+ end
13
+ end
14
+
15
+ it 'returns an array with the categories that can be accessed from a category page' do
16
+ VCR.use_cassette('mar-sara-missions') do
17
+ categories = Page.get_categories_for '/3396700/1/Tato', :category => 3211280
18
+ categories.should have(8).items
19
+ categories[0].should == "3211280"
20
+ categories[7].should == "3211287"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+ require 'sc2_achievements'
3
+
4
+ describe SC2Achievements do
5
+ it 'add the recently earned achievements to the top' do
6
+ SC2Achievements::Page.stub(:get_categories_for) { [] }
7
+ VCR.use_cassette('achievements-homepage') do
8
+ achievements = SC2Achievements.for('/3396700/1/Tato')
9
+ achievements.should have(6).items
10
+ achievements[0].should == {
11
+ :title => "That\342\200\231s Teamwork",
12
+ :description => "Win 5 Team league Quick Match games.",
13
+ :date => "2012-09-20"
14
+ }
15
+ achievements[5].should == {
16
+ :title => "Semi-Glorious",
17
+ :description => "Kill 250 additional Zerg units in the\302\240\342\200\234In Utter Darkness\342\200\235 mission on Normal difficulty.",
18
+ :date => "2012-09-20"
19
+ }
20
+ end
21
+ end
22
+
23
+ it 'gets the achievements from the first group of categories' do
24
+ SC2Achievements::Page.stub(:get_categories_for) { [3211280, 3211281] }
25
+ VCR.use_cassette('achievements-homepage-and-first-categories') do
26
+ achievements = SC2Achievements.for('/3396700/1/Tato')
27
+ achievements.should have(16).items
28
+ achievements[0][:title].should == "That\342\200\231s Teamwork"
29
+ achievements[5][:title].should == "Semi-Glorious"
30
+ end
31
+ end
32
+
33
+ it "doesn't duplicate achievements that are on the homepage" do
34
+ SC2Achievements::Page.stub(:get_categories_for) { [4325400] }
35
+ VCR.use_cassette('achievements-homepage-and-guide-three') do
36
+ achievements = SC2Achievements.for('/3396700/1/Tato')
37
+ achievements.should have(7).items
38
+ achievements[0][:title].should == "That\342\200\231s Teamwork"
39
+ achievements[5][:title].should == "Semi-Glorious"
40
+ achievements[6][:date].should == "2012-05-07"
41
+ end
42
+ end
43
+
44
+ it "goes and fetch the achievements for all the categories on the page" do
45
+ user_path = '/3396700/1/Tato'
46
+ SC2Achievements::Page.stub(:get_categories_for).with(user_path) { [3211280, 4325398] }
47
+ SC2Achievements::Page.stub(:get_categories_for).with(user_path, :category => 3211280) { [3211280, 3211281] }
48
+ SC2Achievements::Page.stub(:get_categories_for).with(user_path, :category => 3211281) { [3211280, 3211281] }
49
+ SC2Achievements::Page.stub(:get_categories_for).with(user_path, :category => 4325398) { [4325398, 4325400] }
50
+ SC2Achievements::Page.stub(:get_categories_for).with(user_path, :category => 4325398) { [4325400, 4325400] }
51
+ VCR.use_cassette('all-selected-achievements') do
52
+ achievements = SC2Achievements.for(user_path)
53
+ achievements.should have(17).items
54
+ achievements[0][:title].should == "That\342\200\231s Teamwork"
55
+ achievements[5][:title].should == "Semi-Glorious"
56
+ achievements[6][:date].should == "2012-09-17"
57
+ achievements[15][:date].should == "2012-09-17"
58
+ achievements[16][:date].should == "2012-05-07"
59
+ end
60
+ end
61
+
62
+ it "gets ALL the achievements and orders them correctly" do
63
+ VCR.use_cassette('all-achievements') do
64
+ achievements = SC2Achievements.for('/3396700/1/Tato')
65
+ achievements.should have(53).items
66
+ achievements[0][:title].should == "That\342\200\231s Teamwork"
67
+ achievements[5][:title].should == "Semi-Glorious"
68
+ achievements.inject(0) do |sum, achievement|
69
+ sum += achievement[:points]
70
+ end.should == 630
71
+ for i in 1..(achievements.length - 1)
72
+ (achievements[i - 1][:date] <=> achievements[i][:date]).should_not == -1
73
+ end
74
+ end
75
+ end
76
+
77
+ it "gets the remaining data for each recent achievement from its category page" do
78
+ SC2Achievements::Page.stub(:get_categories_for) { [4325400, 3211284] }
79
+ VCR.use_cassette('homepage-and-recent-achievements-category-pages') do
80
+ achievements = SC2Achievements.for('/3396700/1/Tato')
81
+ achievements[0][:category].should == "Guide Three"
82
+ achievements[1][:category].should == "Artifact Missions"
83
+ achievements[0][:points].should == 10
84
+ achievements[1][:points].should == 15
85
+ end
86
+ end
87
+
88
+ xit "returns an empty array if there is no achievements" do
89
+ end
90
+
91
+ xit "optimizes the number of HTTP requests it makes" do
92
+ end
93
+ end
@@ -0,0 +1,7 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |config|
4
+ config.cassette_library_dir = 'spec/cassettes'
5
+ config.hook_into :webmock
6
+ end
7
+
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sc2_achievements
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - "Eduardo Grajeda Bland\xC3\xB3n"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: nokogiri
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: rspec
45
+ prerelease: false
46
+ type: :development
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: vcr
59
+ prerelease: false
60
+ type: :development
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ name: webmock
73
+ prerelease: false
74
+ type: :development
75
+ requirement: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ name: bundler
87
+ prerelease: false
88
+ type: :development
89
+ requirement: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ version_requirements: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ name: jeweler
101
+ prerelease: false
102
+ type: :development
103
+ requirement: *id006
104
+ description: This library downloads all the achievements from a Starcraft II player's public profile and package them as an array.
105
+ email: tatofoo@gmail.com
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ extra_rdoc_files:
111
+ - LICENSE.txt
112
+ - README.md
113
+ files:
114
+ - Gemfile
115
+ - Gemfile.lock
116
+ - LICENSE.txt
117
+ - README.md
118
+ - Rakefile
119
+ - VERSION
120
+ - lib/sc2_achievements.rb
121
+ - lib/sc2_achievements/category_page.rb
122
+ - lib/sc2_achievements/homepage.rb
123
+ - lib/sc2_achievements/page.rb
124
+ - spec/cassettes/achievements-homepage-and-first-categories.yml
125
+ - spec/cassettes/achievements-homepage-and-guide-three.yml
126
+ - spec/cassettes/achievements-homepage.yml
127
+ - spec/cassettes/all-achievements.yml
128
+ - spec/cassettes/all-selected-achievements.yml
129
+ - spec/cassettes/homepage-and-recent-achievements-category-pages.yml
130
+ - spec/cassettes/mar-sara-missions.yml
131
+ - spec/cassettes/solo-league.yml
132
+ - spec/sc2_achievements/category_page_spec.rb
133
+ - spec/sc2_achievements/homepage_spec.rb
134
+ - spec/sc2_achievements/page_spec.rb
135
+ - spec/sc2_achievements_spec.rb
136
+ - spec/spec_helper.rb
137
+ homepage: http://github.com/egrajeda/sc2_achievements
138
+ licenses:
139
+ - MIT
140
+ post_install_message:
141
+ rdoc_options: []
142
+
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
162
+ version: "0"
163
+ requirements: []
164
+
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.15
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: Download all the achievements of a SC2 player.
170
+ test_files: []
171
+