Class: RStack::StackExchange

Inherits:
Object
  • Object
show all
Defined in:
lib/rstack/stack_exchange.rb

Constant Summary collapse

API_VERSION =
'0.9'

Instance Method Summary collapse

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

#badgesObject

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