Giter Site home page Giter Site logo

ruby-getting-remote-data-lab-chicago-web-033020's Introduction

Getting Remote Data Lab

Learning Goals

  • Practice sending GET requests using Ruby
  • Build a reusable class for sending requests and handling responses

Introduction

It is time to practice building out your own class for retrieving remote data. In this lab, you are tasked with building a generic GetRequester class. This class will be able to take in a URL on initialization and send an HTTP GET request on command. You will also need to build a method for dealing with requests that return JSON.

When complete, you will have a simple, but versatile class for getting information from all kinds of sources over the internet.

Instructions

All work should be completed in lib/get_requester.rb. Use the previous code-along on getting data from APIs as a reference when building out your class.

Start by creating a GetRequester class. This class should be able to initialize with a string URL.

The GetRequester class should have a get_response_body method that sends a GET request to the URL passed in on initialization. This method should return the body of the response.

The GetRequester class should have a parse_json method should use get_response_body to send a request, then return a Ruby Array or Hash made up of data converted from the response of that request.

The tests in this lab will use your code to send a request for some JSON data, located at https://learn-co-curriculum.github.io/json-site-example/endpoints/people.json. Read the test error messages for additional as you work for additional information. Don't forget to require the necessary Ruby modules and classes!

Conclusion

Once you've successfully passed the tests, from this lesson's directory, you should be able to open IRB, use require_relative to load lib/get_requester.rb, and send out some requests!

get_requester = GetRequester.new('https://learn-co-curriculum.github.io/json-site-example/endpoints/people.json')
get_requester.parse_json
#=> [{"name"=>"Daniel", "occupation"=>"LG Fridge Salesman"}, {"name"=>"Joe", "occupation"=>"WiFi Fixer"}, {"name"=>"Avi", "occupation"=>"DJ"}, {"name"=>"Howard", "occupation"=>"Mountain Legend"}]

This class won't work for all cases but is a good starting place to get us off the ground. We can now augment our applications with data from the internet! Combined with our knowledge of Ruby, we have all the tools we need to start building smarter Ruby applications populated with real data.

ruby-getting-remote-data-lab-chicago-web-033020's People

Contributors

maxwellbenton avatar drakeltheryuujin avatar

Watchers

 avatar  avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar  avatar Ben Oren avatar Matt avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar Kaeland Chatman avatar  avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.