Skip to content

Commit 29fe98a

Browse files
authored
Merge pull request coinbase#85 from JohnLZeller/zeller/issue-83-fix
Retrieve resource_path from response and apply to APIObject
2 parents a75cae3 + 5c99570 commit 29fe98a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

coinbase/wallet/compat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
if six.PY2:
44
from itertools import imap
55
from urllib import quote
6-
from urlparse import urljoin
6+
from urlparse import urljoin, urlsplit
77
from urlparse import urlparse
88
elif six.PY3:
99
imap = map
1010
from urllib.parse import quote
11-
from urllib.parse import urljoin
11+
from urllib.parse import urljoin, urlsplit
1212
from urllib.parse import urlparse

coinbase/wallet/model.py

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import json
88
import six
99

10+
from coinbase.wallet.compat import urlsplit
11+
1012

1113
def new_api_object(client, obj, cls=None, **kwargs):
1214
if isinstance(obj, dict):
@@ -38,12 +40,15 @@ class APIObject(dict):
3840
the appropriate Python models.
3941
"""
4042
__api_client = None
43+
__resource_path = None
4144
__response = None
4245
__pagination = None
4346
__warnings = None
4447

4548
def __init__(self, api_client, response=None, pagination=None, warnings=None):
4649
self.__api_client = api_client
50+
if response:
51+
self.__resource_path = urlsplit(response.url).path
4752
self.__response = response
4853
self.__pagination = pagination
4954
self.__warnings = warnings
@@ -52,6 +57,10 @@ def __init__(self, api_client, response=None, pagination=None, warnings=None):
5257
def api_client(self):
5358
return self.__api_client
5459

60+
@property
61+
def resource_path(self):
62+
return self.__resource_path
63+
5564
@property
5665
def response(self):
5766
return self.__response

tests/test_api_object.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import copy
88
import json
9+
from requests.models import Response
910
import six
1011
import unittest2
1112
import warnings
@@ -54,7 +55,7 @@ def api_client(x): return x
5455
self.assertIsNone(obj.pagination)
5556
self.assertIsNone(obj.warnings)
5657

57-
def response(x): return x
58+
response = Response()
5859

5960
def pagination(x): return x
6061

0 commit comments

Comments
 (0)