PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://bitbucket.org/A_Red/challenge-backend
Markdown | 135 lines | 105 code | 30 blank | 0 comment | 0 complexity | 06d84be4190ff2d3d2a6afac1e7888f6 MD5 | raw file
  1. # Fork this project and send back a pull request.
  2. ## What to do
  3. Create a simple RESTful API that imports data from GitHub Search API https://developer.github.com/v3/search/
  4. Import repositories that have been written in Python and have more than 500 stars. Import just a few fields from GitHub Search API:
  5. `full_name`, `html_url`, `description`, `stargazers_count`, `language`.
  6. You may use any database or just store repositories in a RAM.
  7. REQUIREMENTS:
  8. 1. It is necessary to do a script/function/endpoint to fill the database.
  9. 2. Add pagination to API.
  10. 3. Add docsrings and comments to your code.
  11. 4. Describe your solution in the README.md file.
  12. ## Bonus 1
  13. Add sorting by `stars` to an API.
  14. ## Bonus 2
  15. Use docker compose encapsulating all the services related to this app.
  16. ## Some help
  17. * How to fork https://confluence.atlassian.com/bitbucket/forking-a-repository-221449527.html
  18. * How to create a pull request https://confluence.atlassian.com/bitbucket/create-a-pull-request-774243413.html
  19. ## Describing my solution
  20. According to the task to create a simple RESTful API Server which will be
  21. working with the GitHub API I decided to use such tools like:
  22. 1. Framework: I choose asyncio and aiohttp, because at first these both modules
  23. work asynchronously that's why they are faster, at second asyncio is the part
  24. of the python 3.4+ versions (we could use it "from the box") and at last
  25. current task to create API Server with 1 endpoint is minor task and this is
  26. no sense to use large frameworks like Django, Flask and etc...
  27. 2. DB: after reading GitHub's API manul I know that GitHub response data in json
  28. format. The best way to work with JSON at this case is to use MongoDB,
  29. because its Document Oriented Storage and we haven't to convert data for store.
  30. DB schema:
  31. "github" - database
  32. "repositories" - collection for storing data from github
  33. create user for connection to db:
  34. "db.createUser({user:"admin", pwd:"admin123", roles:[{role:"root", db:"admin"}]})"
  35. 3. Pagination: According to GitHub API manual for developers the API will
  36. automatically paginate the requested items. "Different API calls respond
  37. with different defaults. For example, a call to list GitHub's public
  38. repositories provides paginated items in sets of 30, whereas a call to
  39. the GitHub Search API provides items in sets of 100".
  40. See https://developer.github.com/v3/#pagination
  41. I will use for pagination parameters "?page" and "per_page" in requests and
  42. in response I will add field with "The Link header includes pagination information:"
  43. Example below:
  44. "Link: <https://api.github.com/user/repos?page=3&per_page=100>; rel="next",
  45. <https://api.github.com/user/repos?page=50&per_page=100>; rel="last""
  46. 4. Authentication: Authentication user could send 5000 request per hour and
  47. unauthentication user could send 60 request per hour. Some endpoints at GitHub
  48. Search API require that request from authenticate user.
  49. A wrote code wich authorize user by his credentials like 'username' and 'password'.
  50. But I haven't user acc for testing in bitbucket (atlassian) that's why I
  51. comment lines 54-55
  52. """
  53. #auth = aiohttp.BasicAuth(login=config['username'],
  54. # password=config['password'])
  55. """
  56. and define variable "auth" like None.
  57. 5. How to check that server is work.
  58. Type in the browser:
  59. http://{HOST}:{PORT}/github/searh/v0.1?language=python&stars=600&per_page=100
  60. According to my settings it looks:
  61. http://localhost:11071/github/searh/v0.1?language=python&stars=600&per_page=100
  62. And you have to get response:
  63. {
  64. "items": [{
  65. "full_name": "vinta/awesome-python",
  66. "html_url": "https://github.com/vinta/awesome-python",
  67. "description": "A curated list of awesome Python frameworks, libraries, software and resources",
  68. "stargazers_count": 50726,
  69. "language": "Python"
  70. },
  71. ......
  72. , {
  73. "full_name": "Miserlou/Zappa",
  74. "html_url": "https://github.com/Miserlou/Zappa",
  75. "description": "Serverless Python",
  76. "stargazers_count": 7125,
  77. "language": "Python"
  78. }, {
  79. "full_name": "RaRe-Technologies/gensim",
  80. "html_url": "https://github.com/RaRe-Technologies/gensim",
  81. "description": "Topic Modelling for Humans",
  82. "stargazers_count": 7100,
  83. "language": "Python"
  84. }],
  85. "pagination": "<https://api.github.com/search/repositories?q=language%3Apython+stars%3A%3E500&sort=stars&page=2&per_page=100>; rel=\"next\", <https://api.github.com/search/repositories?q=language%3Apython+stars%3A%3E500&sort=stars&page=10&per_page=100>; rel=\"last\""
  86. 6. NOT GOOD solutions in my code (In my opinion):
  87. - Construction
  88. "async with aiohttp.ClientSession(auth=auth) as session:" (line 60) doesn't
  89. recommend to use inside the event handler. Link to manual:
  90. "https://docs.aiohttp.org/en/stable/client_advanced.html?highlight=ClientSession"
  91. But at this server we have only 1 endpoint and 1 handler (and little free time)
  92. - and this was make sense here.
  93. 7. How much time did I spend:
  94. 2 hours - to read documents for GitHub Search API and googling info about it.
  95. The major part of the time spent for looking for filters which depend fields
  96. in JSON. ('full_name','html_url','description','stargazers_count','language').
  97. But I didn't.
  98. 1 hours - to choose technologies and tools.
  99. 11 hours - for developing and debugging + fighting with mongodb launching.
  100. PS: I had BLOCKERS: In my laptop (OSX High Sierrs) was python 3.4 as default
  101. in system and I didn't update OS for long long period. As a result when I
  102. start updating python3.4 to python3.6.5 I got a problems.
  103. All fridays evening I fixed this.
  104. That's all)
  105. If you have a question you could write or call me. I answer with a pleasure.