Repository: airbrake/pybrake

Issue:
Update routes API
- incRequest -> notifyRequest
- statusCode -> status_code
- /api/v4/projects/{}/routes-stats -> /api/v5/projects/{}/routes-stats

Discussion:

Patch:
diff --git a/examples/flask/airbrake_middleware.py b/examples/flask/airbrake_middleware.py
index e53d8d2..24e3ea1 100755
--- a/examples/flask/airbrake_middleware.py
+++ b/examples/flask/airbrake_middleware.py
@@ -24,7 +24,7 @@ def after_request(notifier):
       logger.error("processing time is not valid")
       return response
 
-    notifier.inc_request(
+    notifier.notify_request(
       method=request.method, route=str(request.endpoint),
       status_code=response.status_code, time=now, ms=dur.millisecond,
     )
diff --git a/pybrake/notifier.py b/pybrake/notifier.py
index 4881a73..0c75eb7 100644
--- a/pybrake/notifier.py
+++ b/pybrake/notifier.py
@@ -331,6 +331,5 @@ class Notifier:
       self._thread_pool = futures.ThreadPoolExecutor(max_workers=max_workers)
     return self._thread_pool
 
-  def inc_request(self, method='', route='', status_code=0, time=None, ms=0):
-    self._routes.inc_request(
-      method=method, route=route, status_code=status_code, time=time, ms=ms)
+  def notify_request(self, **kwargs):
+    self._routes.notify_request(**kwargs)
diff --git a/pybrake/routes.py b/pybrake/routes.py
index 02b4def..21a14da 100755
--- a/pybrake/routes.py
+++ b/pybrake/routes.py
@@ -10,7 +10,7 @@ class RouteStat():
   __slots__ = [
     'method',
     'route',
-    'statusCode',
+    'status_code',
     'count',
     'sum',
     'sumsq',
@@ -29,7 +29,7 @@ class RouteStat():
   def __init__(self, method='', route='', status_code=0, time=None):
     self.method = method
     self.route = route
-    self.statusCode = status_code
+    self.status_code = status_code
     self.count = 0
     self.sum = 0
     self.sumsq = 0
@@ -50,7 +50,7 @@ class RouteStats():
       'Content-Type': 'application/json',
       'Authorization': 'Bearer ' + project_key,
     }
-    self._api_url = "{}/api/v4/projects/{}/routes-stats".format(host, project_id)
+    self._api_url = "{}/api/v5/projects/{}/routes-stats".format(host, project_id)
 
     self._thread = None
     self._lock = Lock()
@@ -75,7 +75,7 @@ class RouteStats():
     stats_json = json.dumps({"routes": [stat.__dict__ for _, stat in stats.items()]})
     requests.post(self._api_url, data=stats_json, headers=self._airbrake_headers)
 
-  def inc_request(self, method='', route='', status_code=0, time=None, ms=0):
+  def notify_request(self, method='', route='', status_code=0, time=None, ms=0):
     self._init()
 
     statKey = route_stat_key(method, route, status_code, time)


Test patch:
diff --git a/pybrake/test_routes.py b/pybrake/test_routes.py
index 4709e84..c54c3c0 100644
--- a/pybrake/test_routes.py
+++ b/pybrake/test_routes.py
@@ -13,13 +13,13 @@ def test_route_stat():
   route_stats._flush_period = 1
 
   with requests_mock.mock() as m:
-    url = "http://test.com/api/v4/projects/1/routes-stats"
+    url = "http://test.com/api/v5/projects/1/routes-stats"
     m.post(url, json=_request_callback)
 
     tm = datetime(2000, 1, 1, 0, 0)
-    route_stats.inc_request("GET", "ping", 200, tm, 123)
-    route_stats.inc_request("GET", "pong", 200, tm, 123)
-    route_stats.inc_request("GET", "pong", 200, tm, 123)
+    route_stats.notify_request("GET", "ping", 200, tm, 123)
+    route_stats.notify_request("GET", "pong", 200, tm, 123)
+    route_stats.notify_request("GET", "pong", 200, tm, 123)
 
     route_stats._thread.join()
     assert m.call_count == 1
@@ -34,7 +34,7 @@ def test_route_stat():
     assert route_stats == [{
       'method': 'GET',
       'route': 'ping',
-      'statusCode': 200,
+      'status_code': 200,
       'count': 1,
       'sum': 123,
       'sumsq': 15129,
@@ -43,7 +43,7 @@ def test_route_stat():
     }, {
       'method': 'GET',
       'route': 'pong',
-      'statusCode': 200,
+      'status_code': 200,
       'count': 2,
       'sum': 246,
       'sumsq': 30258,