Skip to content

Commit

Permalink
Adds requests-ratelimiter and updates request builder (#79)
Browse files Browse the repository at this point in the history
* Adds requests-ratelimiter and updates request builder

- Adds requests-ratelimiter
- Modifies request builder class to use the LimiterSession to make all the requests.

* Modifies the rate limit to one every two second.

* Switches to 300 per 15 minutes rate limit

- Switches to 300 per 15 minutes rate limit based on https://andshrew.github.io/PlayStation-Trophies/#/APIv2?id=api-rate-limit

* Code coverage now pushes to head_ref.ref_name instead

* Fixes an issue with code coverage action

* Update coverage on Readme

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
isFakeAccount and github-actions[bot] authored Jul 8, 2024
1 parent bebbe0c commit 7d22c3c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/code_coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo

- uses: actions/setup-python@v5
with:
python-version: "3.11"
Expand Down Expand Up @@ -60,6 +62,6 @@ jobs:
- name: Commit & Push changes to Readme
uses: actions-js/push@master
with:
branch: master
branch: ${{ github.head_ref || github.ref_name }}
message: Update coverage on Readme
github_token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Retrieve User Information, Trophies, Game and Store data from the PlayStation Ne
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/MIT)

<!-- Pytest Coverage Comment:Begin -->
<a href="https://github.com/isFakeAccount/psnawp/blob/main/README.md"><img alt="Coverage" src="https://img.shields.io/badge/Coverage-91%25-brightgreen.svg" /></a><details><summary>Coverage Report </summary><table><tr><th>File</th><th>Stmts</th><th>Miss</th><th>Cover</th><th>Missing</th></tr><tbody><tr><td colspan="5"><b>src/psnawp_api</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/__init__.py">__init__.py</a></td><td>2</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/psnawp.py">psnawp.py</a></td><td>40</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/psnawp.py#L 95%"> 95%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/core</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/__init__.py">__init__.py</a></td><td>4</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/authenticator.py">authenticator.py</a></td><td>129</td><td>19</td><td>19</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/authenticator.py#L 85%"> 85%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/psnawp_exceptions.py">psnawp_exceptions.py</a></td><td>11</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/request_builder.py">request_builder.py</a></td><td>65</td><td>9</td><td>9</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/request_builder.py#L 86%"> 86%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/models</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/__init__.py">__init__.py</a></td><td>7</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/client.py">client.py</a></td><td>73</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/client.py#L 97%"> 97%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/game_title.py">game_title.py</a></td><td>26</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/game_title.py#L 92%"> 92%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/group.py">group.py</a></td><td>53</td><td>8</td><td>8</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/group.py#L 85%"> 85%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/search.py">search.py</a></td><td>150</td><td>42</td><td>42</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/search.py#L 72%"> 72%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/title_stats.py">title_stats.py</a></td><td>75</td><td>3</td><td>3</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/title_stats.py#L 96%"> 96%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/user.py">user.py</a></td><td>79</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/user.py#L 97%"> 97%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/models/listing</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/listing/__init__.py">__init__.py</a></td><td>2</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/listing/pagination_iterator.py">pagination_iterator.py</a></td><td>56</td><td>4</td><td>4</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/listing/pagination_iterator.py#L 93%"> 93%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/models/trophies</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/__init__.py">__init__.py</a></td><td>6</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy.py">trophy.py</a></td><td>130</td><td>9</td><td>9</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy.py#L 93%"> 93%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_constants.py">trophy_constants.py</a></td><td>30</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_group.py">trophy_group.py</a></td><td>92</td><td>3</td><td>3</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_group.py#L 97%"> 97%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_summary.py">trophy_summary.py</a></td><td>27</td><td>1</td><td>1</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_summary.py#L 96%"> 96%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_titles.py">trophy_titles.py</a></td><td>88</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_titles.py#L 98%"> 98%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/utility_functions.py">utility_functions.py</a></td><td>7</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td colspan="5"><b>src/psnawp_api/utils</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/utils/__init__.py">__init__.py</a></td><td>3</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/utils/endpoints.py">endpoints.py</a></td><td>2</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/utils/misc.py">misc.py</a></td><td>5</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td><b>TOTAL</b></td><td><b>1162</b></td><td><b>108</b></td><td><b>91%</b></td><td>&nbsp;</td></tr></tbody></table></details>
<a href="https://github.com/isFakeAccount/psnawp/blob/main/README.md"><img alt="Coverage" src="https://img.shields.io/badge/Coverage-91%25-brightgreen.svg" /></a><details><summary>Coverage Report </summary><table><tr><th>File</th><th>Stmts</th><th>Miss</th><th>Cover</th><th>Missing</th></tr><tbody><tr><td colspan="5"><b>src/psnawp_api</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/__init__.py">__init__.py</a></td><td>2</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/psnawp.py">psnawp.py</a></td><td>40</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/psnawp.py#L 95%"> 95%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/core</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/__init__.py">__init__.py</a></td><td>4</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/authenticator.py">authenticator.py</a></td><td>129</td><td>19</td><td>19</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/authenticator.py#L 85%"> 85%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/psnawp_exceptions.py">psnawp_exceptions.py</a></td><td>11</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/request_builder.py">request_builder.py</a></td><td>70</td><td>9</td><td>9</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/core/request_builder.py#L 87%"> 87%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/models</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/__init__.py">__init__.py</a></td><td>7</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/client.py">client.py</a></td><td>73</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/client.py#L 97%"> 97%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/game_title.py">game_title.py</a></td><td>26</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/game_title.py#L 92%"> 92%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/group.py">group.py</a></td><td>53</td><td>8</td><td>8</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/group.py#L 85%"> 85%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/search.py">search.py</a></td><td>150</td><td>42</td><td>42</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/search.py#L 72%"> 72%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/title_stats.py">title_stats.py</a></td><td>75</td><td>3</td><td>3</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/title_stats.py#L 96%"> 96%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/user.py">user.py</a></td><td>79</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/user.py#L 97%"> 97%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/models/listing</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/listing/__init__.py">__init__.py</a></td><td>2</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/listing/pagination_iterator.py">pagination_iterator.py</a></td><td>56</td><td>4</td><td>4</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/listing/pagination_iterator.py#L 93%"> 93%</a></td></tr><tr><td colspan="5"><b>src/psnawp_api/models/trophies</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/__init__.py">__init__.py</a></td><td>6</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy.py">trophy.py</a></td><td>130</td><td>9</td><td>9</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy.py#L 93%"> 93%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_constants.py">trophy_constants.py</a></td><td>30</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_group.py">trophy_group.py</a></td><td>92</td><td>3</td><td>3</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_group.py#L 97%"> 97%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_summary.py">trophy_summary.py</a></td><td>27</td><td>1</td><td>1</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_summary.py#L 96%"> 96%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_titles.py">trophy_titles.py</a></td><td>88</td><td>2</td><td>2</td><td><a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/trophy_titles.py#L 98%"> 98%</a></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/models/trophies/utility_functions.py">utility_functions.py</a></td><td>7</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td colspan="5"><b>src/psnawp_api/utils</b></td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/utils/__init__.py">__init__.py</a></td><td>3</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/utils/endpoints.py">endpoints.py</a></td><td>2</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td>&nbsp; &nbsp;<a href="https://github.com/isFakeAccount/psnawp/blob/main/src/psnawp_api/utils/misc.py">misc.py</a></td><td>5</td><td>0</td><td>100%</td><td>&nbsp;</td></tr><tr><td><b>TOTAL</b></td><td><b>1167</b></td><td><b>108</b></td><td><b>91%</b></td><td>&nbsp;</td></tr></tbody></table></details>
<!-- Pytest Coverage Comment:End -->

## How to install
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ python = "^3.9"
attrs = "23.1.0"
requests = "^2.31.0"
typing-extensions = "^4.11.0"
requests-ratelimiter = "^0.7.0"

[tool.poetry.group.typing.dependencies]
mypy = "^1.4.0"
Expand Down
6 changes: 3 additions & 3 deletions pytest-coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ src/psnawp_api/__init__.py 2 0 100%
src/psnawp_api/core/__init__.py 4 0 100%
src/psnawp_api/core/authenticator.py 129 19 85%
src/psnawp_api/core/psnawp_exceptions.py 11 0 100%
src/psnawp_api/core/request_builder.py 65 9 86%
src/psnawp_api/core/request_builder.py 70 9 87%
src/psnawp_api/models/__init__.py 7 0 100%
src/psnawp_api/models/client.py 73 2 97%
src/psnawp_api/models/game_title.py 26 2 92%
Expand All @@ -52,6 +52,6 @@ src/psnawp_api/utils/__init__.py 3 0 100%
src/psnawp_api/utils/endpoints.py 2 0 100%
src/psnawp_api/utils/misc.py 5 0 100%
--------------------------------------------------------------------------
TOTAL 1162 108 91%
TOTAL 1167 108 91%

============================== 72 passed in 3.10s ==============================
============================== 72 passed in 3.70s ==============================
Loading

0 comments on commit 7d22c3c

Please sign in to comment.