Skip to content

Commit 505bc87

Browse files
[CORE-2959] Update carrier reference data (Deu Post and Asendia) (#110)
* Added a new carrier * wip * wip
1 parent 663ddd2 commit 505bc87

7 files changed

Lines changed: 91 additions & 2 deletions

File tree

common/common.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
"os"
1111
"regexp"
1212
"strings"
13+
"io"
1314

1415
"github.com/flowcommerce/tools/util"
16+
"runtime"
1517
)
1618

1719
type Carrier struct {
@@ -290,8 +292,13 @@ func WriteJson(target string, data interface{}) {
290292
os.Exit(1)
291293
}
292294

293-
err = os.Rename(tmp.Name(), target)
294-
util.ExitIfError(err, "Error renaming tmp file")
295+
if runtime.GOOS == "linux" {
296+
err = MoveFile(tmp.Name(), target)
297+
util.ExitIfError(err, "Error moving tmp file")
298+
} else {
299+
err = os.Rename(tmp.Name(), target)
300+
util.ExitIfError(err, "Error renaming tmp file")
301+
}
295302
}
296303

297304
func FormatLocaleId(value string) string {
@@ -374,3 +381,29 @@ func RemapCurrencyCodeToSupported(code string) string {
374381
return newCurrency
375382
}
376383
}
384+
385+
//This method is executed for linux OS
386+
//Reference for this method: https://gist.github.com/var23rav/23ae5d0d4d830aff886c3c970b8f6c6b
387+
func MoveFile(sourcePath, destPath string) error {
388+
inputFile, err := os.Open(sourcePath)
389+
if err != nil {
390+
return fmt.Errorf("Couldn't open source file: %s", err)
391+
}
392+
outputFile, err := os.Create(destPath)
393+
if err != nil {
394+
inputFile.Close()
395+
return fmt.Errorf("Couldn't open dest file: %s", err)
396+
}
397+
defer outputFile.Close()
398+
_, err = io.Copy(outputFile, inputFile)
399+
inputFile.Close()
400+
if err != nil {
401+
return fmt.Errorf("Writing to output file failed: %s", err)
402+
}
403+
// The copy was successful, so now delete the original file
404+
err = os.Remove(sourcePath)
405+
if err != nil {
406+
return fmt.Errorf("Failed removing original file: %s", err)
407+
}
408+
return nil
409+
}

data/cleansed/carrier-services.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"id": "asendia-e-paq-select",
4+
"name": "e-Paq Select",
5+
"carrier_id": "asendia"
6+
},
27
{
38
"id": "asendia-express",
49
"name": "Express",
@@ -39,6 +44,16 @@
3944
"name": "Express",
4045
"carrier_id": "chronopost"
4146
},
47+
{
48+
"id": "deutsche-post-packet-tracked-priority-gpt",
49+
"name": "Packet Tracked Priority GPT",
50+
"carrier_id": "deutsche-post"
51+
},
52+
{
53+
"id": "deutsche-post-usa-direct",
54+
"name": "USA Direct",
55+
"carrier_id": "deutsche-post"
56+
},
4257
{
4358
"id": "dhl-ecommerce-standard",
4459
"name": "Standard",

data/cleansed/carriers.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"name": "Chronopost",
1515
"tracking_url": "https://www.chronopost.fr/en/chrono_suivi_search?listeNumerosLT="
1616
},
17+
{
18+
"id": "deutsche-post",
19+
"name": "Deutsche Post",
20+
"tracking_url": "https://track.aftership.com/deutsch-post/"
21+
},
1722
{
1823
"id": "dhl",
1924
"name": "DHL Express",

data/final/carrier-services.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
[
2+
{
3+
"id": "asendia-e-paq-select",
4+
"name": "e-Paq Select",
5+
"carrier": {
6+
"id": "asendia",
7+
"name": "Asendia",
8+
"tracking_url": "https://track.aftership.com/asendia/"
9+
}
10+
},
211
{
312
"id": "asendia-express",
413
"name": "Express",
@@ -71,6 +80,24 @@
7180
"tracking_url": "https://www.chronopost.fr/en/chrono_suivi_search?listeNumerosLT="
7281
}
7382
},
83+
{
84+
"id": "deutsche-post-packet-tracked-priority-gpt",
85+
"name": "Packet Tracked Priority GPT",
86+
"carrier": {
87+
"id": "deutsche-post",
88+
"name": "Deutsche Post",
89+
"tracking_url": "https://track.aftership.com/deutsch-post/"
90+
}
91+
},
92+
{
93+
"id": "deutsche-post-usa-direct",
94+
"name": "USA Direct",
95+
"carrier": {
96+
"id": "deutsche-post",
97+
"name": "Deutsche Post",
98+
"tracking_url": "https://track.aftership.com/deutsch-post/"
99+
}
100+
},
74101
{
75102
"id": "dhl-ecommerce-standard",
76103
"name": "Standard",

data/final/carriers.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"name": "Chronopost",
1515
"tracking_url": "https://www.chronopost.fr/en/chrono_suivi_search?listeNumerosLT="
1616
},
17+
{
18+
"id": "deutsche-post",
19+
"name": "Deutsche Post",
20+
"tracking_url": "https://track.aftership.com/deutsch-post/"
21+
},
1722
{
1823
"id": "dhl",
1924
"name": "DHL Express",

data/original/carrier-services.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
id,name,carrier_id
2+
asendia-e-paq-select,e-Paq Select,asendia
23
asendia-express,Express,asendia
34
asendia-standard,Standard,asendia
45
canada-post-expedited-parcel,Expedited Parcel,canada-post
@@ -7,6 +8,8 @@ canada-post-regular-parcel,Regular Parcel,canada-post
78
canada-post-xpresspost,Xpresspost,canada-post
89
chronopost-chrono-classic,Classic,chronopost
910
chronopost-chrono-express,Express,chronopost
11+
deutsche-post-packet-tracked-priority-gpt,Packet Tracked Priority GPT,deutsche-post
12+
deutsche-post-usa-direct,USA Direct,deutsche-post
1013
dhl-ecommerce-standard,Standard,dhl-ecommerce
1114
dhl-economy-select,Economy Select,dhl
1215
dhl-express-export-economy,Express Export Economy,dhl

data/original/carriers.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ id,name,tracking_url
22
asendia,Asendia,https://track.aftership.com/asendia/
33
canada-post,Canada Post,https://track.aftership.com/canada-post/
44
chronopost,Chronopost,https://www.chronopost.fr/en/chrono_suivi_search?listeNumerosLT=
5+
deutsche-post,Deutsche Post,https://track.aftership.com/deutsch-post/
56
dhl,DHL Express,http://www.dhl.com/en/express/tracking.html?AWB=
67
dhl-ecommerce,DHL Ecommerce,https://webtrack.dhlglobalmail.com/?trackingnumber=
78
dhl-global-mail,DHL Global Mail,https://webtrack.dhlglobalmail.com/?trackingnumber=

0 commit comments

Comments
 (0)