Skip to content

Commit b361794

Browse files
authored
Merge pull request #201 from hollyabrams/canada-post-custom-workflows
Update Canada Post workflow in build_curls.py; add cURL examples for …
2 parents ed2fa05 + 2385b7a commit b361794

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
curl -X POST https://api.easypost.com/v2/carrier_accounts \
2+
-u "$EASYPOST_API_KEY": \
3+
-H 'Content-Type: application/json' \
4+
-d '{
5+
"carrier_account": {
6+
"type": "CanadaPostAccount",
7+
"payment_mode": "aggregation"
8+
}
9+
}'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
curl -X POST https://api.easypost.com/v2/carrier_accounts \
2+
-u "$EASYPOST_API_KEY": \
3+
-H 'Content-Type: application/json' \
4+
-d '{
5+
"carrier_account": {
6+
"type": "OsmWorldwideV2Account",
7+
"description": "OsmWorldwideV2Account",
8+
"credentials": {
9+
"api_key": "VALUE",
10+
"client_id": "VALUE",
11+
"mailer_id": "VALUE",
12+
"rate_key": "VALUE"
13+
}
14+
}
15+
}'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
curl -X POST https://api.easypost.com/v2/carrier_accounts \
2+
-u "$EASYPOST_API_KEY": \
3+
-H 'Content-Type: application/json' \
4+
-d '{
5+
"carrier_account": {
6+
"type": "UsaExportPbaAccount",
7+
"description": "UsaExportPbaAccount",
8+
"credentials": {
9+
"address_city": "VALUE",
10+
"address_state": "VALUE",
11+
"address_street": "VALUE",
12+
"address_street2": "VALUE",
13+
"address_zip": "VALUE",
14+
"company_name": "VALUE",
15+
"country": "VALUE",
16+
"email": "VALUE",
17+
"name": "VALUE",
18+
"phone": "VALUE"
19+
}
20+
}
21+
}'

tools/build_create_carrier_curl_requests/build_curls.py

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,51 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st
101101
carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'"
102102
carrier_output += END_CHARS
103103
carrier_output = carrier_output.replace(f"{LINE_BREAK_CHARS}{END_CHARS}", f"{END_CHARS}")
104-
# UPS/CanadaPost
105-
elif carrier["type"] in (UPS_CUSTOM_WORKFLOW_CARRIERS + CANADAPOST_CUSTOM_WORKFLOW_CARRIERS):
106-
# TODO: Fix UPS carrier account
107-
# TODO: Fix CanadaPost carrier account
108-
pass
104+
# CanadaPost
105+
elif carrier["type"] in CANADAPOST_CUSTOM_WORKFLOW_CARRIERS:
106+
# BYOA cURL
107+
end = END_CHARS
108+
for top_level in carrier_fields:
109+
if top_level == "custom_workflow":
110+
end += CUSTOM_WORKFLOW_CHARS
111+
else:
112+
top_level_carrier_fields = carrier_fields[top_level]
113+
for item in top_level_carrier_fields:
114+
if carrier_account_json["carrier_account"].get(top_level) is None:
115+
carrier_account_json["carrier_account"][top_level] = {}
116+
carrier_account_json["carrier_account"][top_level][item] = "VALUE"
117+
118+
carrier_output += f" -d '{json.dumps(carrier_account_json, indent=2)}'"
119+
carrier_output += end
120+
carrier_output = carrier_output.replace(f"{LINE_BREAK_CHARS}{END_CHARS}", f"{END_CHARS}")
121+
122+
# Default (aggregation) cURL
123+
default_output = f'# {carrier.get("type")} (EasyPost Aggregation)\n'
124+
default_output = add_curl_line(default_output, carrier)
125+
default_output = add_headers(default_output, carrier)
126+
127+
default_json = {
128+
"carrier_account": {
129+
"type": carrier["type"],
130+
"payment_mode": "aggregation"
131+
}
132+
}
133+
134+
default_output += f" -d '{json.dumps(default_json, indent=2)}'"
135+
default_output += END_CHARS
136+
default_output = default_output.replace(f"{LINE_BREAK_CHARS}{END_CHARS}", f"{END_CHARS}")
137+
138+
output_destination = os.path.join("../", "../", "official", "guides", "create-carrier-curls")
139+
if not os.path.exists(output_destination):
140+
os.makedirs(output_destination)
141+
142+
with open(
143+
os.path.join(output_destination, "canadapost-default.sh"),
144+
"w",
145+
) as default_file:
146+
default_file.write(re.sub(r"^.*?\n", "", default_output))
147+
148+
return carrier_output
109149
# Amazon Shipping
110150
elif carrier["type"] in OAUTH_CUSTOM_WORKFLOW_CARRIERS:
111151
carrier_account_json = {
@@ -141,6 +181,5 @@ def add_credential_structure(carrier_output: str, carrier: dict[str, str]) -> st
141181

142182
return carrier_output
143183

144-
145184
if __name__ == "__main__":
146185
main()

0 commit comments

Comments
 (0)