@@ -34,16 +34,25 @@ import Language.Haskell.Exts.SrcLoc
34import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
34import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
36urlSig :: Name -> Decl
36urlSig :: Name -> Decl
37−urlSig n = TypeSig noLoc [n] (TyCon "RequestBuilder")
37+urlSig n = TypeSig noLoc [n] (TyCon "Service")
39urlDecl :: Service a -> Name -> Decl
39urlDecl :: Service a -> Name -> Decl
40urlDecl s n = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
40urlDecl s n = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
42− rhs = appFun (var "defaultRequest")
42+ rhs = appFun (var "defaultService")
43− [ str (s ^. dRootUrl)
43+ [ app (var "ServiceId") (str (s ^. dId))
44+ , str . stripSuffix "/" $ stripPrefix "https://" (s ^. dRootUrl)
44 , str (s ^. dServicePath)
45 , str (s ^. dServicePath)
48+scopeSig :: Name -> Decl
49+scopeSig n = TypeSig noLoc [n] (TyCon "OAuthScope")
51+scopeDecl :: Name -> Text -> Decl
52+scopeDecl n s = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
54+ rhs = app (var "OAuthScope") (str s)
47 -- type API = :<|> ...
56 -- type API = :<|> ...
48apiAlias :: Name -> [Name] -> Decl
57apiAlias :: Name -> [Name] -> Decl
49apiAlias n ls = TypeDecl noLoc n [] alias
58apiAlias n ls = TypeDecl noLoc n [] alias
@@ -97,8 +106,6 @@ verbAlias n m
97 let t = terminalType (_type (_pParam x))
106 let t = terminalType (_type (_pParam x))
98 n = sing (local k)
107 n = sing (local k)
99 in case _pLocation x of
108 in case _pLocation x of
100− Header | local k == "oauth_token"
101− -> Just $ TyApp (TyApp (TyCon "Header") (sing "Authorization")) t
102 Query | x ^. iRepeated
109 Query | x ^. iRepeated
103 -> Just $ TyApp (TyApp (TyCon "QueryParams") n) t
110 -> Just $ TyApp (TyApp (TyCon "QueryParams") n) t
104 Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
111 Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
@@ -188,21 +195,18 @@ googleRequestDecl g n assoc alt p api url fields m pat prec =
188 InstDecl noLoc Nothing [] [] (unqual "GoogleRequest") [n]
195 InstDecl noLoc Nothing [] [] (unqual "GoogleRequest") [n]
190 , request
197 , request
194− request = funD "request" $ app (var "requestWith") (var url)
196− requestWith = InsDecl (FunBind [match])
200+ request = InsDecl (FunBind [match])
198− match = Match noLoc (name "requestWith") pats Nothing rhs decls
202+ match = Match noLoc (name "requestClient") [prec] Nothing rhs decls
200 decls = BDecls
204 decls = BDecls
201 [ patBind noLoc pat $
205 [ patBind noLoc pat $
202 appFun (var "clientBuild") $
206 appFun (var "clientBuild") $
203 [ ExpTypeSig noLoc (var "Proxy") $
207 [ ExpTypeSig noLoc (var "Proxy") $
204 TyApp (TyCon "Proxy") (TyCon (UnQual api))
208 TyApp (TyCon "Proxy") (TyCon (UnQual api))
205− , var "rq"
209+ , var "mempty"
@@ -210,6 +214,7 @@ googleRequestDecl g n assoc alt p api url fields m pat prec =
210 ++ maybeToList (app (var "Just") <$> alt)
214 ++ maybeToList (app (var "Just") <$> alt)
211 ++ maybeToList (go <$> rq)
215 ++ maybeToList (go <$> rq)
212 ++ maybeToList (go <$> pay)
216 ++ maybeToList (go <$> pay)
214 go l = case Map.lookup l ps of
219 go l = case Map.lookup l ps of
215 Just p | _pLocation p == Query
220 Just p | _pLocation p == Query
@@ -240,18 +245,6 @@ googleRequestDecl g n assoc alt p api url fields m pat prec =
241 $ map fst (rights (extractPath (_mPath m))) ++ _mParameterOrder m
246 $ map fst (rights (extractPath (_mPath m))) ++ _mParameterOrder m
243− pats = [pvar "rq", prec]
245−authDecl :: Global -> Prefix -> [Local] -> Decl
246−authDecl g p fs = InstDecl noLoc Nothing [] [] (unqual "GoogleAuth") [tycon g]
247− [ method "_AuthKey" "key"
248− , method "_AuthToken" "oauth_token"
252− | f `elem` fs = funD l (infixApp (var (lname p f)) "." (var "_Just"))
253− | otherwise = funD l (app (var "const") (var "pure"))
255jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
248jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
256jsonDecls g p (Map.toList -> rs) = [from, to]
249jsonDecls g p (Map.toList -> rs) = [from, to]
@@ -458,8 +451,6 @@ externalLit = \case
458 Int64 -> TyCon "Int64"
451 Int64 -> TyCon "Int64"
460 Alt t -> TyCon (unqual (Text.unpack t))
453 Alt t -> TyCon (unqual (Text.unpack t))
461− Key -> TyCon "AuthKey"
462− OAuthToken -> TyCon "OAuthToken"
463 Body -> TyCon "Stream"
454 Body -> TyCon "Stream"
464 JSONValue -> TyCon "JSONValue"
455 JSONValue -> TyCon "JSONValue"
@@ -480,8 +471,6 @@ internalLit = \case
480 Int64 -> TyCon "Int64"
471 Int64 -> TyCon "Int64"
482 Alt t -> TyCon (unqual (Text.unpack t))
473 Alt t -> TyCon (unqual (Text.unpack t))
483− Key -> TyCon "AuthKey"
484− OAuthToken -> TyCon "OAuthToken"
485 Body -> TyCon "Stream"
474 Body -> TyCon "Stream"
486 JSONValue -> TyCon "JSONValue"
475 JSONValue -> TyCon "JSONValue"