Skip to content

Challenge #3: Initializing a Class

Franccesco Orozco edited this page Apr 26, 2018 · 5 revisions

Difficulty: ⭐⭐

Test: pipenv run python -m unittest tests/test_challenge_3.py -f


Instructions

  • Import the package requests. Beware: It is more beneficial to load only the packages that you need, in this case you will need the method get from requests package.
  • Modify your IPInfo class inside ipinfo.py and define your initialization module. This initialization will require only one parameter of type string and will be called ip.
  • Create a Class Attribute named ip_data. This class attribute will requests a json response from the public API https://ipinfo.io/IP_NUMBER/json where IP_NUMBER is equal to the initialization parameter ip. To challenge yourself, try to make this JSON request in a single line.

TL;DR: Define your class initialization that accepts only one parameter => Create a class attributes that makes a json requests to https://ipinfo.io/IP_NUMBER/json


Documentation