on develop help sign in
Adding GoogleAuth and Download instances
commitec605e48168cafa28f60f4c567a143896f41f784 authorBrendan Hay <brendan.g.hay@gmail.com> dateThu 1 Oct 2015, 16:56 (11 years ago) parent8399a3c
2 files changed+12−1
gen/src/Gen/AST/Render.hs+2−1 gen/src/Gen/Syntax.hs+10
gen/src/Gen/AST/Render.hs+2−1
@@ -124,10 +124,11 @@ renderMethod s root suf m@Method {..} = do
124124 x@Solved {..} <- getSolved typ
125125 Just d <- renderSchema x
126126
127+ a <- pp Print $ authDecl _unique _prefix (props _schema)
127128 i <- pp Print $ requestDecl _unique _prefix alias url (props _schema) m
128129 dl <- pp Print $ downloadDecl _unique _prefix alias url (props _schema) m
129130
130− let is = i : [dl | _mSupportsMediaDownload]
131+ let is = a : i : [dl | _mSupportsMediaDownload]
131132
132133 Action _mId _unique (root <> mkNS ns) _mDescription alias
133134 <$> pp Print (verbAlias alias m)
gen/src/Gen/Syntax.hs+10
@@ -194,6 +194,16 @@ googleRequestDecl g n assoc alt p api url fs m =
194194 pats = [pvar "r", pvar "u", prec]
195195 prec = PRec (UnQual (dname g)) [PFieldWildcard]
196196
197+authDecl :: Global -> Prefix -> [Local] -> Decl
198+authDecl g p fs = InstDecl noLoc Nothing [] [] (unqual "GoogleAuth") [tycon g]
199+ [ method "authKey" "key"
200+ , method "authToken" "oauth_token"
201+ ]
202+ where
203+ method l f
204+ | f `elem` fs = funD l (var (lname p f))
205+ | otherwise = funD l (app (var "const") (var "pure"))
206+
197207jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
198208jsonDecls g p (Map.toList -> rs) = [from, to]
199209 where