pilha 0.1.1
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/lib/pilha.rb +92 -0
- data/lib/pilha/stack_overflow/badge.rb +29 -0
- data/lib/pilha/stack_overflow/statistics.rb +29 -0
- data/lib/pilha/stack_overflow/user.rb +33 -0
- data/pilha.gemspec +26 -0
- data/spec/fixtures/badges.json +400 -0
- data/spec/fixtures/badges_by_id.json +966 -0
- data/spec/fixtures/badges_by_id_page2.json +1612 -0
- data/spec/fixtures/badges_name.json +400 -0
- data/spec/fixtures/stats.json +20 -0
- data/spec/pilha/stack_overflow/badge_spec.rb +23 -0
- data/spec/pilha/stack_overflow/stack_overflow_spec.rb +60 -0
- data/spec/pilha/stack_overflow/statistics_spec.rb +27 -0
- data/spec/pilha/stack_overflow/user_spec.rb +47 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +33 -0
- metadata +77 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StackExchange::StackOverflow::Statistics do
|
4
|
+
|
5
|
+
before do
|
6
|
+
StackExchange::StackOverflow::Client.config
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'when querying for statistics' do
|
10
|
+
it "should return the stack overflow's statistics" do
|
11
|
+
response = StackOverflow::Statistics.all
|
12
|
+
response.total_questions.should == 692539
|
13
|
+
response.total_unanswered.should == 107245
|
14
|
+
response.total_answers.should == 1938135
|
15
|
+
response.total_comments.should == 2724322
|
16
|
+
response.total_votes.should == 6817279
|
17
|
+
response.total_badges.should == 699700
|
18
|
+
response.total_users.should == 247683
|
19
|
+
response.questions_per_minute.should == 1.78
|
20
|
+
response.answers_per_minute.should == 3.71
|
21
|
+
response.badges_per_minute.should == 1.58
|
22
|
+
response.api_version['version'].should == "0.8"
|
23
|
+
response.api_version['revision'].should == "1.0.1234.5678"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StackExchange::StackOverflow::User do
|
4
|
+
|
5
|
+
it "should the users that have been awarded the badge identified by 'id'" do
|
6
|
+
response = StackOverflow::User.find_by_badge_id 9
|
7
|
+
response.total.should == 28080
|
8
|
+
response.page.should == 1
|
9
|
+
response.pagesize.should == 30
|
10
|
+
|
11
|
+
first_user = response.users.first
|
12
|
+
first_user.should be_instance_of StackOverflow::User
|
13
|
+
first_user.user_id.should == 349130
|
14
|
+
first_user.user_type.should == "registered"
|
15
|
+
first_user.creation_date.should == 1274719205
|
16
|
+
first_user.display_name.should == "matias.valdenegro"
|
17
|
+
first_user.reputation.should == 16
|
18
|
+
first_user.email_hash.should == "2e4efeebbf6994bb904738c4fb8922bf"
|
19
|
+
first_user.age.should == 25
|
20
|
+
first_user.last_access_date.should == 1274894693
|
21
|
+
first_user.website_url.should == "http://None"
|
22
|
+
first_user.location.should == "Santiago, Chile."
|
23
|
+
first_user.about_me.should == "Computer Engineer, interested in Robotics, Computer Graphics, and GPGPU."
|
24
|
+
first_user.question_count.should be_zero
|
25
|
+
first_user.answer_count.should == 2
|
26
|
+
first_user.view_count.should be_zero
|
27
|
+
first_user.up_vote_count.should be_zero
|
28
|
+
first_user.down_vote_count.should be_zero
|
29
|
+
first_user.user_questions_url.should == "/users/349130/questions"
|
30
|
+
first_user.user_answers_url.should == "/users/349130/answers"
|
31
|
+
first_user.user_tags_url.should == "/users/349130/tags"
|
32
|
+
first_user.user_badges_url.should == "/users/349130/badges"
|
33
|
+
first_user.user_timeline_url.should == "/users/349130/timeline"
|
34
|
+
first_user.user_mentioned_url.should == "/users/349130/mentioned"
|
35
|
+
first_user.user_comments_url.should == "/users/349130/comments"
|
36
|
+
first_user.user_reputation_url.should == "/users/349130/reputation"
|
37
|
+
first_user.badge_counts['gold'].should be_zero
|
38
|
+
first_user.badge_counts['silver'].should be_zero
|
39
|
+
first_user.badge_counts['bronze'].should == 1
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return the right number of items when pagesize is passed in the query parameters' do
|
43
|
+
response = StackOverflow::User.find_by_badge_id(9, :pagesize => 50)
|
44
|
+
response.pagesize.should == 50
|
45
|
+
response.users.size.should == 50
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'fakeweb'
|
6
|
+
require 'pilha'
|
7
|
+
require 'spec'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
include StackExchange
|
11
|
+
FIXTURES_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
12
|
+
ROOT_URL = [StackOverflow::Client::URL.chomp('/'), StackOverflow::Client::API_VERSION].join '/'
|
13
|
+
FakeWeb.allow_net_connect = false
|
14
|
+
|
15
|
+
def register(options)
|
16
|
+
url = api_method_url(options[:url])
|
17
|
+
FakeWeb.register_uri(:get, url, :body => read_fixture(options[:body] + '.json'))
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_fixture(fixture)
|
21
|
+
File.read(File.join(FIXTURES_PATH, fixture))
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_method_url(method)
|
25
|
+
ROOT_URL + '/' + method
|
26
|
+
end
|
27
|
+
|
28
|
+
['stats', 'badges' ].each do |method|
|
29
|
+
register :url => method + '/', :body => method
|
30
|
+
end
|
31
|
+
|
32
|
+
register(:url => 'badges/9/', :body => 'badges_by_id')
|
33
|
+
register(:url => 'badges/9/?pagesize=50', :body => 'badges_by_id_page2')
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pilha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dalto Curvelano Junior
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-27 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A ruby wrapper to the StackExchange (StackOverflow and friends) API.
|
22
|
+
email:
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- pilha.gemspec
|
31
|
+
- lib/pilha/stack_overflow/badge.rb
|
32
|
+
- lib/pilha/stack_overflow/statistics.rb
|
33
|
+
- lib/pilha/stack_overflow/user.rb
|
34
|
+
- lib/pilha.rb
|
35
|
+
- spec/fixtures/badges.json
|
36
|
+
- spec/fixtures/badges_by_id.json
|
37
|
+
- spec/fixtures/badges_by_id_page2.json
|
38
|
+
- spec/fixtures/badges_name.json
|
39
|
+
- spec/fixtures/stats.json
|
40
|
+
- spec/pilha/stack_overflow/badge_spec.rb
|
41
|
+
- spec/pilha/stack_overflow/stack_overflow_spec.rb
|
42
|
+
- spec/pilha/stack_overflow/statistics_spec.rb
|
43
|
+
- spec/pilha/stack_overflow/user_spec.rb
|
44
|
+
- spec/spec.opts
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/dlt/stack_exchange
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.3.6
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: A ruby wrapper to the StackExchange (StackOverflow and friends) API.
|
76
|
+
test_files: []
|
77
|
+
|