Skip to content

Commit 34bd13f

Browse files
authored
Merge pull request #122 from Justintime50/smartrate
feat(smartrate): adds smartrate functionality
2 parents 49f656f + 6465137 commit 34bd13f

File tree

3 files changed

+297
-50
lines changed

3 files changed

+297
-50
lines changed

easypost/__init__.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import json
33
import platform
44
import re
5-
import six
65
import ssl
76
import time
87
import types
98

10-
from six.moves.urllib.parse import urlencode, quote_plus, urlparse
9+
import six
10+
from six.moves.urllib.parse import quote_plus, urlencode, urlparse
1111

1212
from .version import VERSION, VERSION_INFO
1313

@@ -728,6 +728,14 @@ def get_rates(self):
728728
self.refresh_from(response, api_key)
729729
return self
730730

731+
def get_smartrates(self):
732+
requestor = Requestor(self._api_key)
733+
url = "%s/%s" % (self.instance_url(), "smartrate")
734+
735+
response, api_key = requestor.request('get', url)
736+
self.refresh_from(response, api_key)
737+
return self
738+
731739
def buy(self, **params):
732740
requestor = Requestor(self._api_key)
733741
url = "%s/%s" % (self.instance_url(), "buy")

tests/cassettes/test_smartrate.yaml

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
interactions:
2+
- request:
3+
body: shipment%5Bfrom_address%5D%5Bcity%5D=San+Francisco&shipment%5Bfrom_address%5D%5Bcountry%5D=US&shipment%5Bfrom_address%5D%5Bemail%5D=support%40easypost.com&shipment%5Bfrom_address%5D%5Bname%5D=EasyPost&shipment%5Bfrom_address%5D%5Bphone%5D=4153334444&shipment%5Bfrom_address%5D%5Bstate%5D=CA&shipment%5Bfrom_address%5D%5Bstreet1%5D=417+Montgomery+Street&shipment%5Bfrom_address%5D%5Bstreet2%5D=5th+Floor&shipment%5Bfrom_address%5D%5Bzip%5D=94104&shipment%5Bparcel%5D%5Bheight%5D=5&shipment%5Bparcel%5D%5Blength%5D=20.2&shipment%5Bparcel%5D%5Bweight%5D=65.9&shipment%5Bparcel%5D%5Bwidth%5D=10.9&shipment%5Bto_address%5D%5Bcity%5D=Redondo+Beach&shipment%5Bto_address%5D%5Bcountry%5D=US&shipment%5Bto_address%5D%5Bemail%5D=dr_steve_brule%40gmail.com&shipment%5Bto_address%5D%5Bname%5D=Dr.+Steve+Brule&shipment%5Bto_address%5D%5Bphone%5D=4153334444&shipment%5Bto_address%5D%5Bstate%5D=CA&shipment%5Bto_address%5D%5Bstreet1%5D=179+N+Harbor+Dr&shipment%5Bto_address%5D%5Bzip%5D=90277
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Connection:
10+
- keep-alive
11+
Content-Length:
12+
- '976'
13+
Content-type:
14+
- application/x-www-form-urlencoded
15+
authorization:
16+
- EZTK-NONE
17+
user-agent:
18+
- easypost/v2 pythonclient/suppressed
19+
x-client-user-agent:
20+
- suppressed
21+
method: POST
22+
uri: https://api.easypost.com/v2/shipments
23+
response:
24+
body:
25+
string: !!binary |
26+
H4sIAAAAAAAAA+xZS5PTOBD+Ky5fd3DpaUk5MTCwe1golsCFLcqllycGx87KDhAo/vu2nMeEYSZj
27+
YGpSUOQUt1pSq7+vu/X4lNrgde9doft0khJE8D3E72H0guAJohMiXqUnadUVwffL0KSTUtedP0nn
28+
vuv0ue/Syb+fUqtDqHyA/g91s9ABemxEhba2XTZ9UTlotbrgknHsiTDcWFbm1jCsnDIec4GgTUDX
29+
frXwoBzAqsKH0MbhNtOB+GWjTe2Tvk3AIpjinU/WkyaxQ5eUbUiatrn38DRpQ3VeNUk3qxZz3/Rd
30+
ln5+DUO1Lo4Duj0M3C76qm1gGbCKZQi+sas4yfQM2hZ6FfvFto1N00dPzx49Tz+fpC5ap9073Vho
31+
QCAJvvSxP3w2y7o+Sbte90sYOV02b5v2fROXFrR9WzXnhR2MWOstF+4QADICYHRvZ4MT133W39sZ
32+
9mU7T62Fdtn17bwrqqZst7IytHOw3QVQjYsbsNEuFIpJ6wnTQhDJkGXKIUwAGGNzhjk10V/mjbfR
33+
0NNN/5MbCfQHQhOE0hsXeqHY6Hn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j77HDueFS
47+
HGP3/mcAw92BuGcZHbF336qNi/pvSP2/BO6lRjmThBNnIcx5KbUnGjHBGKQB2OUdNfVPNTjkegIo
48+
mZEReX+rNooAiGU4v520/6MMuKO0Lz0RWBIFR3bFcqy1LXOBhciNwBh7c1QGHIh+hDOKR4T/Vm8c
49+
/HnGRyeAw/BjNKE/AfyYaSe4K3NqMVNIKCMx1cwzoozNET9m1T9Q82nGyYiav1Ebgz3Ns/wHjvI/
50+
R+5/Pdy4Q1m9dAveWd0UZRvmO8Fw7gIAw97xdbiIj2BsPtsr78MlxTljBI6NXDLYQ0gGlcVDaOlS
51+
GUK/OEnewX34WciSaR9fPB6EZT3w97prcSxU8jT5SwfThuQs0m93Ib55F1jfhD/3rm1cmzzw2s7S
52+
q2/CEREi/babcPBdFw0tTDT0/nkUH/c2fNktuuLjYDIbomgZmt9vIL/6G4hZrmIS+R3av3Jox2Qf
53+
n3Bex4H85t+3FJsd0NNNqUo//w8AAP//AwDv00GpFx8AAA==
54+
headers:
55+
cache-control:
56+
- no-cache, no-store
57+
content-encoding:
58+
- gzip
59+
content-type:
60+
- application/json; charset=utf-8
61+
etag:
62+
- W/"1541d88e28c3e5183353ef0e5952b194"
63+
expires:
64+
- '0'
65+
location:
66+
- /api/v2/shipments/shp_b5c0915745af42f68daf8416dbadc378
67+
pragma:
68+
- no-cache
69+
referrer-policy:
70+
- strict-origin-when-cross-origin
71+
strict-transport-security:
72+
- max-age=15768000; includeSubDomains; preload
73+
transfer-encoding:
74+
- chunked
75+
x-backend:
76+
- easypost
77+
x-canary:
78+
- direct
79+
x-content-type-options:
80+
- nosniff
81+
x-download-options:
82+
- noopen
83+
x-ep-request-uuid:
84+
- b12f390860999f9fe789f99e000458cf
85+
x-frame-options:
86+
- SAMEORIGIN
87+
x-node:
88+
- bigweb7nuq
89+
x-permitted-cross-domain-policies:
90+
- none
91+
x-proxied:
92+
- intlb2nuq 7ba176609e
93+
- extlb1nuq 7ba176609e
94+
x-request-id:
95+
- 174696e5-4098-4c44-b1ea-65a8cec50451
96+
x-runtime:
97+
- '1.304631'
98+
x-version-label:
99+
- easypost-202105102029-6e7a60b19a-master
100+
x-xss-protection:
101+
- 1; mode=block
102+
status:
103+
code: 201
104+
message: Created
105+
- request:
106+
body: null
107+
headers:
108+
Accept:
109+
- '*/*'
110+
Accept-Encoding:
111+
- gzip, deflate
112+
Connection:
113+
- keep-alive
114+
Content-type:
115+
- application/x-www-form-urlencoded
116+
authorization:
117+
- EZTK-NONE
118+
user-agent:
119+
- easypost/v2 pythonclient/suppressed
120+
x-client-user-agent:
121+
- suppressed
122+
method: GET
123+
uri: https://api.easypost.com/v2/shipments/shp_b5c0915745af42f68daf8416dbadc378/smartrate
124+
response:
125+
body:
126+
string: !!binary |
127+
H4sIAAAAAAAAA+zYXW/bNhQG4P+ia1fg4Td1V6zFbrahm7ObDoPAz0WF4niUXNQI8t9H2Q5sh8JG
128+
pHUHdwNyk6NXtGQ94NHxQxX9sOnHqvntobI6xs7Hqql+Xb5bVounQqutvd+sxrZz6ZjV7Z8r/vN3
129+
PLgpEr0evWt1WqLCCMMrxF4BusHQINJg+X7KbGL0K7vdLfwmFZzvu48+bluXzq2a1abvnxXbPzY6
130+
6tXoffrIoPvBnwW2w9NZfhjb2QO7a43TUs4wgTjzNHhHAwETFGdWMqNdkBJNd9F3aZnsMnfVuLtE
131+
imvBFtXdvUv/VGP61HT83nzwdrrvX6bMojqLRj/qrs8XPdQPWVXTlB18/NjZaeW3n9bpgQwpN9x2
132+
6zv/9KUPt+vWMIsUMEGZDhQHLp0OkgJ36UYsETKdNHZ3vu1W7Zi+u6FLl/ZQrX20aZmu9y1DVYMX
133+
pxXBnldkqpCzikJZJWXoeUVUDTuvqKoRj4tqs3b/4ONxcW3y8Cw7fGoOCw1AKbPBeWqFMII6obBB
134+
2jHnZSgxp2pGysjtk0XiANdn4N7F7j524/Zy4qBAHH6ROJqJ49+oODYrjp3tcsC08FwzSjgVWmiG
135+
JfPSagRIICnKxGFZKm5KFonbR0/E6fTI+qXvp2W/4j7HMnU8UyczdQAZO8CZO5Avgfe37qK8/aFX
136+
H5ZfyN3xPHKDSYNQ+nv/PFYgkcxKJKcSuSDcWGcksoQaaaTFShutlBLcck5KJGJeq0KKmNWi1OIh
137+
e8RI3ujtpSm+bAPEGUWcSSQZRHI9DuEGyZc7hFmHcOqQKiwsABGeMCqtNzuX1Km0PVqXnkyBQyCy
138+
5mUOgZCaFLfhQ/go8Sf/aUwYX3fxrY799vWPlwO570HPTGZFOVdUc6er2aSYK6p98XqU4s/aLQve
139+
FBFzSkqmlEWGSuM0wUhSFgKmQTBqi6YTVDNVppSImtFCpIfs0SheuT3R/3X+V3TKkJ6gEGlOBuoV
140+
KEw08h4ccMOkKJqdgRT3cqA1KZ2dD9mjzu9j+tLd1+zj8IX6eP5Cia/HIHyWwYI+HjTiVGKGnU17
141+
IgtSe6wRFZSmPTONN0UGEa2hsJErWePSPn7IzrXxpU439O9qhEwj5ANOPt/k4801aQTUkAtqlB4L
142+
kFgFAopy0NoGLkAIbgQAeFOmkdesdEtEUBMo3RMP4TmP3wbFK9oYL96cgWonmAucWKAKCWUkEE09
143+
xcpYjlgJRcJrXvgrYxpZGC59ddxnZ14dr3HOzvtz4Zz9++NfAAAA//8DAHy8jJJhGQAA
144+
headers:
145+
cache-control:
146+
- no-cache, no-store
147+
content-encoding:
148+
- gzip
149+
content-type:
150+
- application/json; charset=utf-8
151+
etag:
152+
- W/"f858b3a97b81e649b56017ad96b408b9"
153+
expires:
154+
- '0'
155+
pragma:
156+
- no-cache
157+
referrer-policy:
158+
- strict-origin-when-cross-origin
159+
strict-transport-security:
160+
- max-age=15768000; includeSubDomains; preload
161+
transfer-encoding:
162+
- chunked
163+
x-backend:
164+
- easypost
165+
x-content-type-options:
166+
- nosniff
167+
x-download-options:
168+
- noopen
169+
x-ep-request-uuid:
170+
- b12f390860999fa0e789f99e00045946
171+
x-frame-options:
172+
- SAMEORIGIN
173+
x-node:
174+
- bigweb2nuq
175+
x-permitted-cross-domain-policies:
176+
- none
177+
x-proxied:
178+
- intlb1nuq 7ba176609e
179+
- extlb1nuq 7ba176609e
180+
x-request-id:
181+
- c6f83f52-f7f2-40bd-a54f-92269ab0a987
182+
x-runtime:
183+
- '0.082920'
184+
x-version-label:
185+
- easypost-202105102029-6e7a60b19a-master
186+
x-xss-protection:
187+
- 1; mode=block
188+
status:
189+
code: 200
190+
message: OK
191+
version: 1

0 commit comments

Comments
 (0)