diff --git a/broker/fastexact.go b/broker/fastexact.go index dd1a77d..8723322 100644 --- a/broker/fastexact.go +++ b/broker/fastexact.go @@ -107,7 +107,20 @@ func (fe FastExact) searchOne(state config.State) ([]Job, error) { } func (fe FastExact) newRequest(state config.State) (*http.Request, error) { - return nil, errors.New("not impl: fe.newreq") + zip, ok := config.States[state] + if !ok { + return nil, fmt.Errorf("no configured zip for %s", state) + } + req, err := http.NewRequest( + http.MethodGet, + "https://www.fastexact.com/secure/index.php?page=ajaxListJobs&action=ajax&zipcode="+zip+"&records_per_page=50&distance=300&st_loc_zip=8", + nil, + ) + if err != nil { + return nil, err + } + fe.setHeaders(req) + return req, nil } func (fe FastExact) doRequest(req *http.Request) (*http.Response, error) { @@ -121,20 +134,43 @@ func (fe FastExact) parse(resp *http.Response) ([]Job, error) { type mockFastExactDoer struct{} func (mock mockFastExactDoer) doRequest(req *http.Request) (*http.Response, error) { - switch req.URL.Path { - case "/secure/index.php": - if req.URL.Query().Get("page") != "userLogin" { - return nil, errors.New("bad query") - } + if req.URL.Path != "/secure/index.php" { + return nil, errors.New("bad path") + } + switch req.URL.Query().Get("page") { + case "userLogin": if b, _ := ioutil.ReadAll(req.Body); !bytes.Equal(b, []byte(`user_name=u&user_password=p&buttonSubmit=Login`)) { return nil, errors.New("bad req body") } return &http.Response{ Status: http.StatusText(http.StatusOK), StatusCode: http.StatusOK, - Header: http.Header{"Set-Cookie": []string{"PHPSESSID=8o0slo18q6cr0v5v5k9ohjcg01; path=/"}}, + Header: http.Header{"Set-Cookie": []string{"PHPSESSID=SessionFromLogin; path=/"}}, Body: io.NopCloser(bytes.NewReader([]byte{})), }, nil + case "ajaxListJobs": + if req.URL.Query().Get("action") != "ajax" { + return nil, errors.New("bad query: action should be ajax") + } + if req.URL.Query().Get("records_per_page") != "50" { + return nil, errors.New("bad query: records_per_page should be 50") + } + if req.URL.Query().Get("distance") != "300" { + return nil, errors.New("bad query: distance should be 300") + } + if req.URL.Query().Get("zipcode") == "" { + return nil, errors.New("bad query: zip code empty") + } + b, err := ioutil.ReadFile("./testdata/fastexact_search.xml") + if err != nil { + return nil, err + } + return &http.Response{ + Status: http.StatusText(http.StatusOK), + StatusCode: http.StatusOK, + Header: http.Header{"Set-Cookie": []string{"PHPSESSID=SessionFromSearch; path=/"}}, + Body: io.NopCloser(bytes.NewReader(b)), + }, nil } - return nil, errors.New("bad path") + return nil, errors.New("bad query") } diff --git a/broker/testdata/fastexact_search.sh b/broker/testdata/fastexact_search.sh index 4c9a71d..1da8df8 100644 --- a/broker/testdata/fastexact_search.sh +++ b/broker/testdata/fastexact_search.sh @@ -6,5 +6,5 @@ curl -sS \ -H 'Accept-Language: en-US,en;q=0.5' \ -H 'Accept-Encoding: gzip, deflate, br' \ -H 'Content-Type: application/x-www-form-urlencoded' \ - -H 'Cookie: PHPSESSID=36n1p1rrp5e2ad5ms0qvhp37m1' \ + -H 'Cookie: PHPSESSID=vq4ss3lbfg0viluaau7e0d32q6' \ | gzip -d diff --git a/broker/testdata/fastexact_search.xml b/broker/testdata/fastexact_search.xml new file mode 100644 index 0000000..a26fa9e --- /dev/null +++ b/broker/testdata/fastexact_search.xml @@ -0,0 +1,218 @@ +
+ + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID   Origin   Destination   Mile   Pieces / Weight   Dimension Vehicle Size Pickup (EST)   View
Z-5344222Circleville, OH 43113Willard, OH 448901284 / 480096x48x88in.SMALL STRAIGHT31-Jan-2022 17:00:00 +
Z-5344003WASHINGTON, DCWINSTON SALEM, NC3322 / 300078x35x99 in.LARGE STRAIGHT31-Jan-2022 08:00:00 +
Z-5344092Winchester, VA 22603Milwaukee, WI 532217284 / 2195NO DIMENSIONS SPECIFIEDVAN30-Jan-2022 15:00:00 +
Z-5344035ATLANTA, GA 30301BURNSVILLE, MN 55337109810 / 600048x40x40 in.LARGE STRAIGHT29-Jan-2022 08:00:00 +
Z-5344518Hamlet, NC 28345East Windsor, CT 060887201 / 50054x36x24in.CARGO VAN28-Jan-2022 13:00:00 +
X-5344304MOUNT PLEASANT, PA 15666MIAMI, FL 33178-105611560 / 5000.0048Inches x 48Inches x Straight Truck 20-24 ft28-Jan-2022 13:00:00 +
Z-5344061Chesapeake, VA 23321Fort Wayne, IN 468187270 / 5000NO DIMENSIONS SPECIFIEDLARGE STRAIGHT28-Jan-2022 13:00:00 +
B-5344514MAXTON, NC 28364PEMBINA, ND 5827116377 / 280007@54x96x4028-Jan-2022 12:00:00 +
Z-5344114Durham, NC 27703Cumming, GA 300403686 / 320048x40x48in.LARGE STRAIGHT28-Jan-2022 12:00:00 +
Z-5344231Durham, NC 27702Cumming, GA 300403666 / 320048x40x48in.LARGE STRAIGHT28-Jan-2022 12:00:00 +
+
+
+
+ + + + + + + + +
Details Found: 81Page 1 of 9
+ + Next » +
+ + + + + + +
Records Per Page: 
+ +