httpattack-lib 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +9 -0
- data/lib/httpattack.rb +1 -1
- data/lib/httpattack/items.rb +2 -1
- data/lib/httpattack/items/base.rb +1 -0
- data/lib/httpattack/items/github.rb +1 -1
- data/lib/httpattack/items/status_net.rb +34 -0
- data/lib/httpattack/items/twitter.rb +1 -1
- data/spec/httpattack/items/github_spec.rb +1 -1
- data/spec/httpattack/items/responses/identica-oshuma.json +1 -0
- data/spec/httpattack/items/status_net_spec.rb +45 -0
- data/spec/httpattack/items/twitter_spec.rb +1 -1
- metadata +5 -2
data/README
CHANGED
@@ -16,3 +16,12 @@ determine the Item strength.
|
|
16
16
|
def stat
|
17
17
|
stats['user']['followers_count'].to_i
|
18
18
|
end
|
19
|
+
|
20
|
+
stats_url
|
21
|
+
---------
|
22
|
+
Should return a string which returns the remote API response for the Item.
|
23
|
+
Currently supports JSON.
|
24
|
+
|
25
|
+
def stats_url
|
26
|
+
URI.parse("http://example.com/users/luser.json").to_s
|
27
|
+
end
|
data/lib/httpattack.rb
CHANGED
data/lib/httpattack/items.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'httpattack/items/base'
|
2
2
|
require 'httpattack/items/github'
|
3
|
+
require 'httpattack/items/status_net'
|
3
4
|
require 'httpattack/items/twitter'
|
4
5
|
|
5
6
|
module HTTPAttack
|
6
7
|
module Items
|
7
8
|
|
8
9
|
# A list of registered Item types (the actual classes).
|
9
|
-
TYPES = [ Github, Twitter ]
|
10
|
+
TYPES = [ Github, StatusNet, Twitter ]
|
10
11
|
|
11
12
|
class InvalidStat < Exception; end
|
12
13
|
class MustOverrideMethod < Exception; end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module HTTPAttack
|
2
|
+
module Items
|
3
|
+
|
4
|
+
# Item for the Status.net software (http://status.net/), which is used
|
5
|
+
# by the identi.ca service (http://identi.ca/).
|
6
|
+
#
|
7
|
+
# You can specify the <tt>:api_root</tt> option to point to a different
|
8
|
+
# URL running Status.net (defaults to identi.ca).
|
9
|
+
class StatusNet < HTTPAttack::Items::Base
|
10
|
+
STATS = ['followers_count', 'friends_count']
|
11
|
+
|
12
|
+
def initialize(username, options = {})
|
13
|
+
options[:remote_stat] ||= 'followers_count'
|
14
|
+
options[:api_root] ||= 'identi.ca/api'
|
15
|
+
raise Items::InvalidStat unless STATS.include?(options[:remote_stat])
|
16
|
+
@username = username
|
17
|
+
@remote_stat = options[:remote_stat]
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def stat
|
22
|
+
self.reload_stats! unless stats
|
23
|
+
stats[@remote_stat].to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def stats_url
|
27
|
+
URI.parse("http://#{@options[:api_root]}/users/show/#{@username}.json").to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
end # StatusNet
|
31
|
+
|
32
|
+
end # Items
|
33
|
+
end # HTTPAttack
|
34
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
{"id":12769,"name":"Dale Campbell","screen_name":"oshuma","location":"53703, US","description":"Causing trouble is the most fun you can have.","profile_image_url":"http:\/\/avatar.identi.ca\/12769-48-20090910050144.jpeg","url":"http:\/\/oshuma.github.com\/","protected":false,"followers_count":"36","profile_background_color":"","profile_text_color":"","profile_link_color":"","profile_sidebar_fill_color":"","profile_sidebar_border_color":"","friends_count":"24","created_at":"Tue Jul 08 14:40:08 +0000 2008","favourites_count":"0","utc_offset":"0","time_zone":"UTC","profile_background_image_url":"","profile_background_tile":false,"statuses_count":"2164","following":false,"notifications":false,"status":{"text":"o\/` Dan Le Sac vs Scroobius Pip - Thou Shalt Always Kill o\/`","truncated":false,"created_at":"Sun Sep 13 03:56:05 +0000 2009","in_reply_to_status_id":null,"source":"<a href=\"http:\/\/hellotxt.com\/\">HelloTxt<\/a>","id":9938046,"in_reply_to_user_id":null,"in_reply_to_screen_name":null,"favorited":false}}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
include HTTPAttack::Items
|
4
|
+
describe StatusNet do
|
5
|
+
before(:each) do
|
6
|
+
@username = 'oshuma_dev'
|
7
|
+
@stats_file = File.dirname(__FILE__) + '/responses/identica-oshuma.json'
|
8
|
+
@stats_url = "http://identi.ca/api/users/show/#{@username}.json"
|
9
|
+
|
10
|
+
@item = StatusNet.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 36' do
|
29
|
+
@item = StatusNet.new(@username, :stat => 'followers_count')
|
30
|
+
@item.reload_stats!(@stats_file) # test data
|
31
|
+
@item.stat.should == 36
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have a (friends_count) stat of 24' do
|
35
|
+
@item = StatusNet.new(@username, :remote_stat => 'friends_count')
|
36
|
+
@item.reload_stats!(@stats_file) # test data
|
37
|
+
@item.stat.should == 24
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should raise InvalidStat' do
|
41
|
+
lambda do
|
42
|
+
StatusNet.new(@username, :remote_stat => 'invalid')
|
43
|
+
end.should raise_error(HTTPAttack::Items::InvalidStat)
|
44
|
+
end
|
45
|
+
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- lib/httpattack/items/base.rb
|
29
29
|
- lib/httpattack/items/github.rb
|
30
|
+
- lib/httpattack/items/status_net.rb
|
30
31
|
- lib/httpattack/items/twitter.rb
|
31
32
|
- lib/httpattack/items.rb
|
32
33
|
- lib/httpattack.rb
|
@@ -34,7 +35,9 @@ files:
|
|
34
35
|
- spec/httpattack/items/github_spec.rb
|
35
36
|
- spec/httpattack/items/responses/base.json
|
36
37
|
- spec/httpattack/items/responses/github-oshuma.json
|
38
|
+
- spec/httpattack/items/responses/identica-oshuma.json
|
37
39
|
- spec/httpattack/items/responses/twitter-oshuma_dev.json
|
40
|
+
- spec/httpattack/items/status_net_spec.rb
|
38
41
|
- spec/httpattack/items/twitter_spec.rb
|
39
42
|
- spec/httpattack/items_spec.rb
|
40
43
|
- spec/httpattack_spec.rb
|