Skip to content

Commit

Permalink
Merge pull request #122 from Justintime50/smartrate
Browse files Browse the repository at this point in the history
feat(smartrate): adds smartrate functionality
  • Loading branch information
Justintime50 authored May 14, 2021
2 parents 49f656f + 6465137 commit 34bd13f
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 50 deletions.
12 changes: 10 additions & 2 deletions easypost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import json
import platform
import re
import six
import ssl
import time
import types

from six.moves.urllib.parse import urlencode, quote_plus, urlparse
import six
from six.moves.urllib.parse import quote_plus, urlencode, urlparse

from .version import VERSION, VERSION_INFO

Expand Down Expand Up @@ -728,6 +728,14 @@ def get_rates(self):
self.refresh_from(response, api_key)
return self

def get_smartrates(self):
requestor = Requestor(self._api_key)
url = "%s/%s" % (self.instance_url(), "smartrate")

response, api_key = requestor.request('get', url)
self.refresh_from(response, api_key)
return self

def buy(self, **params):
requestor = Requestor(self._api_key)
url = "%s/%s" % (self.instance_url(), "buy")
Expand Down
191 changes: 191 additions & 0 deletions tests/cassettes/test_smartrate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
interactions:
- request:
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
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '976'
Content-type:
- application/x-www-form-urlencoded
authorization:
- EZTK-NONE
user-agent:
- easypost/v2 pythonclient/suppressed
x-client-user-agent:
- suppressed
method: POST
uri: https://api.easypost.com/v2/shipments
response:
body:
string: !!binary |
H4sIAAAAAAAAA+xZS5PTOBD+Ky5fd3DpaUk5MTCwe1golsCFLcqllycGx87KDhAo/vu2nMeEYSZj
YGpSUOQUt1pSq7+vu/X4lNrgde9doft0khJE8D3E72H0guAJohMiXqUnadUVwffL0KSTUtedP0nn
vuv0ue/Syb+fUqtDqHyA/g91s9ABemxEhba2XTZ9UTlotbrgknHsiTDcWFbm1jCsnDIec4GgTUDX
frXwoBzAqsKH0MbhNtOB+GWjTe2Tvk3AIpjinU/WkyaxQ5eUbUiatrn38DRpQ3VeNUk3qxZz3/Rd
ln5+DUO1Lo4Duj0M3C76qm1gGbCKZQi+sas4yfQM2hZ6FfvFto1N00dPzx49Tz+fpC5ap9073Vho
QCAJvvSxP3w2y7o+Sbte90sYOV02b5v2fROXFrR9WzXnhR2MWOstF+4QADICYHRvZ4MT133W39sZ
9mU7T62Fdtn17bwrqqZst7IytHOw3QVQjYsbsNEuFIpJ6wnTQhDJkGXKIUwAGGNzhjk10V/mjbfR
0NNN/5MbCfQHQhOE0hsXeqHY6Hn09iPdrZ61A0y2nS90s7pwbfC+x6DDsEietE1/3s59WCXToSHd
ahDQ4P0seVy3A41s1Ud4p7pJHgeArupsm66RihM+PIWPj9UC/iqGERsmBvaGNS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hDOKR4T/Vm8c
/HnGRyeAw/BjNKE/AfyYaSe4K3NqMVNIKCMx1cwzoozNET9m1T9Q82nGyYiav1Ebgz3Ns/wHjvI/
R+5/Pdy4Q1m9dAveWd0UZRvmO8Fw7gIAw97xdbiIj2BsPtsr78MlxTljBI6NXDLYQ0gGlcVDaOlS
GUK/OEnewX34WciSaR9fPB6EZT3w97prcSxU8jT5SwfThuQs0m93Ib55F1jfhD/3rm1cmzzw2s7S
q2/CEREi/babcPBdFw0tTDT0/nkUH/c2fNktuuLjYDIbomgZmt9vIL/6G4hZrmIS+R3av3Jox2Qf
n3Bex4H85t+3FJsd0NNNqUo//w8AAP//AwDv00GpFx8AAA==
headers:
cache-control:
- no-cache, no-store
content-encoding:
- gzip
content-type:
- application/json; charset=utf-8
etag:
- W/"1541d88e28c3e5183353ef0e5952b194"
expires:
- '0'
location:
- /api/v2/shipments/shp_b5c0915745af42f68daf8416dbadc378
pragma:
- no-cache
referrer-policy:
- strict-origin-when-cross-origin
strict-transport-security:
- max-age=15768000; includeSubDomains; preload
transfer-encoding:
- chunked
x-backend:
- easypost
x-canary:
- direct
x-content-type-options:
- nosniff
x-download-options:
- noopen
x-ep-request-uuid:
- b12f390860999f9fe789f99e000458cf
x-frame-options:
- SAMEORIGIN
x-node:
- bigweb7nuq
x-permitted-cross-domain-policies:
- none
x-proxied:
- intlb2nuq 7ba176609e
- extlb1nuq 7ba176609e
x-request-id:
- 174696e5-4098-4c44-b1ea-65a8cec50451
x-runtime:
- '1.304631'
x-version-label:
- easypost-202105102029-6e7a60b19a-master
x-xss-protection:
- 1; mode=block
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-type:
- application/x-www-form-urlencoded
authorization:
- EZTK-NONE
user-agent:
- easypost/v2 pythonclient/suppressed
x-client-user-agent:
- suppressed
method: GET
uri: https://api.easypost.com/v2/shipments/shp_b5c0915745af42f68daf8416dbadc378/smartrate
response:
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cia/HIHyWwYI+HjTiVGKGnU17
IgtSe6wRFZSmPTONN0UGEa2hsJErWePSPn7IzrXxpU439O9qhEwj5ANOPt/k4801aQTUkAtqlB4L
kFgFAopy0NoGLkAIbgQAeFOmkdesdEtEUBMo3RMP4TmP3wbFK9oYL96cgWonmAucWKAKCWUkEE09
xcpYjlgJRcJrXvgrYxpZGC59ddxnZ14dr3HOzvtz4Zz9++NfAAAA//8DAHy8jJJhGQAA
headers:
cache-control:
- no-cache, no-store
content-encoding:
- gzip
content-type:
- application/json; charset=utf-8
etag:
- W/"f858b3a97b81e649b56017ad96b408b9"
expires:
- '0'
pragma:
- no-cache
referrer-policy:
- strict-origin-when-cross-origin
strict-transport-security:
- max-age=15768000; includeSubDomains; preload
transfer-encoding:
- chunked
x-backend:
- easypost
x-content-type-options:
- nosniff
x-download-options:
- noopen
x-ep-request-uuid:
- b12f390860999fa0e789f99e00045946
x-frame-options:
- SAMEORIGIN
x-node:
- bigweb2nuq
x-permitted-cross-domain-policies:
- none
x-proxied:
- intlb1nuq 7ba176609e
- extlb1nuq 7ba176609e
x-request-id:
- c6f83f52-f7f2-40bd-a54f-92269ab0a987
x-runtime:
- '0.082920'
x-version-label:
- easypost-202105102029-6e7a60b19a-master
x-xss-protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit 34bd13f

Please sign in to comment.