-
Notifications
You must be signed in to change notification settings - Fork 1
/
southwest.go
91 lines (77 loc) · 2.06 KB
/
southwest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"strings"
)
//Southwest structure
type Southwest struct {
FirstName string
LastName string
ConfirmationNumber string
Url string
}
func NewSouthwest(firstName string, lastName string,
confirmationNumber string,
url string) *Southwest {
southwest := Southwest{FirstName: firstName, LastName: lastName, ConfirmationNumber: confirmationNumber, Url: url}
return &southwest
}
func (s *Southwest) CheckIn() error {
//Create x-www-form-url-encoded
// URL package
v := url.Values{}
v.Set("platform", "android")
v.Set("firstName", s.FirstName)
v.Set("lastName", s.LastName)
v.Set("recordLocator", s.ConfirmationNumber)
v.Set("serviceID", "flightcheckin_new")
v.Set("appID", "swa")
v.Set("appver", "2.24.0")
v.Set("platformver", "5.0.GA_v201403042054")
v.Set("channel", "rc")
req, err := http.NewRequest("POST", s.Url, strings.NewReader(v.Encode()))
if err != nil {
log.Panic(err)
return err
}
req.Header.Add("Content-type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Panic(err)
return err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Panic(err)
return err
}
fmt.Printf("Status code: %s\n", resp.StatusCode)
fmt.Printf("Body: %s\n", string(body))
return nil
}
func main() {
var firstName string
var lastName string
var confirmationNumber string
url := "http://mobile.southwest.com/middleware/MWServlet"
flag.StringVar(&firstName, "firstName", "", "First name for check in")
flag.StringVar(&lastName, "lastName", "", "Last name for check in")
flag.StringVar(&confirmationNumber, "confirmationNumber", "", "Confirmation Number for check in")
flag.Parse()
if firstName == "" || lastName == "" || confirmationNumber == "" {
log.Panic("Please ensure first name, last name and confirmation number are filled out")
os.Exit(1)
}
s := NewSouthwest(firstName, lastName, confirmationNumber, url)
err := s.CheckIn()
if err != nil {
log.Panic(err)
os.Exit(1)
}
}