This gem serves as an interface to the SODA (Sports On Demand API) from XML Team. It uses HTTParty and Nokogiri to retrieve and parse the data.
Add this line to your application's Gemfile:
gem 'soda_xml_team'
And then execute:
$ bundle
Or install it yourself as:
$ gem install soda_xml_team
The SODA service works by keeping revisions of various documents (schedules, news, injury reports, etc.) that you are charged pre-paid credit for downloading. It is currently does not cost any credits to obtain the list of available documents.
soda = SodaXmlTeam::Client.new('your_username', 'your_password')
listing = soda.content_finder({
# Set sandbox to true if you are browsing the trial dataset
sandbox: false,
league_id: 'l.nhl.com',
team_id: 'l.nhl.com-t.19',
type: 'schedule-single-team',
start_datetime: '2010-01-01 00:00:00 CDT',
end_datetime: '2011-01-01 00:00:00 CDT'
})
# An array of documents matching your query
puts listing.inspect
Once you have this listing, you can obtain the individual document. As each document costs a credit per download (even if you download the same version again), it is recommended that you cache / index this data somewhere in your application to avoid quickly depleting your credit balance.
soda = SodaXmlTeam::Client.new('your_username', 'your_password')
document = soda.get_document({
# Set sandbox to true if you are browsing the trial dataset
sandbox: false,
document_id: 'xt.10875359-nas-sked'
})
# A Nokogiri XML representation of the document contents
puts document.inspect
For some of the more common data types, the gem will create a native ruby representation of the data if you run it through one of the parsing methods.
soda = SodaXmlTeam::Client.new('your_username', 'your_password')
schedule_document = soda.get_document({
sandbox: true,
document_id: 'xt.10875359-nas-sked'
})
schedule = SodaXmlTeam::Schedule.parse_schedule(schedule_document)
# This is now available as an array of values
puts schedule.inspect
soda = SodaXmlTeam::Client.new('your_username', 'your_password')
news_document = soda.get_document({
sandbox: true,
document_id: 'xt.3329967-NAS-2005-OUTLOOK'
})
article = SodaXmlTeam::Schedule.parse_news(news_document)
# This is now available as an array of values
puts article.inspect
soda = SodaXmlTeam::Client.new('your_username', 'your_password')
standings_document = soda.get_document({
sandbox: true,
document_id: 'xt.10878197-standings'
})
standings = SodaXmlTeam::Standings.parse_standings(standings_document)
# This is now available as an array of values
puts standings.inspect
This gem includes an executable for parsing files from the SODA League Directory, which is useful for handling a particular sports league.
$ soda-league-directory ~/Downloads/xt.20140505T114154-0400.l.afa.ar.primera-leaguedir.xml
[{:import_key=>"o.afa.ar-t.113", :entity_name=>"Argentinos Juniors ", :status=>1, :entity_type=>"l.afa.ar.primera"}, {:import_key=>"o.afa.ar-t.92", :entity_name=>"Arsenal de Sarandi ", :status=>1, :entity_type=>"l.afa.ar.primera"}, ... ]
- Fork it ( https://github.com/seatshare/soda_xml_team/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request