quick n dirty mockless ntgvision secrets superslow lookup though
This commit is contained in:
@@ -33,9 +33,70 @@ type ntgVisionJob struct {
|
||||
Weight int `json:"weight"`
|
||||
Equipment string `json:"equip"`
|
||||
Temp string `json:"temp"`
|
||||
jobinfo ntgVisionJobInfo
|
||||
}
|
||||
|
||||
func (ntgJob ntgVisionJob) Job() Job {
|
||||
type ntgVisionJobInfo struct {
|
||||
StopsInfo []struct {
|
||||
StopHours string `json:"stopHours"`
|
||||
AppointmentTime string `json:"appointmentTime"`
|
||||
Instructions string `json:"instructions"`
|
||||
IsDropTrailer bool `json:"isDropTrailer"`
|
||||
} `json:"stopinfos"`
|
||||
PayUpTo float32 `json:"payUpTo"`
|
||||
LoadState string `json:"loadStatus"`
|
||||
CanBidNow bool `json:"canBidNow"`
|
||||
}
|
||||
|
||||
func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
||||
if fmt.Sprint(ntgJob.jobinfo) != fmt.Sprint(ntgVisionJobInfo{}) {
|
||||
return ntgJob.jobinfo, nil
|
||||
}
|
||||
ji, err := ntgJob.jobInfo()
|
||||
if err == ErrNoAuth {
|
||||
if err := NewNTGVision().refreshAuth(); err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
ji, err = ntgJob.jobInfo()
|
||||
}
|
||||
ntgJob.jobinfo = ji
|
||||
return ji, err
|
||||
}
|
||||
|
||||
func (ntgJob *ntgVisionJob) jobInfo() (ntgVisionJobInfo, error) {
|
||||
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf(`https://ntgvision.com/api/v1/load/LoadDetails?loadId=%v`, ntgJob.ID), nil)
|
||||
if err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
setNTGHeaders(request)
|
||||
request.Header.Set("Authorization", "Bearer "+config.Get().Brokers.NTG.Token)
|
||||
resp, err := do(request)
|
||||
if err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
log.Printf("fetch ntg job info %+v: %d: %s", request, resp.StatusCode, b)
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
|
||||
return ntgVisionJobInfo{}, ErrNoAuth
|
||||
}
|
||||
var result ntgVisionJobInfo
|
||||
err = json.Unmarshal(b, &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (ntgJob *ntgVisionJob) Job(info ...bool) Job {
|
||||
if len(info) == 0 || !info[0] {
|
||||
return ntgJob.job(ntgVisionJobInfo{})
|
||||
}
|
||||
jobInfo, err := ntgJob.JobInfo()
|
||||
if err != nil {
|
||||
log.Printf("failed to get jobinfo: %v", err)
|
||||
}
|
||||
return ntgJob.job(jobInfo)
|
||||
}
|
||||
|
||||
func (ntgJob *ntgVisionJob) job(jobInfo ntgVisionJobInfo) Job {
|
||||
pickup, _ := time.ParseInLocation("01/02/06", ntgJob.PickupDate, time.Local)
|
||||
dropoff, _ := time.ParseInLocation("01/02/06", ntgJob.DropoffDate, time.Local)
|
||||
return Job{
|
||||
@@ -53,7 +114,7 @@ func (ntgJob ntgVisionJob) Job() Job {
|
||||
},
|
||||
Miles: ntgJob.Miles,
|
||||
Weight: ntgJob.Weight,
|
||||
Meta: fmt.Sprintf("equipment:%s", ntgJob.Equipment),
|
||||
Meta: fmt.Sprintf("equipment:%s, secrets:%+v", ntgJob.Equipment, jobInfo),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +148,7 @@ func (ntg NTGVision) Search(states []config.State) ([]Job, error) {
|
||||
|
||||
jobs := make([]Job, len(ntgjobs))
|
||||
for i := range jobs {
|
||||
jobs[i] = ntgjobs[i].Job()
|
||||
jobs[i] = ntgjobs[i].Job(true)
|
||||
}
|
||||
return jobs, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user