-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/acme-sky/workers/internal/models" | ||
"github.com/charmbracelet/log" | ||
"github.com/tiaguinho/gosoap" | ||
) | ||
|
||
type BookRentResult struct { | ||
Response BookRentResponse `xml:"BookRentResponse"` | ||
} | ||
|
||
type BookRentResponse struct { | ||
Status string `xml:"Status"` | ||
RentId string `xml:"RentId"` | ||
} | ||
|
||
// SOAP call to BookRent action for a selected rent. Returns the call response | ||
// which has a Status and RentId, the latter will be saved on the offer journey | ||
func MakeRentRequest(rent models.Rent, offer models.Offer) (*BookRentResponse, error) { | ||
httpClient := &http.Client{ | ||
Timeout: 1500 * time.Millisecond, | ||
} | ||
soap, err := gosoap.SoapClient(rent.Endpoint, httpClient) | ||
if err != nil { | ||
log.Errorf("SoapClient error: %s", err) | ||
return nil, err | ||
} | ||
|
||
params := gosoap.Params{ | ||
"PickupAddress": *offer.User.Address, | ||
"Address": offer.Journey.Flight1.DepartaureAirport, | ||
"CustomerName": offer.User.Name, | ||
"PickupDate": offer.Journey.Flight1.DepartaureTime.Add(-2 * time.Hour), | ||
} | ||
|
||
res, err := soap.Call("BookRent", params) | ||
if err != nil { | ||
log.Fatalf("Call error: %s", err) | ||
return nil, err | ||
} | ||
|
||
var r BookRentResponse | ||
res.Unmarshal(&r) | ||
|
||
return &r, nil | ||
} |