passkit 0.0.1

Apple PassKit library to manage passes
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use field::Field;
use util::*;

/// The top level of the pass.json file is a dictionary.
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Pass {
    /// Brief description of the pass, used by the iOS accessibility technologies.
    pub description: String,

    /// Version of the file format. The value must be 1.
    pub format_version: i32,

    /// Display name of the organization that originated and signed the pass.
    pub organization_name: String,

    /// Pass type identifier, as issued by Apple.
    /// The value must correspond with your signing certificate.
    pub pass_type_identifier: String,

    /// Serial number that uniquely identifies the pass.
    /// No two passes with the same pass type identifier may have the same serial number.
    pub serial_number: String,

    /// Team identifier of the organization that originated and signed the pass, as issued by Apple.
    pub team_identifier: String,

    /// A URL to be passed to the associated app when launching it.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "appLaunchURL")]
    #[serde(default)]
    pub app_launch_url: Option<String>,

    /// A list of iTunes Store item identifiers for the associated apps.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    #[serde(default)]
    pub associated_store_identifiers: Vec<i32>,

    #[serde(default)]
    pub user_info: HashMap<String, String>,

    /// Date and time when the pass expires.
    /// W3C date
    /// The value must be a complete date with hours and minutes, and may optionally include seconds.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub expiration_date: Option<String>,

    /// Indicates that the pass is void—for example, a one time use coupon that has been redeemed.
    /// The default value is false.
    #[serde(skip_serializing_if = "is_false")]
    #[serde(default)]
    pub voided: bool,

    /// Beacons marking locations where the pass is relevant.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    #[serde(default)]
    pub beacons: Vec<Beacon>,

    /// Locations where the pass is relevant. For example, the location of your store.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    #[serde(default)]
    pub locations: Vec<Location>,

    /// Maximum distance in meters from a relevant latitude and longitude that the pass is relevant.
    /// This number is compared to the pass’s default distance and the smaller value is used.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub max_distance: Option<u32>,

    /// Recommended for event tickets and boarding passes; otherwise optional.
    /// Date and time when the pass becomes relevant. For example, the start time of a movie.
    /// The value must be a complete date with hours and minutes, and may optionally include seconds.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub relevant_date: Option<String>,

    #[serde(flatten)]
    pub style: Style,

    #[serde(default)]
    #[serde(flatten)]
    pub visual: Option<VisualAppearance>,

    /// Information used to update passes using the web service.
    // #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(flatten)]
    #[serde(default)]
    pub web_service: Option<WebService>,

    /// Information used for Value Added Service Protocol transactions.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub nfc: Option<NFC>,
}

#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct VisualAppearance {
    /// Information specific to the pass’s barcode.
    /// The system uses the first valid barcode dictionary in the array.
    /// Additional dictionaries can be added as fallbacks
    #[serde(skip_serializing_if = "Vec::is_empty")]
    #[serde(default)]
    pub barcodes: Vec<Barcode>,

    /// Background color of the pass, specified as an CSS-style RGB triple.
    /// For example, rgb(23, 187, 82).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub background_color: Option<String>,

    /// Foreground color of the pass, specified as a CSS-style RGB triple.
    /// For example, rgb(100, 10, 110).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub foreground_color: Option<String>,

    /// Optional for event tickets and boarding passes; otherwise not allowed.
    /// Identifier used to group related passes. If a grouping identifier is specified,
    /// passes with the same style, pass type identifier, and grouping identifier are displayed as a group.
    /// Otherwise, passes are grouped automatically. Use this to group passes that are tightly related,
    /// such as the boarding passes for different connections of the same trip.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub grouping_identifier: Option<String>,

    /// Color of the label text, specified as a CSS-style RGB triple.
    /// For example, rgb(255, 255, 255).
    /// If omitted, the label color is determined automatically.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub label_color: Option<String>,

    /// Text displayed next to the logo on the pass.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub logo_text: Option<String>,

    /// If true, the strip image is displayed without a shine effect.
    /// The default value prior to iOS 7.0 is false.
    /// In iOS 7.0, a shine effect is never applied, and this key is deprecated.
    #[serde(skip_serializing_if = "is_false")]
    #[serde(default)]
    pub suppress_strip_shine: bool,
}

/// Information about a location beacon.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct Beacon {
    /// Unique identifier of a Bluetooth Low Energy location beacon.
    #[serde(rename = "proximityUUID")]
    pub proximity_uuid: String,

    /// Major identifier of a Bluetooth Low Energy location beacon.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub major: Option<u16>,

    /// Minor identifier of a Bluetooth Low Energy location beacon.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minor: Option<u16>,

    /// Text displayed on the lock screen when the pass is currently relevant.
    /// For example, a description of the nearby location such as “Store nearby on 1st and Main.”
    #[serde(skip_serializing_if = "Option::is_none")]
    pub relevant_text: Option<String>,
}

/// Information about a location.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct Location {
    /// Altitude, in meters, of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub altitude: Option<f64>,

    /// Latitude, in meters, of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub latitude: Option<f64>,

    /// Longitude, in meters, of the location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub longitude: Option<f64>,

    /// Text displayed on the lock screen when the pass is currently relevant.
    /// For example, a description of the nearby location such as “Store nearby on 1st and Main.”
    #[serde(skip_serializing_if = "Option::is_none")]
    pub relevant_text: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Style {
    BoardingPass(Structure),
    Coupon(Structure),
    EventTicket(Structure),
    Generic(Structure),
    StoreCard(Structure),
}

impl Default for Style {
    fn default() -> Style {
        Style::Generic(Default::default())
    }
}

/// Keys that define the structure of the pass.
/// These keys are used for all pass styles and partition the fields into the various parts of the pass.
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub struct Structure {
    /// Additional fields to be displayed on the front of the pass.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    auxiliary_fields: Vec<Field>,

    /// Fields to be on the back of the pass.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    back_fields: Vec<Field>,

    /// Fields to be displayed in the header on the front of the pass.
    /// Use header fields sparingly; unlike all other fields, they remain visible when a stack of passes are displayed.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    header_fields: Vec<Field>,

    /// Fields to be displayed prominently on the front of the pass.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    primary_fields: Vec<Field>,

    /// Fields to be displayed on the front of the pass.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    secondary_fields: Vec<Field>,

    /// Required for boarding passes; otherwise not allowed. Type of transit.
    #[serde(skip_serializing_if = "Option::is_none")]
    transit_type: Option<TransitType>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum TransitType {
    #[serde(rename = "PKTransitTypeAir")]
    Air,

    #[serde(rename = "PKTransitTypeBoat")]
    Boat,

    #[serde(rename = "PKTransitTypeBus")]
    Bus,

    #[serde(rename = "PKTransitTypeGeneric")]
    Generic,

    #[serde(rename = "PKTransitTypeTrain")]
    Train,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Barcode {
    /// Message or payload to be displayed as a barcode.
    pub message: String,

    /// Barcode format.
    pub format: BarcodeFormat,

    /// Text encoding that is used to convert the message from the string representation
    /// to a data representation to render the barcode.
    /// The value is typically iso-8859-1, but you may use another encoding that
    /// is supported by your barcode scanning infrastructure.
    pub message_encoding: String,

    /// Text displayed near the barcode.
    /// For example, a human-readable version of the barcode data in case the barcode doesn’t scan.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub alt_text: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum BarcodeFormat {
    #[serde(rename = "PKBarcodeFormatQR")]
    QR,
    #[serde(rename = "PKBarcodeFormatPDF417")]
    PDF417,
    #[serde(rename = "PKBarcodeFormatAztec")]
    Aztec,
    #[serde(rename = "PKBarcodeFormatCode128")]
    Code128,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WebService {
    /// The authentication token to use with the web service. The token must be 16 characters or longer.
    pub authentication_token: String,

    /// The URL of a web service that conforms to the API described in PassKit Web Service Reference.
    /// https://developer.apple.com/library/archive/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988
    /// The web service must use the HTTPS protocol; the leading https:// is included in the value of this key.
    /// On devices configured for development, there is UI in Settings to allow HTTP web services.
    #[serde(rename = "webServiceURL")]
    pub web_service_url: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NFC {
    /// The payload to be transmitted to the Apple Pay terminal.
    /// Must be 64 bytes or less. Messages longer than 64 bytes are truncated by the system.
    pub message: String,

    /// The public encryption key used by the Value Added Services protocol.
    /// Use a Base64 encoded X.509 SubjectPublicKeyInfo structure containing a ECDH public key for group P256.
    #[serde(default)]
    pub encryption_public_key: Option<String>,
}

#[derive(Default, Clone)]
pub struct PassBuilder {
    serial_number: String,
    pass_type_identifier: String,
    team_identifier: String,
    organization_name: Option<String>,
    description: Option<String>,
    structure: Structure,
    app_launch_url: Option<String>,
    associated_store_identifiers: Vec<i32>,
    user_info: HashMap<String, String>,
    expiration_date: Option<String>,
    voided: bool,
    beacons: Vec<Beacon>,
    locations: Vec<Location>,
    max_distance: Option<u32>,
    relevant_date: Option<String>,
    visual: VisualAppearance,
    web_service: Option<WebService>,
    nfc: Option<NFC>,
}

impl PassBuilder {
    pub fn new<S, I, T>(
        serial_number: S,
        pass_type_identifier: I,
        team_identifier: T,
    ) -> PassBuilder
    where
        S: Into<String>,
        I: Into<String>,
        T: Into<String>,
    {
        PassBuilder {
            serial_number: serial_number.into(),
            pass_type_identifier: pass_type_identifier.into(),
            team_identifier: team_identifier.into(),
            ..Default::default()
        }
    }

    pub fn organization_name<O: Into<String>>(mut self, organization_name: O) -> PassBuilder {
        self.organization_name = Some(organization_name.into());
        self
    }

    pub fn description<D: Into<String>>(mut self, description: D) -> PassBuilder {
        self.description = Some(description.into());
        self
    }

    pub fn app_launch_url<U: Into<String>>(mut self, url: U) -> PassBuilder {
        self.app_launch_url = Some(url.into());
        self
    }

    pub fn add_associated_store_identifier(mut self, id: i32) -> PassBuilder {
        self.associated_store_identifiers.push(id);
        self
    }

    pub fn add_user_info<K, V>(mut self, key: K, value: V) -> PassBuilder
    where
        K: Into<String>,
        V: Into<String>,
    {
        self.user_info.insert(key.into(), value.into());
        self
    }

    pub fn expiration_date<D: Into<String>>(mut self, date: D) -> PassBuilder {
        self.expiration_date = Some(date.into());
        self
    }

    pub fn voided(mut self) -> PassBuilder {
        self.voided = true;
        self
    }

    pub fn add_beacon(mut self, beacon: Beacon) -> PassBuilder {
        self.beacons.push(beacon);
        self
    }

    pub fn add_location(mut self, location: Location) -> PassBuilder {
        self.locations.push(location);
        self
    }

    pub fn max_distance(mut self, distance: u32) -> PassBuilder {
        self.max_distance = Some(distance);
        self
    }

    pub fn relevant_date(mut self, date: String) -> PassBuilder {
        self.relevant_date = Some(date);
        self
    }

    pub fn add_auxiliary_field(mut self, field: Field) -> PassBuilder {
        self.structure.auxiliary_fields.push(field);
        self
    }

    pub fn add_back_field(mut self, field: Field) -> PassBuilder {
        self.structure.back_fields.push(field);
        self
    }

    pub fn add_header_field(mut self, field: Field) -> PassBuilder {
        self.structure.header_fields.push(field);
        self
    }

    pub fn add_primary_field(mut self, field: Field) -> PassBuilder {
        self.structure.primary_fields.push(field);
        self
    }

    pub fn add_secondary_field(mut self, field: Field) -> PassBuilder {
        self.structure.auxiliary_fields.push(field);
        self
    }

    pub fn add_barcode(mut self, barcode: Barcode) -> PassBuilder {
        self.visual.barcodes.push(barcode);
        self
    }

    pub fn background_color<C: Into<String>>(mut self, color: C) -> PassBuilder {
        self.visual.background_color = Some(color.into());
        self
    }

    pub fn foreground_color<C: Into<String>>(mut self, color: C) -> PassBuilder {
        self.visual.foreground_color = Some(color.into());
        self
    }

    pub fn grouping_identifier(mut self, identifier: String) -> PassBuilder {
        self.visual.grouping_identifier = Some(identifier);
        self
    }

    pub fn label_color(mut self, color: String) -> PassBuilder {
        self.visual.label_color = Some(color);
        self
    }

    pub fn logo_text<T: Into<String>>(mut self, text: T) -> PassBuilder {
        self.visual.logo_text = Some(text.into());
        self
    }

    pub fn suppress_strip_shine(mut self) -> PassBuilder {
        self.visual.suppress_strip_shine = true;
        self
    }

    pub fn web_service<T, U>(mut self, token: T, url: U) -> PassBuilder
    where
        T: Into<String>,
        U: Into<String>,
    {
        self.web_service = Some(WebService {
            authentication_token: token.into(),
            web_service_url: url.into(),
        });
        self
    }

    pub fn nfc<M: Into<String>>(mut self, message: M, key: Option<String>) -> PassBuilder {
        self.nfc = Some(NFC {
            message: message.into(),
            encryption_public_key: key,
        });
        self
    }

    fn build(self, style: Style) -> Pass {
        Pass {
            format_version: 1,
            serial_number: self.serial_number,
            pass_type_identifier: self.pass_type_identifier,
            team_identifier: self.team_identifier,
            organization_name: self.organization_name.unwrap_or_default(),
            description: self.description.unwrap_or_default(),
            app_launch_url: self.app_launch_url,
            associated_store_identifiers: self.associated_store_identifiers,
            user_info: self.user_info,
            expiration_date: self.expiration_date,
            voided: self.voided,
            beacons: self.beacons,
            locations: self.locations,
            max_distance: self.max_distance,
            relevant_date: self.relevant_date,
            style,
            visual: Some(self.visual),
            web_service: self.web_service,
            nfc: self.nfc,
        }
    }

    pub fn finish_boarding_pass(self, transit_type: TransitType) -> Pass {
        let mut structure = self.structure.clone();
        structure.transit_type = Some(transit_type);
        self.build(Style::BoardingPass(structure))
    }

    pub fn finish_coupon(self) -> Pass {
        let structure = self.structure.clone();
        self.build(Style::Coupon(structure))
    }

    pub fn finish_event_ticket(self) -> Pass {
        let structure = self.structure.clone();
        self.build(Style::EventTicket(structure))
    }

    pub fn finish_generic(self) -> Pass {
        let structure = self.structure.clone();
        self.build(Style::Generic(structure))
    }

    pub fn finish_store_card(self) -> Pass {
        let structure = self.structure.clone();
        self.build(Style::StoreCard(structure))
    }
}

mod test {
    #[test]
    fn ser_pass_example() {
        use super::*;

        let pass = PassBuilder::new("001", "pass.com.example", "CDHE9L6U22")
            .web_service(
                "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
                "https://example.com/passes/",
            ).relevant_date("2012-07-22T14:25-08:00".into())
            .add_location(Location {
                longitude: Some(-122.3748889),
                latitude: Some(37.6189722),
                altitude: None,
                relevant_text: None,
            }).add_barcode(Barcode {
                message: "SFOJFK JOHN APPLESEED LH451 2012-07-22T14:25-08:00".into(),
                format: BarcodeFormat::PDF417,
                message_encoding: "iso-8859-1".into(),
                alt_text: None,
            }).organization_name("Skyport Airways")
            .description("Skyport Boarding Pass")
            .logo_text("Skyport Airways")
            .foreground_color("rgb(22, 55, 110)")
            .background_color("rgb(22, 55, 110)")
            .add_header_field(Field::new_with_change(
                "GATE",
                "gate",
                "23",
                "Gate changed to %@.",
            )).add_primary_field(Field::new("SAN FRANCISCO", "depart", "SFO"))
            .add_primary_field(Field::new("NEW YORK", "arrive", "JFK"))
            .add_secondary_field(Field::new("PASSENGER", "passenger", "John Appleseed"))
            .add_auxiliary_field(Field::new_with_change(
                "DEPART",
                "boardingTime",
                "2:25 PM",
                "Boarding time changed to %@.",
            )).add_auxiliary_field(Field::new_with_change(
                "FLIGHT",
                "flightNewName",
                "815",
                "Flight number changed to %@",
            )).add_auxiliary_field(Field::new("DESIG.", "class", "Coach"))
            .add_auxiliary_field(Field::new("DATE", "date", "7/22"))
            .add_back_field(Field::new("PASSPORT", "passport", "Canadian/Canadien"))
            .add_back_field(Field::new(
                "RESIDENCE",
                "residence",
                "999 Infinite Loop, Apartment 42, Cupertino CA",
            )).finish_boarding_pass(TransitType::Air);

        println!("{}", serde_json::to_string_pretty(&pass).unwrap());
    }

    #[test]
    fn de_pass_example() {
        use super::*;

        let src = r#"
            {
  "formatVersion" : 1,
  "passTypeIdentifier": "pass.com.sergeysova.home",
  "serialNumber" : "0001",
  "teamIdentifier" : "CDHE9L6U22",
  "webServiceURL" : "https://example.com/passes/",
  "authenticationToken" : "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
  "relevantDate" : "2012-07-22T14:25-08:00",
  "locations" : [
    {
      "longitude" : -122.3748889,
      "latitude" : 37.6189722
    }
  ],
  "barcode" : {
    "message" : "SFOJFK JOHN APPLESEED LH451 2012-07-22T14:25-08:00",
    "format" : "PKBarcodeFormatPDF417",
    "messageEncoding" : "iso-8859-1"
  },
  "organizationName" : "Skyport Airways",
  "description" : "Skyport Boarding Pass",
  "logoText" : "Skyport Airways",
  "foregroundColor" : "rgb(22, 55, 110)",
  "backgroundColor" : "rgb(50, 91, 185)",
  "boardingPass" : {
    "transitType" : "PKTransitTypeAir",
    "headerFields" : [
      {
        "label" : "GATE",
        "key" : "gate",
        "value" : "23",
        "changeMessage" : "Gate changed to %@."
      }
    ],
    "primaryFields" : [
      {
        "key" : "depart",
        "label" : "SAN FRANCISCO",
        "value" : "SFO"
      },
      {
        "key" : "arrive",
        "label" : "NEW YORK",
        "value" : "JFK"
      }
    ],
    "secondaryFields" : [
      {
        "key" : "passenger",
        "label" : "PASSENGER",
        "value" : "John Appleseed"
      }
    ],
    "auxiliaryFields" : [
      {
        "label" : "DEPART",
        "key" : "boardingTime",
        "value" :  "2:25 PM",
        "changeMessage" : "Boarding time changed to %@."
      },
      {
        "label" : "FLIGHT",
        "key" : "flightNewName",
        "value" : "815",
        "changeMessage" : "Flight number changed to %@"
      },
      {
        "key" : "class",
        "label" : "DESIG.",
        "value" : "Coach"
      },
      {
        "key" : "date",
        "label" : "DATE",
        "value" :  "7/22"
      }
    ],
    "backFields" : [
      {
        "key" : "passport",
        "label" : "PASSPORT",
        "value" : "Canadian/Canadien"
      },
      {
        "key" : "residence",
        "label" : "RESIDENCE",
        "value" : "999 Infinite Loop, Apartment 42, Cupertino CA"
      }
    ]
  }
}
        "#;

        let pass: Pass = serde_json::from_str(&src).unwrap();

        println!("{:#?}", pass);
    }
}