Friday, April 15, 2016

Eighth Week of LITG Program

The task of the 8th week is to code the API(QUserAPI) to return information from Quora user profiles. This API uses the pyquora package developed throughout the fifth week of the LITG program. I followed the Horoscope-API(https://github.com/tapasweni-pathak/Horoscope-API) developed by my mentor, as a reference to learn when coding QuserAPI. The final API is available on the github repository at https://github.com/hansika/QuserAPI. This API consists of the following files. 
  • License.md 
  • Profile 
  • README.md 
  • requirements.txt 
  • server.py 
Out of these, the server.py is the file coded within this week. The License.md and the README.md files were added to the project way back during the first and the second weeks of the program. Of course the README.md file was modified during this week to include the features of the API. The Profile and the requirements.txt are two files needed by the file structure of Heroku, where we are expecting to deploy the API over the next weeks. These files will be explained in detail in a blog post in an upcoming week. 

The server.py file was coded similar to the server.py file of Horoscope-API which was studied in depth during the last week. It uses Flask Python framework. This file has one method for each of the features of the pyquora package. These features and their corresponding methods are as follows. 
  • Quora Profile - profile_name_route(user_name)
  • NameQuora Profile Picture Link - profile_picture_link_route(user_name)
  • Quora Profile URL - url_route(user_name)
  • Number of Questions - no_of_questions_route(user_name)
  • Number of Answers - no_of_answers_route(user_name)
  • Number of Followers - no_of_followers_route(user_name)
  • Number of Following - no_of_questions_following(user_name)
  • Number of Edits - no_of_edits_route(user_name)
All the above methods call the methods of the pyquora package in order to scrape Quora user profiles. Also there is another method named index_route() which returns additional details related to the API such as the author, project name, project url, project issues, base url and end points. All these methods have their own route decorators and all the methods have used GET requests. Furthermore, all the methods return their results in the form of a json object using the jsonify method of Flask which was discussed in detail in the blog post of the seventh week. Few example route decorators and their corresponding methods are shown below. 
  • index_route() - @app.route('/', methods=['GET'])
  • profile_name_route(user_name) - @app.route('/profile/name/<user_name>', methods=['GET'])
  • profile_picture_link_route(user_name) - @app.route('/profile/picture_link/<user_name>', methods=['GET'])
  • url_route(user_name) - @app.route('/url/<user_name>', methods=['GET'])
  • no_of_answers_route(user_name) - @app.route('/profile/number/answers/<user_name>', methods=['GET'])
The tasks to be completed during the next weeks are to read, find out about Heroku and finally deploy this API on Heroku. Therefore, the next blog post will be basically about what is Heroku. 

No comments:

Post a Comment