+
+MEMO: get-moxfield-user ( username -- json )
+ "https://api2.moxfield.com/v2/users/%s/decks?pageNumber=1&pageSize=100" sprintf http-get-json nip ;
+
+MEMO: get-moxfield-deck ( public-id -- json )
+ "https://api2.moxfield.com/v3/decks/all/" prepend http-get-json nip ;
+
+: moxfield-board>cards ( board -- seq )
+ "cards" of values [
+ [ "quantity" of ] [ "card" of "name" of ] bi 2array
+ ] map assoc>cards ;
+
+: json>moxfield-deck ( json -- mtga-deck )
+ [ "name" of ]
+ [
+ "boards" of
+ [ "mainboard" of moxfield-board>cards ]
+ [ "sideboard" of moxfield-board>cards ] bi
+ ] bi
+ <moxfield-deck> ;
+
+: moxfield-random-deck-for-username ( username -- json )
+ get-moxfield-user
+ "data" of
+ random "publicId" of get-moxfield-deck
+ json>moxfield-deck ;
+
+: moxfield-latest-deck-for-username ( username -- json )
+ get-moxfield-user
+ "data" of ?first "publicId" of get-moxfield-deck
+ json>moxfield-deck ;
+
+: moxfield-latest-deck-for-username. ( username -- )
+ moxfield-latest-deck-for-username deck. ;
+
+: moxfield-latest-deck-and-sideboard-for-username. ( username -- )
+ moxfield-latest-deck-for-username deck-and-sideboard. ;
\ No newline at end of file