Skip to content

Commit

Permalink
Move "auto_json" into rest_api_v2_client, the only place where it is …
Browse files Browse the repository at this point in the history
…used
  • Loading branch information
Deconstrained committed Feb 14, 2025
1 parent 396deb4 commit bfd390a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pagerduty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from . rest_api_v2_client import (
RestApiV2Client,
auto_json,
canonical_path,
endpoint_matches,
entity_wrappers,
Expand All @@ -26,7 +27,6 @@
HttpError,
ServerHttpError,
UrlError,
auto_json,
deprecated_kwarg,
http_error_message,
plural_name,
Expand Down
13 changes: 0 additions & 13 deletions pagerduty/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@
### HELPER FUNCTIONS ###
########################

def auto_json(method):
"""
Makes methods return the full response body object after decoding from JSON.
Intended for use on functions that take a URL positional argument followed
by keyword arguments and return a `requests.Response`_ object.
"""
doc = method.__doc__
def call(self, url, **kw):
return try_decoding(successful_response(method(self, url, **kw)))
call.__doc__ = doc
return call

def deprecated_kwarg(deprecated_name: str, details=None, method=None):
"""
Raises a warning if a deprecated keyword argument is used.
Expand Down
14 changes: 13 additions & 1 deletion pagerduty/rest_api_v2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Local
from . api_client import ApiClient, normalize_url
from . common import (
auto_json,
requires_success,
singular_name,
successful_response,
Expand Down Expand Up @@ -651,6 +650,19 @@ def unwrap(response: Response, wrapper) -> Union[dict, list]:
### FUNCTION DECORATORS ###
###########################

def auto_json(method):
"""
Makes methods return the full response body object after decoding from JSON.
Intended for use on functions that take a URL positional argument followed
by keyword arguments and return a `requests.Response`_ object.
"""
doc = method.__doc__
def call(self, url, **kw):
return try_decoding(successful_response(method(self, url, **kw)))
call.__doc__ = doc
return call

def resource_url(method):
"""
API call decorator that allows passing a resource dict as the path/URL
Expand Down

0 comments on commit bfd390a

Please sign in to comment.