Skip to content

Commit 38e1db9

Browse files
Retrieve me (#158)
* Add RetrieveMe Convenience Functions * Update CHANGELOG.md Co-authored-by: Justin Hammond <[email protected]> Co-authored-by: Justin Hammond <[email protected]>
1 parent d000bd5 commit 38e1db9

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Removes `_max_timeout` and instead uses a flat 60 second timeout for requests
77
* Adds Python version to user-agent header on requests
88
* Removes `shipment.get_rates()` method since the shipment object already has rates. If you need to get new rates for a shipment, please use the `shipment.regenerate_rates()` method.
9+
* Add `retrieve_me()` convenience function that allow users to retrieve without specifying an ID.
910

1011
### v6.0.0 2021-10-12
1112

easypost/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ def retrieve(cls, easypost_id="", api_key=None, **params):
867867
instance.refresh()
868868
return instance
869869

870+
@classmethod
871+
def retrieve_me(cls, api_key=None, **params):
872+
requestor = Requestor(api_key)
873+
response, api_key = requestor.request("get", cls.class_url())
874+
return convert_to_easypost_object(response, api_key)
875+
870876
@classmethod
871877
def all_api_keys(cls, api_key=None):
872878
requestor = Requestor(api_key)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-type:
12+
- application/json
13+
authorization:
14+
- EZTK-NONE
15+
user-agent:
16+
- easypost/v2 pythonclient/suppressed
17+
x-client-user-agent:
18+
- suppressed
19+
method: GET
20+
uri: https://api.easypost.com/v2/users
21+
response:
22+
body:
23+
string: !!binary |
24+
H4sIAAAAAAAAA9STy27bMBBFf8XQtlYwfItatSi66yILd5MiEPgYRSr0MCgpQBDk3ztyUjdOELdb
25+
c0deDnkP5/Ixa2NWZsuEqVJSKO20tzpYCbGwTFjNnAjGW7A1z7bZ6H9hmKngBxXQfO8SDnO1njEs
26+
XbfNBtcjyd/c9HA9TvPm+mFuxmHztWtp3+Z765NLD5sdTvO0lpOG1bD0nk4rM3UcpN1jausW6eQ5
27+
LbjNQkI3Y6zcej0HZnIQObAdiBJYKeQN1XjXuSGsBuAK1rHekdqA1Z74pqbd92TjRE4YGpfusHL9
28+
uKzaM8eEYRwiea0+2HBcnpuEUzN2xydo3FT5tuva4a7qkfCPSghVjVgl4nj2IMhAxNotHb3hMC1p
29+
df/mor/rp7Use6v17dD2S08yuzqwYe/ajqYR7z8hdWRPHcn3h458/jO/CmNPW0PTdpF6mZU/H19F
30+
wvrAlWMRTK2kLri1hkJihfECoqzhfCT+O1YvqXkJy5euy3cNPd+Ur0GhCLxLSgFAKQF2wPxHUjjk
31+
oHLGdpyVypZgbk55b5+2r5GFdsKqIkStnFSWexajN5LXJgqhubsgZLl+DqVKxc8j10oxU3gQPEgZ
32+
DBaBa8ZqV0jJVLTyspBlSdRcnEdGVhfgOIKqCymYtRqCFgbIMaDBiwm2yTnfMVYyW0p1HlmjRLTK
33+
as+MDCy4KGRBv5i+NnCD9QUhmx1AyYtS2nfIt0+/AQAA//8DACIHgfPTBgAA
34+
headers:
35+
cache-control:
36+
- no-cache, no-store
37+
content-encoding:
38+
- gzip
39+
content-type:
40+
- application/json; charset=utf-8
41+
etag:
42+
- W/"34ca08bedadc1e53373fe4563b1c2ca3"
43+
expires:
44+
- '0'
45+
pragma:
46+
- no-cache
47+
referrer-policy:
48+
- strict-origin-when-cross-origin
49+
strict-transport-security:
50+
- max-age=31536000; includeSubDomains; preload
51+
transfer-encoding:
52+
- chunked
53+
x-backend:
54+
- easypost
55+
x-content-type-options:
56+
- nosniff
57+
x-download-options:
58+
- noopen
59+
x-ep-request-uuid:
60+
- 704d1f6d6217f664ff22b938004b019a
61+
x-frame-options:
62+
- SAMEORIGIN
63+
x-node:
64+
- bigweb9nuq
65+
x-permitted-cross-domain-policies:
66+
- none
67+
x-proxied:
68+
- intlb1nuq 88c34981dc
69+
- extlb2nuq 88c34981dc
70+
x-request-id:
71+
- 5148adca-8a43-46f0-865a-636b9d39e833
72+
x-runtime:
73+
- '0.093758'
74+
x-version-label:
75+
- easypost-202202242013-00973e8608-master
76+
x-xss-protection:
77+
- 1; mode=block
78+
status:
79+
code: 200
80+
message: OK
81+
version: 1

tests/test_user.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
import easypost
66

77

8+
@pytest.mark.vcr()
9+
def test_retrieve_me(prod_api_key):
10+
user = easypost.User.retrieve_me()
11+
12+
assert user.id is not None
13+
14+
815
@pytest.mark.vcr()
916
def test_child_user_create(prod_api_key):
1017
# Create an address and then verify some fields to test whether it was created just fine.

0 commit comments

Comments
 (0)