-
Notifications
You must be signed in to change notification settings - Fork 0
/
house_request.go
149 lines (122 loc) · 3.9 KB
/
house_request.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2017 Mattias Pernhult. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goiaf
import (
"net/url"
"strconv"
)
// HouseRequest contains method which can be used to filter the response.
type HouseRequest interface {
ParamConverter
// Limit sets the maximum houses to return.
Limit(int) HouseRequest
// Name can be used to filter the returned houses by their name.
Name(string) HouseRequest
// Region sets the value for the region parameter.
// Only houses that belong in the given region are included in the response.
Region(string) HouseRequest
// Words sets the value for the words parameter.
// Only houses that has the given words are included in the response.
Words(string) HouseRequest
// HasWords sets the value for the hasWords parameter.
// Only houses that have words are included in the response.
HasWords(bool) HouseRequest
// HasTitles sets the value for the hasTitles parameter.
// Only houses that have titles are included in the response.
HasTitles(bool) HouseRequest
// HasSeats sets the value for the hasSeats parameter.
// Only houses that have seats are included in the response.
HasSeats(bool) HouseRequest
// HasDiedOut sets the value for the hasDiedOut parameter.
// Only houses that are extinct are included in the response.
HasDiedOut(bool) HouseRequest
// HasAncestralWeapons sets the value for the hasAncestralWeapons parameter.
// Only houses that have ancestral weapons are included in the response.
HasAncestralWeapons(bool) HouseRequest
}
// NewHouseRequest returns a new HouseRequest which can be used to filter houses.
func NewHouseRequest() HouseRequest {
h := houseRequest{}
h.limit = 10
return h
}
type houseRequest struct {
request
name *string
region *string
words *string
hasWords *bool
hasTitles *bool
hasSeats *bool
hasDiedOut *bool
hasAncestralWeapons *bool
}
func (request houseRequest) Limit(value int) HouseRequest {
request.limit = value
return request
}
func (request houseRequest) Convert() url.Values {
params := url.Values{}
params.Add("page", strconv.Itoa(request.limit))
if request.page != nil {
params.Set("pageSize", strconv.Itoa(*request.page))
}
if request.name != nil {
params.Set("name", *request.name)
}
if request.region != nil {
params.Set("region", *request.region)
}
if request.words != nil {
params.Set("words", *request.words)
}
if request.hasWords != nil {
params.Set("hasWords", strconv.FormatBool(*request.hasWords))
}
if request.hasTitles != nil {
params.Set("hasTitles", strconv.FormatBool(*request.hasTitles))
}
if request.hasSeats != nil {
params.Set("hasSeats", strconv.FormatBool(*request.hasSeats))
}
if request.hasDiedOut != nil {
params.Set("hasDiedOut", strconv.FormatBool(*request.hasDiedOut))
}
if request.hasAncestralWeapons != nil {
params.Set("hasAncestralWeapons", strconv.FormatBool(*request.hasAncestralWeapons))
}
return params
}
func (request houseRequest) Name(value string) HouseRequest {
request.name = &value
return request
}
func (request houseRequest) Region(value string) HouseRequest {
request.region = &value
return request
}
func (request houseRequest) Words(value string) HouseRequest {
request.words = &value
return request
}
func (request houseRequest) HasWords(value bool) HouseRequest {
request.hasWords = &value
return request
}
func (request houseRequest) HasTitles(value bool) HouseRequest {
request.hasTitles = &value
return request
}
func (request houseRequest) HasSeats(value bool) HouseRequest {
request.hasSeats = &value
return request
}
func (request houseRequest) HasDiedOut(value bool) HouseRequest {
request.hasDiedOut = &value
return request
}
func (request houseRequest) HasAncestralWeapons(value bool) HouseRequest {
request.hasAncestralWeapons = &value
return request
}