-
Notifications
You must be signed in to change notification settings - Fork 0
/
vevo.go
100 lines (87 loc) · 3.05 KB
/
vevo.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
92
93
94
95
96
97
98
99
100
package vevo
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
"time"
)
const (
jsonURL = "https://www.ecom.immi.gov.au/evo/ws/first-party/json"
)
// VEVO defines the unite information package needed to get a Visa.
type VEVO struct {
n string // visa number
p string // passport number
c string // country
dob time.Time // date of birth
}
// NewVEVO function creates the instance of VEVO. All parameters are mandatory to get a valid response from the server.
// Date of Birth does not have to be precise in the manner of hours or minute - the date is enough.
// Country code is the 3 letter code of the visa issuer country.
// VisaNumber could be one of:
// Visa Grant Number
// Transaction Reference Number
func NewVEVO(dob time.Time, passport, countryCode, visaNumber string) VEVO {
return VEVO{
n: visaNumber,
p: passport,
c: countryCode,
dob: dob,
}
}
// Visa method handles the connection to the immigration department (government) and returns the Visa and/or error.
func (v VEVO) Visa() (Visa, error) {
var visa Visa
resp, err := http.Get(v.prepareURL())
if err != nil {
return visa, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return visa, fmt.Errorf("HTTP call failed: %s", resp.Status)
}
return visa, json.NewDecoder(resp.Body).Decode(&visa)
}
// Visa is the response expected from the immigration server.
type Visa struct {
ClientEvoID string `json:"clientEvoId"`
DateOfEnquiry string `json:"dateOfEnquiry"`
VisaTypeCode string `json:"visaTypeCode"`
Success bool `json:"wsSuccess"`
Error string `json:"wsErrorMessage"`
VisaDescription string `json:"visaDescription"`
PassportNumber string `json:"passportNumber"`
VisaClassSubclass string `json:"visaClassSubclass"`
VisaSubclass string `json:"visaSubclass"`
VisaStream string `json:"visaStream"`
VisaApplicant string `json:"visaApplicant"`
VisaGrantDate string `json:"visaGrantDate"`
VisaExpiryDate string `json:"visaExpiryDate"`
Location string `json:"location"`
VisaStatus string `json:"visaStatus"`
VisaGrantNumber string `json:"visaGrantNumber"`
EntriesAllowed string `json:"entriesAllowed"`
InitialStayDate string `json:"initialStayDate"`
MustNotArriveAfter string `json:"mustNotArriveAfter"`
PeriodOfStay string `json:"periodOfStay"`
EnterBeforeDate string `json:"enterBeforeDate"`
VisaConditions string `json:"visaConditions"`
}
// ------------------------------------------------ PRIVATE METHODS ------------------------------------------------
func (v VEVO) prepareURL() string {
u, _ := url.Parse(jsonURL)
q := u.Query()
q.Add("passport", strings.ToUpper(v.p))
q.Add("country", strings.ToUpper(v.c))
q.Add("dateofbirth", v.dob.Format("20060102"))
vn := strings.ToUpper(v.n)
if strings.HasPrefix(vn, "E") { // with letter E starts Transaction Reference Number
q.Add("trn", vn)
} else { // otherwise it's a Visa Grant Number
q.Add("visagrant", vn)
}
u.RawQuery = q.Encode()
return u.String()
}