Class: RStack::StackExchange
- Inherits:
-
Object
- Object
- RStack::StackExchange
- Defined in:
- lib/rstack/stack_exchange.rb
Constant Summary collapse
- API_VERSION =
'0.9'
Instance Method Summary collapse
-
#badges ⇒ Object
Get all badges for this StackExchange, in alphabetical order.
-
#initialize(api_host, api_port = 80) ⇒ StackExchange
constructor
Create a new StackExchange object for interacting with the API for a given site
api_host
The API host to use (ie: ‘api.stackoverflow.com’).
Constructor Details
#initialize(api_host, api_port = 80) ⇒ StackExchange
Create a new StackExchange object for interacting with the API for a given site api_host
The API host to use (ie: ‘api.stackoverflow.com’)
10 11 12 13 |
# File 'lib/rstack/stack_exchange.rb', line 10 def initialize(api_host, api_port = 80) @api_host = api_host @api_port = api_port end |
Instance Method Details
#badges ⇒ Object
Get all badges for this StackExchange, in alphabetical order
16 17 18 19 20 21 |
# File 'lib/rstack/stack_exchange.rb', line 16 def badges response = Net::HTTP.get_response(@api_host, "/#{API_VERSION}/badges", @api_port) body = inflate_string(response.body) # TODO error handling JSON.parse(body)['badges'].map { |b| Badge.new(b) } end |