Skip to content

Instantly share code, notes, and snippets.

@djtal
Created June 29, 2012 15:50
Show Gist options
  • Save djtal/3018752 to your computer and use it in GitHub Desktop.
Save djtal/3018752 to your computer and use it in GitHub Desktop.
BGG small API test
require 'rubygems'
require 'faraday'
require 'faraday_middleware'
@conn = Faraday.new(:url => 'http://www.boardgamegeek.com/xmlapi2/') do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
faraday.response :logger # log requests to STDOUT
faraday.response :xml, :content_type => /\bxml$/
end
def search(name)
resp = @conn.get('search', {:query => name, :type => 'boardgame'})
games = resp.body['items']['item']
end
def game(id)
resp = @conn.get('thing', {:type => %w(boardgame boardgamexpension) * ',', :id => id.is_a?(Array) ? id * ',' : id})
resp.body['items']['item']
end
def trending
resp = @conn.get('hot', :type => 'boardgame')
resp.body['items']['item']
e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment