Created
June 29, 2012 15:50
-
-
Save djtal/3018752 to your computer and use it in GitHub Desktop.
BGG small API test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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