-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-FreeBurritos.ps1
More file actions
334 lines (303 loc) · 13.7 KB
/
Get-FreeBurritos.ps1
File metadata and controls
334 lines (303 loc) · 13.7 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
function get-FreeBurritos {
[cmdletbinding(DefaultParameterSetName='byQuestions')]
Param(
[Parameter(Mandatory=$True,ParameterSetName='byanswerfile')]
[ValidateScript({test-path $_})]
[String]$answerfile,
[Parameter(Mandatory=$True,
HelpMessage='Enter Receipt code with no spaces, numbers only')]
[ValidatePattern({^\d{20,20}$})]
[String]$ReceiptCode,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='How satisfied are you with your overall experience at Chipotle?'
)]
[ValidateSet('1','2','3','4','5')]
[String]$OverallExperience,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='What is the primary reason for the score you just gave?')]
[String]$ReasonForScore,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='How likely are you to recommend Chipotle to a friend or colleague? '
)]
[ValidateSet('1','2','3','4','5')]
[String]$LikelihoodtoReturnwithin30Days,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='What type of experience did you have?'
)]
[ValidateSet('Dine-In','Carry-Out','Catering','Delivery')]
[String]$ExperienceType,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='How did you place your order?'
)]
[ValidateSet('In-Person','Chipotle.com','Chipotle app','Delivery app','Other')]
[String]$OrderType,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Ease of Placing your Order'
)]
[ValidateSet('1','2','3','4','5')]
[String]$EaseofPlacingOrder,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Speed of Service'
)]
[ValidateSet('1','2','3','4','5')]
[String]$SpeedofService,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Taste of your food'
)]
[ValidateSet('1','2','3','4','5')]
[String]$TasteofFood,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Friendliness of our staff'
)]
[ValidateSet('1','2','3','4','5')]
[String]$FriendlinessofStaff,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Cleanliness of the Restaurant'
)]
[ValidateSet('1','2','3','4','5')]
[String]$CleanlinessofRestaurant,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Describe the amount of food in your entree'
)]
[ValidateSet('Less than I wanted','Just What I wanted','More than I wanted')]
[String]$FoodQuantity,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Was your order assembled to your liking?'
)]
[ValidateSet('yes','no')]
[String]$OrderAssembledtoyourLiking,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Was the restaurant environment pleasant?'
)]
[ValidateSet('yes','no')]
[String]$RestaurantEnvironmentPleasant,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Were any food items unavailable when you ordered/received your meal?'
)]
[ValidateSet('yes','no')]
[String]$FoodItemsUnavailable,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Did you experience a problem on your visit?'
)]
[ValidateSet('yes','no')]
[String]$ExperiencedProblem,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Was your order accurate?'
)]
[ValidateSet('yes','no')]
[String]$AccurateOrder,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Including this visit how many times have you ordered from Chipotle in the last 6 months?'
)]
[ValidateSet('First visit','1','2-3','4-5','6+')]
[String]$OrdersinLast6Months,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Please indicate your age group.'
)]
[ValidateSet('Under 18','18-24','25-34','35-49','50-64','65 and older','Prefer not to answer')]
[String]$AgeGroup,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Would you like to enter our sweepstakes?'
)]
[ValidateSet('yes','no')]
[String]$EnterSweepstakes,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='First Name'
)]
[String]$FirstName,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Last Name'
)]
[String]$LastName,
[Parameter(Mandatory=$True,
ParameterSetName='byQuestions',
HelpMessage='Email Address'
)]
[String]$EmailAddress,
[Parameter(ParameterSetName='byQuestions')]
[Switch]$ExportAnswerFile
)
$formattedReceiptCode = $ReceiptCode.insert(3,' ').insert(7,' ').insert(11,' ').insert(15,' ').insert(19,' ').insert(23,' ')
if ($answerfile){
$formdata = get-content $answerfile | convertfrom-json
$formdata[0].spl_q_chipotle_receipt_code_txt = $formattedReceiptCode
} else {
#start with sample form data and modify values based on parameters
$formdata = get-content "$PSScriptRoot\sampleformdata.json" | convertfrom-json
$formdata[0].spl_q_chipotle_receipt_code_txt = $formattedReceiptCode
$formdata[1].onf_q_chipotle_overall_experience_5ptscale = $OverallExperience
$formdata[1].spl_q_chipotle_reason_for_score_cmt = $ReasonForScore
$formdata[1].onf_q_chipotle_likelihood_to_return_30_days_5pt_ltrscale = $LikelihoodtoReturnwithin30Days
Switch ($ExperienceType){
'Dine-In' {$formdata[2].onf_q_chipotle_experience_type_alt = '10'}
'Carry-Out' {$formdata[2].onf_q_chipotle_experience_type_alt = '20'}
'Catering' {$formdata[2].onf_q_chipotle_experience_type_alt = '30'}
'Delivery' {$formdata[2].onf_q_chipotle_experience_type_alt = '40'}
}
Switch ($OrderType){
'In-Person' {$formdata[2].onf_q_chipotle_order_medium_alt = '10'}
'Chipotle.com' {$formdata[2].onf_q_chipotle_order_medium_alt = '20'}
'Chipotle app' {$formdata[2].onf_q_chipotle_order_medium_alt = '30'}
'Delivery app' {$formdata[2].onf_q_chipotle_order_medium_alt = '40'}
'Other' {$formdata[2].onf_q_chipotle_order_medium_alt = '50'}
}
$formdata[3].onf_q_chipotle_taste_of_food_5pt_sat_scale = $TasteofFood
$formdata[3].onf_q_chipotle_cleanliness_of_restaurant_5pt_sat_scale = $CleanlinessofRestaurant
$formdata[3].onf_q_chipotle_ease_of_placing_order_5pt_sat_scale = $EaseofPlacingOrder
$formdata[3].onf_q_chipotle_speed_of_service_5pt_sat_scale = $SpeedofService
$formdata[3].onf_q_chipotle_friendliness_of_staff_5pt_sat_scale = $FriendlinessofStaff
Switch ($FoodQuantity) {
'Less than I wanted' {$formdata[4].onf_q_chipotle_food_quantity_received_alt = '10'}
'Just What I wanted' {$formdata[4].onf_q_chipotle_food_quantity_received_alt = '20'}
'More than I wanted' {$formdata[4].onf_q_chipotle_food_quantity_received_alt = '30'}
}
Switch ($OrderAssembledtoyourLiking){
'yes' {$formdata[4].onf_q_chipotle_order_assembled_liking_yn = '1'}
'no' {$formdata[4].onf_q_chipotle_order_assembled_liking_yn = '2'}
}
Switch ($RestaurantEnvironmentPleasant){
'yes' {$formdata[4].onf_q_chipotle_restaurant_environment_yn = '1'}
'no' {$formdata[4].onf_q_chipotle_restaurant_environment_yn = '2'}
}
Switch ($FoodItemsUnavailable){
'yes' {$formdata[5].onf_q_chipotle_food_item_unavailable_yn = '1'}
'no' {$formdata[5].onf_q_chipotle_food_item_unavailable_yn = '2'}
}
Switch ($ExperiencedProblem){
'yes' {$formdata[5].onf_q_chipotle_experienced_problem_on_visit_yn = '1'}
'no' {$formdata[5].onf_q_chipotle_experienced_problem_on_visit_yn = '2'}
}
Switch ($AccurateOrder){
'yes' {$formdata[5].onf_q_chipotle_accurate_order_yn = '1'}
'no' {$formdata[5].onf_q_chipotle_accurate_order_yn = '2'}
}
Switch ($OrdersinLast6Months){
'First visit' {$formdata[6].onf_q_chipotle_orders_in_last_6_months_alt = '10'}
'1' {$formdata[6].onf_q_chipotle_orders_in_last_6_months_alt = '15'}
'2-3' {$formdata[6].onf_q_chipotle_orders_in_last_6_months_alt = '20'}
'4-5' {$formdata[6].onf_q_chipotle_orders_in_last_6_months_alt = '30'}
'6+' {$formdata[6].onf_q_chipotle_orders_in_last_6_months_alt = '40'}
}
Switch ($AgeGroup){
'Under 18' {$formdata[6].onf_q_chipotle_age_group_alt = '10'}
'18-24' {$formdata[6].onf_q_chipotle_age_group_alt = '20'}
'25-34' {$formdata[6].onf_q_chipotle_age_group_alt = '30'}
'35-49' {$formdata[6].onf_q_chipotle_age_group_alt = '40'}
'50-64' {$formdata[6].onf_q_chipotle_age_group_alt = '50'}
'65 and older' {$formdata[6].onf_q_chipotle_age_group_alt = '60'}
'Prefer not to answer' {$formdata[6].onf_q_chipotle_age_group_alt = '70'}
}
If ($EnterSweepstakes -eq 'yes'){
$formdata[7].spl_q_chipotle_customer_first_name_txt = $FirstName
$formdata[7].spl_q_chipotle_customer_last_name_txt = $LastName
$formdata[7].spl_q_chipotle_customer_email_address_txt = $EmailAddress
}
If ($ExportAnswerFile){
$formdata | ConvertTo-Json | set-content -Path "$PSScriptRoot\SurveyAnswers.json"
}
}
#
Send-surveyanswers -Formdata $formdata
}
function send-surveyanswers {
[Cmdletbinding()]
Param($Formdata)
$url = 'https://www.chipotlefeedback.com'
#initial connection and retreive first formdata
$webrequest = invoke-webrequest $url -SessionVariable websession
$WebForm = $webrequest.forms[0]
#nodeID and ballotVer appear to be unique to the session. set it now then append it to each form for submission
$nodeID = $webform.fields.nodeId
$nextBallotVer = $webform.fields.ballotVer
#loop through json array, for each set of form data, post the form data
Write-Progress -Activity "Gathering Free Burritos" -Status "Submitting Form Data" -PercentComplete 0
foreach ($item in $formdata){
#update nodeID field
$item.nodeId = $nodeID
$item.ballotVer = $nextBallotVer
$hashtable = $item | ConvertPSObjectToHashtable
#submit form data
write-verbose $hashtable
$return = invoke-webrequest -uri "$url$($WebForm.action)" -Method POST -Body $hashtable -WebSession $websession
$nextBallotVer = $return.forms[0].fields.ballotVer
$ReturnMessages = $return.allelements.where{$_.tagName -eq "BODY"}.innerHTML
#check return data for errors
if ($ReturnMessages.where{$_ -like "*receipt code you entered has already been used*"}){
write-error "The Receipt code you entered has already been used to complete a survey"
return
}
if ($ReturnMessages.where{$_ -like "*class=`"error-block readable-text`"*"}){
Write-error $ReturnMessages.split('<').where{$_ -like "*class=`"error-block readable-text`"*"}.split('<>')[1]
return
}
#if no errors get progress or completed state
$CompletedData = $return.allelements.where{$_.tagName -eq "BODY"}.innerHTML.where{$_ -like "*Thank You!*"}
if ($ReturnMessages.where{$_ -like "*class=progress-bar*"}){
$SurveyProgress = $ReturnMessages.split('<').where{$_ -like "*class=progress-bar*"}.split(' ').where{$_ -like "*%"}.replace('%','')
}
if ($CompletedData){
$SurveyProgress = '100'
$outputMessage = $Completeddata.split('<>').where{$_ -like "Thank You *"}
}
#output progress or completed state
write-verbose "SurveyProgress: $surveyprogress"
if ($SurveyProgress){
Write-Progress -Activity "Gathering Free Burritos" -Status "Submitting Form Data" -PercentComplete $SurveyProgress
}
if ($outputMessage){
return $outputMessage
}
}
}
function ConvertPSObjectToHashtable
{
param (
[Parameter(ValueFromPipeline)]
$InputObject
)
process
{
if ($null -eq $InputObject) { return $null }
if ($InputObject -is [System.Collections.IEnumerable] -and $InputObject -isnot [string])
{
$collection = @(
foreach ($object in $InputObject) { ConvertPSObjectToHashtable $object }
)
Write-Output -NoEnumerate $collection
}
elseif ($InputObject -is [psobject])
{
$hash = @{}
foreach ($property in $InputObject.PSObject.Properties)
{
$hash[$property.Name] = ConvertPSObjectToHashtable $property.Value
}
$hash
}
else
{
$InputObject
}
}
}