httpattack-lib 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -0
- data/Rakefile +1 -2
- data/lib/httpattack.rb +2 -2
- data/lib/httpattack/items.rb +25 -0
- data/lib/httpattack/{weapons → items}/base.rb +7 -7
- data/lib/httpattack/{weapons → items}/github.rb +8 -8
- data/lib/httpattack/{weapons → items}/twitter.rb +8 -8
- data/spec/httpattack/{weapons → items}/base_spec.rb +17 -17
- data/spec/httpattack/items/github_spec.rb +45 -0
- data/spec/httpattack/{weapons → items}/responses/base.json +0 -0
- data/spec/httpattack/{weapons → items}/responses/github-oshuma.json +0 -0
- data/spec/httpattack/{weapons → items}/responses/twitter-oshuma_dev.json +0 -0
- data/spec/httpattack/items/twitter_spec.rb +45 -0
- data/spec/httpattack/items_spec.rb +21 -0
- metadata +16 -15
- data/lib/httpattack/weapons.rb +0 -10
- data/spec/httpattack/weapons/github_spec.rb +0 -45
- data/spec/httpattack/weapons/twitter_spec.rb +0 -45
data/README
CHANGED
@@ -1 +1,18 @@
|
|
1
1
|
The game library for HTTP Attack.
|
2
|
+
|
3
|
+
Item Protocol
|
4
|
+
-------------
|
5
|
+
Initializer must take two parameters, a username and an optional hash of settings.
|
6
|
+
|
7
|
+
SomeItem.new('luser', :set_this => 'to_this')
|
8
|
+
|
9
|
+
The Item must override the following methods:
|
10
|
+
|
11
|
+
stat
|
12
|
+
------
|
13
|
+
This method should return an Integer (or maybe a Float), which will be used to
|
14
|
+
determine the Item strength.
|
15
|
+
|
16
|
+
def stat
|
17
|
+
stats['user']['followers_count'].to_i
|
18
|
+
end
|
data/Rakefile
CHANGED
@@ -45,7 +45,6 @@ namespace :gem do
|
|
45
45
|
Rake::Task['gem:clean'].invoke
|
46
46
|
Rake::Task['gem:build'].invoke
|
47
47
|
gem = FileList["#{APP_DIR}/#{GEMNAME}-*.gem"].first
|
48
|
-
|
49
|
-
sh "#{sudo} gem uninstall #{GEMNAME} ; #{sudo} gem install #{gem}"
|
48
|
+
sh "gem uninstall #{GEMNAME} ; gem install #{gem}"
|
50
49
|
end
|
51
50
|
end
|
data/lib/httpattack.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'httpattack/items/base'
|
2
|
+
require 'httpattack/items/github'
|
3
|
+
require 'httpattack/items/twitter'
|
4
|
+
|
5
|
+
module HTTPAttack
|
6
|
+
module Items
|
7
|
+
|
8
|
+
# A list of registered Item types (the actual classes).
|
9
|
+
TYPES = [ Github, Twitter ]
|
10
|
+
|
11
|
+
class InvalidStat < Exception; end
|
12
|
+
class MustOverrideMethod < Exception; end
|
13
|
+
|
14
|
+
# Items enumerator. Just a wrapper to the TYPES array #each method.
|
15
|
+
def self.each(&block)
|
16
|
+
TYPES.send(:each, &block) if TYPES.respond_to?(:each)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Items enumerator. Just a wrapper to the TYPES array #map method.
|
20
|
+
def self.map(&block)
|
21
|
+
TYPES.send(:map, &block) if TYPES.respond_to?(:map)
|
22
|
+
end
|
23
|
+
|
24
|
+
end # Items
|
25
|
+
end # HTTPAttack
|
@@ -2,20 +2,20 @@ require 'json'
|
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
4
|
module HTTPAttack
|
5
|
-
module
|
5
|
+
module Items
|
6
6
|
|
7
7
|
class Base
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :stats
|
9
9
|
|
10
|
-
# This is the strength of the
|
10
|
+
# This is the strength of the Item and must be
|
11
11
|
# overridden in a subclass. It should return
|
12
|
-
# an
|
13
|
-
def
|
12
|
+
# an Integer (or Float).
|
13
|
+
def stat
|
14
14
|
raise MustOverrideMethod
|
15
15
|
end
|
16
16
|
|
17
17
|
# This is the URL where the JSON will come from.
|
18
|
-
# Must be overridden in a subclassed
|
18
|
+
# Must be overridden in a subclassed Item.
|
19
19
|
def stats_url
|
20
20
|
raise MustOverrideMethod
|
21
21
|
end
|
@@ -40,5 +40,5 @@ module HTTPAttack
|
|
40
40
|
|
41
41
|
end # Base
|
42
42
|
|
43
|
-
end #
|
43
|
+
end # Items
|
44
44
|
end # HTTPAttack
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module HTTPAttack
|
2
|
-
module
|
2
|
+
module Items
|
3
3
|
|
4
|
-
class Github < HTTPAttack::
|
4
|
+
class Github < HTTPAttack::Items::Base
|
5
5
|
STATS = ['followers_count', 'following_count']
|
6
6
|
|
7
7
|
def initialize(username, options = {})
|
8
|
-
options[:
|
9
|
-
raise
|
8
|
+
options[:remote_stat] ||= 'followers_count'
|
9
|
+
raise Items::InvalidStat unless STATS.include?(options[:remote_stat])
|
10
10
|
@username = username
|
11
|
-
@
|
11
|
+
@remote_stat = options[:remote_stat]
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def stat
|
15
15
|
self.reload_stats! unless stats
|
16
|
-
stats['user'][@
|
16
|
+
stats['user'][@remote_stat].to_i
|
17
17
|
end
|
18
18
|
|
19
19
|
def stats_url
|
@@ -22,5 +22,5 @@ module HTTPAttack
|
|
22
22
|
|
23
23
|
end # Github
|
24
24
|
|
25
|
-
end #
|
25
|
+
end # Items
|
26
26
|
end # HTTPAttack
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module HTTPAttack
|
2
|
-
module
|
2
|
+
module Items
|
3
3
|
|
4
|
-
class Twitter < HTTPAttack::
|
4
|
+
class Twitter < HTTPAttack::Items::Base
|
5
5
|
STATS = ['followers_count', 'friends_count']
|
6
6
|
|
7
7
|
def initialize(username, options = {})
|
8
|
-
options[:
|
9
|
-
raise
|
8
|
+
options[:remote_stat] ||= 'followers_count'
|
9
|
+
raise Items::InvalidStat unless STATS.include?(options[:remote_stat])
|
10
10
|
@username = username
|
11
|
-
@
|
11
|
+
@remote_stat = options[:remote_stat]
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def stat
|
15
15
|
self.reload_stats! unless stats
|
16
|
-
stats[@
|
16
|
+
stats[@remote_stat].to_i
|
17
17
|
end
|
18
18
|
|
19
19
|
def stats_url
|
@@ -22,6 +22,6 @@ module HTTPAttack
|
|
22
22
|
|
23
23
|
end # Twitter
|
24
24
|
|
25
|
-
end #
|
25
|
+
end # Items
|
26
26
|
end # HTTPAttack
|
27
27
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
|
-
include HTTPAttack::
|
3
|
+
include HTTPAttack::Items
|
4
4
|
describe Base do
|
5
5
|
before(:each) do
|
6
6
|
@remote_api = 'http://localhost:3000/users.json'
|
@@ -8,43 +8,43 @@ describe Base do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should fetch some JSON from the URL' do
|
11
|
-
@
|
12
|
-
data = @
|
11
|
+
@item = Base.new
|
12
|
+
data = @item.reload_stats(@remote_api)
|
13
13
|
data.should_not be_nil
|
14
14
|
data.should be_kind_of(Hash)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should fetch some JSON from the file path' do
|
18
|
-
@
|
19
|
-
data = @
|
18
|
+
@item = Base.new
|
19
|
+
data = @item.reload_stats(@local_file)
|
20
20
|
data.should_not be_nil
|
21
21
|
data.should be_kind_of(Hash)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should return an error hash' do
|
25
|
-
@
|
26
|
-
data = @
|
25
|
+
@item = Base.new
|
26
|
+
data = @item.reload_stats('invalid path')
|
27
27
|
data.should have_key('error')
|
28
28
|
data['error'].should_not be_nil
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should force a subclass to override stats_url' do
|
32
|
-
@
|
32
|
+
@item = Base.new
|
33
33
|
lambda do
|
34
|
-
@
|
35
|
-
end.should raise_error(HTTPAttack::
|
34
|
+
@item.stats_url
|
35
|
+
end.should raise_error(HTTPAttack::Items::MustOverrideMethod)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should load the stats with #fetch_json!' do
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
39
|
+
@item = Base.new
|
40
|
+
@item.reload_stats!(@local_file)
|
41
|
+
@item.stats.should_not be_nil
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'should force a subclass to override
|
45
|
-
@
|
44
|
+
it 'should force a subclass to override stat' do
|
45
|
+
@item = Base.new
|
46
46
|
lambda do
|
47
|
-
@
|
48
|
-
end.should raise_error(HTTPAttack::
|
47
|
+
@item.stat
|
48
|
+
end.should raise_error(HTTPAttack::Items::MustOverrideMethod)
|
49
49
|
end
|
50
50
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
include HTTPAttack::Items
|
3
|
+
|
4
|
+
describe Github do
|
5
|
+
before(:each) do
|
6
|
+
@username = 'Oshuma'
|
7
|
+
@stats_file = File.dirname(__FILE__) + '/responses/github-oshuma.json'
|
8
|
+
@stats_url = "http://github.com/api/v2/json/user/show/#{@username}"
|
9
|
+
|
10
|
+
@item = Github.new(@username)
|
11
|
+
@item.reload_stats!(@stats_file)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should form the API URL' do
|
15
|
+
@item.stats_url.should == @stats_url
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should load the item stats' do
|
19
|
+
stats = @item.reload_stats(@stats_file)
|
20
|
+
stats.should_not be_nil
|
21
|
+
stats.should be_kind_of(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should default to the followers_count remote_stat' do
|
25
|
+
@item.instance_variable_get(:@remote_stat).should == 'followers_count'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have a (followers_count) stat of 15' do
|
29
|
+
@item = Github.new(@username, :stat => 'followers_count')
|
30
|
+
@item.reload_stats!(@stats_file) # test data
|
31
|
+
@item.stat.should == 15
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a (following_count) stat of 37' do
|
35
|
+
@item = Github.new(@username, :remote_stat => 'following_count')
|
36
|
+
@item.reload_stats!(@stats_file) # test data
|
37
|
+
@item.stat.should == 37
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise InvalidStat' do
|
41
|
+
lambda do
|
42
|
+
Github.new(@username, :remote_stat => 'invalid')
|
43
|
+
end.should raise_error(HTTPAttack::Items::InvalidStat)
|
44
|
+
end
|
45
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
include HTTPAttack::Items
|
3
|
+
|
4
|
+
describe Twitter do
|
5
|
+
before(:each) do
|
6
|
+
@username = 'oshuma_dev'
|
7
|
+
@stats_file = File.dirname(__FILE__) + '/responses/twitter-oshuma_dev.json'
|
8
|
+
@stats_url = "http://twitter.com/users/show/#{@username}.json"
|
9
|
+
|
10
|
+
@item = Twitter.new(@username)
|
11
|
+
@item.reload_stats!(@stats_file)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should form the API URL' do
|
15
|
+
@item.stats_url.should == @stats_url
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should load the item stats' do
|
19
|
+
stats = @item.reload_stats(@stats_file)
|
20
|
+
stats.should_not be_nil
|
21
|
+
stats.should be_kind_of(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should default to the followers_count remote_stat' do
|
25
|
+
@item.instance_variable_get(:@remote_stat).should == 'followers_count'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have a (followers_count) stat of 19' do
|
29
|
+
@item = Twitter.new(@username, :stat => 'followers_count')
|
30
|
+
@item.reload_stats!(@stats_file) # test data
|
31
|
+
@item.stat.should == 19
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a (friends_count) stat of 1' do
|
35
|
+
@item = Twitter.new(@username, :remote_stat => 'friends_count')
|
36
|
+
@item.reload_stats!(@stats_file) # test data
|
37
|
+
@item.stat.should == 1
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise InvalidStat' do
|
41
|
+
lambda do
|
42
|
+
Twitter.new(@username, :remote_stat => 'invalid')
|
43
|
+
end.should raise_error(HTTPAttack::Items::InvalidStat)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include HTTPAttack
|
4
|
+
describe Items do
|
5
|
+
it 'should have a TYPES array containing weapon classes' do
|
6
|
+
Items::TYPES.should be_kind_of(Array)
|
7
|
+
Items::TYPES.each do |type|
|
8
|
+
type.class.should == Class
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have an each method pointing to TYPES' do
|
13
|
+
Items.each do |type|
|
14
|
+
type.class.should == Class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have a map method pointing to TYPES' do
|
19
|
+
Items.map { |weapon| weapon }.should == Items::TYPES
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpattack-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-11 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Contains core functionality of the HTTPAttack web game.
|
17
17
|
email:
|
18
18
|
- oshuma@gmail.com
|
19
19
|
executables: []
|
@@ -25,17 +25,18 @@ extra_rdoc_files: []
|
|
25
25
|
files:
|
26
26
|
- README
|
27
27
|
- Rakefile
|
28
|
-
- lib/httpattack/
|
29
|
-
- lib/httpattack/
|
30
|
-
- lib/httpattack/
|
31
|
-
- lib/httpattack/
|
28
|
+
- lib/httpattack/items/base.rb
|
29
|
+
- lib/httpattack/items/github.rb
|
30
|
+
- lib/httpattack/items/twitter.rb
|
31
|
+
- lib/httpattack/items.rb
|
32
32
|
- lib/httpattack.rb
|
33
|
-
- spec/httpattack/
|
34
|
-
- spec/httpattack/
|
35
|
-
- spec/httpattack/
|
36
|
-
- spec/httpattack/
|
37
|
-
- spec/httpattack/
|
38
|
-
- spec/httpattack/
|
33
|
+
- spec/httpattack/items/base_spec.rb
|
34
|
+
- spec/httpattack/items/github_spec.rb
|
35
|
+
- spec/httpattack/items/responses/base.json
|
36
|
+
- spec/httpattack/items/responses/github-oshuma.json
|
37
|
+
- spec/httpattack/items/responses/twitter-oshuma_dev.json
|
38
|
+
- spec/httpattack/items/twitter_spec.rb
|
39
|
+
- spec/httpattack/items_spec.rb
|
39
40
|
- spec/httpattack_spec.rb
|
40
41
|
- spec/spec.opts
|
41
42
|
- spec/spec_helper.rb
|
@@ -62,10 +63,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
version:
|
63
64
|
requirements: []
|
64
65
|
|
65
|
-
rubyforge_project:
|
66
|
+
rubyforge_project: httpattack-lib
|
66
67
|
rubygems_version: 1.3.5
|
67
68
|
signing_key:
|
68
69
|
specification_version: 3
|
69
|
-
summary: The game library for HTTPAttack
|
70
|
+
summary: The game library for HTTPAttack.
|
70
71
|
test_files: []
|
71
72
|
|
data/lib/httpattack/weapons.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'httpattack/weapons/base'
|
2
|
-
require 'httpattack/weapons/github'
|
3
|
-
require 'httpattack/weapons/twitter'
|
4
|
-
|
5
|
-
module HTTPAttack
|
6
|
-
module Weapons
|
7
|
-
class InvalidStat < Exception; end
|
8
|
-
class MustOverrideMethod < Exception; end
|
9
|
-
end # Weapons
|
10
|
-
end # HTTPAttack
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
include HTTPAttack::Weapons
|
3
|
-
|
4
|
-
describe Github do
|
5
|
-
before(:each) do
|
6
|
-
@username = 'Oshuma'
|
7
|
-
@stats_file = File.dirname(__FILE__) + '/responses/github-oshuma.json'
|
8
|
-
@stats_url = "http://github.com/api/v2/json/user/show/#{@username}"
|
9
|
-
|
10
|
-
@weapon = Github.new(@username)
|
11
|
-
@weapon.reload_stats!(@stats_file)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should form the API URL' do
|
15
|
-
@weapon.stats_url.should == @stats_url
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should load the weapon stats' do
|
19
|
-
stats = @weapon.reload_stats(@stats_file)
|
20
|
-
stats.should_not be_nil
|
21
|
-
stats.should be_kind_of(Hash)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should default to the followers_count stat' do
|
25
|
-
@weapon.stat.should == 'followers_count'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should have a (followers_count) attack of 15' do
|
29
|
-
@weapon = Github.new(@username, :stat => 'followers_count')
|
30
|
-
@weapon.reload_stats!(@stats_file) # test data
|
31
|
-
@weapon.attack.should == 15
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should have a (following_count) attack of 37' do
|
35
|
-
@weapon = Github.new(@username, :stat => 'following_count')
|
36
|
-
@weapon.reload_stats!(@stats_file) # test data
|
37
|
-
@weapon.attack.should == 37
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise InvalidStat' do
|
41
|
-
lambda do
|
42
|
-
Github.new(@username, :stat => 'invalid')
|
43
|
-
end.should raise_error(HTTPAttack::Weapons::InvalidStat)
|
44
|
-
end
|
45
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
include HTTPAttack::Weapons
|
3
|
-
|
4
|
-
describe Twitter do
|
5
|
-
before(:each) do
|
6
|
-
@username = 'oshuma_dev'
|
7
|
-
@stats_file = File.dirname(__FILE__) + '/responses/twitter-oshuma_dev.json'
|
8
|
-
@stats_url = "http://twitter.com/users/show/#{@username}.json"
|
9
|
-
|
10
|
-
@weapon = Twitter.new(@username)
|
11
|
-
@weapon.reload_stats!(@stats_file)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should form the API URL' do
|
15
|
-
@weapon.stats_url.should == @stats_url
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should load the weapon stats' do
|
19
|
-
stats = @weapon.reload_stats(@stats_file)
|
20
|
-
stats.should_not be_nil
|
21
|
-
stats.should be_kind_of(Hash)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should default to the followers_count stat' do
|
25
|
-
@weapon.stat.should == 'followers_count'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should have a (followers_count) attack of 19' do
|
29
|
-
@weapon = Twitter.new(@username, :stat => 'followers_count')
|
30
|
-
@weapon.reload_stats!(@stats_file) # test data
|
31
|
-
@weapon.attack.should == 19
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should have a (friends_count) attack of 1' do
|
35
|
-
@weapon = Twitter.new(@username, :stat => 'friends_count')
|
36
|
-
@weapon.reload_stats!(@stats_file) # test data
|
37
|
-
@weapon.attack.should == 1
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should raise InvalidStat' do
|
41
|
-
lambda do
|
42
|
-
Twitter.new(@username, :stat => 'invalid')
|
43
|
-
end.should raise_error(HTTPAttack::Weapons::InvalidStat)
|
44
|
-
end
|
45
|
-
end
|