Skip to content

Commit

Permalink
feat: request cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gratcliff committed Sep 15, 2023
1 parent 043d528 commit ed3c0a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
api_key=os.getenv("README_API_KEY"),
grouping_function="metrics.views.grouping_function",
background_worker_mode=False,
base_log_url="https://docs.readme.com"
# base_log_url="https://example.com",
buffer_length=1,
timeout=5,
)
16 changes: 11 additions & 5 deletions packages/python/readme_metrics/GetProjectBaseUrl.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import requests, base64

from functools import lru_cache
from urllib.parse import urljoin


def auth(readme_api_key: str):
encodedAuth = base64.b64encode("%s:" % readme_api_key)
encodedAuth = base64.b64encode(f"{readme_api_key}:")
return {"Authorization": "Basic %s" % encodedAuth}


@lru_cache(maxsize = 512)
@lru_cache(maxsize=None)
def get_project_base_url(readme_api_url: str, readme_api_key: str):
url = "%s/v1" % readme_api_url

url = urljoin(readme_api_url, "/v1")
headers = auth(readme_api_key)

project = requests.get(url, headers=headers).json()
return project.baseUrl
try:
response = requests.get(url, headers=headers, timeout=1)
response.raise_for_status()
return response.baseUrl
except:
return ""

2 changes: 1 addition & 1 deletion test/integration-metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('Metrics SDK Integration Tests', function () {
expect(response.content.mimeType).toMatch(/application\/json(;\s?charset=utf-8)?/);
});

it.only('should include an _id UUID in har payload', async function () {
it('should include an _id UUID in har payload', async function () {
await fetch(`http://localhost:${PORT}`, { method: 'get' });

const [, body] = await getRequest();
Expand Down

0 comments on commit ed3c0a2

Please sign in to comment.