This is a good time to point out that oftentimes the hardest part of accessing an API is authentication. Those with public leagues can skip that step. For those of you with private leagues, you will need to go into your browser to retrieve some cookies. If you’re following along for your own fantasy league, you may need to pause here. Then we’ll want to pull in our gems to our main.rb class: Go ahead and do a bundle install if you don’t already have these gems (Tools > Bundler > Install). In my environment, I was also receiving an error for the FFI gem, so we’ll specify a version for that as well. As mentioned before, the only gem we’ll need for now is rest-client. We’ll also want to create a Gemfile to bring in the necessary libraries. We’re going to begin with a new Ruby class called main.rb. So let’s get started building our new project. For instructions on this, see Josh’s previous blog post here and stop at “Install Appium”. Note: From here on, I will assume that you have a valid installation of Ruby and Rubymine. We could just use Selenium to scrape data off the site, but websites are subject to change and API’s tend to be much more stable. Many fantasy football platforms supply you with lots of good data, but we don’t have the raw data to play around with and analyze. Points are awarded based on stats such as yards gained and touchdowns. Everyone gets to draft real players to fill out their rosters, set their lineups, make trades, pick up free agents, and much more. Even if you don’t care about fantasy football, hopefully this post will still provide some useful information for you to learn from.įor the uninitiated, fantasy football is when a group of degenerates pit their imaginary football teams against each other in a weekly matchup. First, let’s give a little background on fantasy football and why this is some fun data to pull. We’ll be building out several classes that interact with different pieces of data and organize our code in a way that makes sense. The main purpose is to show you how to pull ESPN data, but we will be trying to look at this from a learning perspective and highlight practices that we can use when working with any web service. In this post we will be mainly using the Ruby rest-client gem to send GET requests to the API, and then we will be pulling data from the JSON data that we receive back. I’m a huge fantasy football nut, and since I work with Ruby so much I decided to build my own project that would connect to ESPN and extract various data for my fantasy football league. A couple years ago I found this post explaining how to connect to ESPN’s “hidden” API using Python. I think many people who don’t have experience working with web services can feel intimidated by them, and might be looking for a good excuse to practice with them. For the past several years I have been passionate about making things easier in the automation world by taking advantage of API’s.
0 Comments
Leave a Reply. |