rstack 0.0.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/rstack.rb +10 -0
- data/lib/rstack/badge.rb +19 -0
- data/lib/rstack/stack_exchange.rb +32 -0
- data/lib/rstack/version.rb +5 -0
- metadata +88 -0
data/lib/rstack.rb
ADDED
data/lib/rstack/badge.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module RStack
|
2
|
+
|
3
|
+
class Badge
|
4
|
+
|
5
|
+
ATTRS = [:badge_id, :rank, :name, :description, :award_count, :tag_based, :badges_recipients_url]
|
6
|
+
|
7
|
+
attr_reader *ATTRS
|
8
|
+
|
9
|
+
def initialize(b)
|
10
|
+
b.each { |k, v| self.send("#{k}=", v) }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_writer *ATTRS
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RStack
|
2
|
+
|
3
|
+
class StackExchange
|
4
|
+
|
5
|
+
API_VERSION = '0.9'
|
6
|
+
|
7
|
+
# Create a new StackExchange object for interacting with the
|
8
|
+
# API for a given site
|
9
|
+
# +api_host+ The API host to use (ie: 'api.stackoverflow.com')
|
10
|
+
def initialize(api_host, api_port = 80)
|
11
|
+
@api_host = api_host
|
12
|
+
@api_port = api_port
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get all badges for this StackExchange, in alphabetical order
|
16
|
+
def badges
|
17
|
+
response = Net::HTTP.get_response(@api_host, "/#{API_VERSION}/badges", @api_port)
|
18
|
+
body = inflate_string(response.body)
|
19
|
+
# TODO error handling
|
20
|
+
JSON.parse(body)['badges'].map { |b| Badge.new(b) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def inflate_string(string)
|
26
|
+
gz = Zlib::GzipReader.new(StringIO.new(string))
|
27
|
+
gz.read
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rstack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- John Crepezzi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-07 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: json
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
description: rstack is a Ruby wrapper for the Stack Exchange API
|
45
|
+
email: john@crepezzi.com
|
46
|
+
executables: []
|
47
|
+
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
extra_rdoc_files: []
|
51
|
+
|
52
|
+
files:
|
53
|
+
- lib/rstack/badge.rb
|
54
|
+
- lib/rstack/stack_exchange.rb
|
55
|
+
- lib/rstack/version.rb
|
56
|
+
- lib/rstack.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://seejohnrun.github.com/rstack/
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: rstack
|
83
|
+
rubygems_version: 1.3.6
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Ruby Stack Exchange API Wrapper
|
87
|
+
test_files: []
|
88
|
+
|