packages feed

lackey 1.0.1 → 1.0.2

raw patch · 10 files changed

+173/−171 lines, 10 filesdep ~basedep ~hspecdep ~servantPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, hspec, servant, servant-foreign, text

API changes (from Hackage documentation)

Files

+ CHANGELOG.markdown view
@@ -0,0 +1,7 @@+# Change log++Lackey uses [Semantic Versioning][].+The change log is available through the [releases on GitHub][].++[Semantic Versioning]: http://semver.org/spec/v2.0.0.html+[releases on GitHub]: https://github.com/tfausak/lackey/releases
− CHANGELOG.md
@@ -1,7 +0,0 @@-# Change log--Lackey uses [Semantic Versioning][].-The change log is available through the [releases on GitHub][].--[Semantic Versioning]: http://semver.org/spec/v2.0.0.html-[releases on GitHub]: https://github.com/tfausak/lackey/releases
+ LICENSE.markdown view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2018 Taylor Fausak++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
− LICENSE.md
@@ -1,21 +0,0 @@-MIT License--Copyright (c) 2018 Taylor Fausak--Permission is hereby granted, free of charge, to any person obtaining a copy-of this software and associated documentation files (the "Software"), to deal-in the Software without restriction, including without limitation the rights-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell-copies of the Software, and to permit persons to whom the Software is-furnished to do so, subject to the following conditions:--The above copyright notice and this permission notice shall be included in all-copies or substantial portions of the Software.--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE-SOFTWARE.
+ README.markdown view
@@ -0,0 +1,42 @@+# [Lackey][]++[![Version badge][]][version]+[![Build badge][]][build]++Lackey is a Haskell library for generating Ruby consumers of [Servant][] APIs.++Use `Lackey.rubyForAPI` to generate a string of Ruby source code for consuming+a Servant API. For example:++``` hs+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE TypeOperators #-}++import qualified Data.Proxy as Proxy+import qualified Data.Text as Text+import qualified Data.Text.IO as Text+import qualified Lackey+import Servant.API++type API = "words" :> Get '[JSON] [String]++api :: Proxy.Proxy API+api = Proxy.Proxy++ruby :: Text.Text+ruby = Lackey.rubyForAPI api++main :: IO ()+main = Text.putStrLn ruby+-- def get_words(excon)excon.request(:method=>:get,:path=>"/words",:headers=>{},:body=>nil)end+```++The generated functions require [Excon][].++[Lackey]: https://github.com/tfausak/lackey+[Version badge]: https://www.stackage.org/package/lackey/badge/nightly?label=version+[version]: https://www.stackage.org/package/lackey+[Build badge]: https://travis-ci.org/tfausak/lackey.svg?branch=master+[build]: https://travis-ci.org/tfausak/lackey+[Servant]: https://haskell-servant.readthedocs.org/en/stable/+[Excon]: https://rubygems.org/gems/excon
− README.md
@@ -1,42 +0,0 @@-# [Lackey][]--[![Version badge][]][version]-[![Build badge][]][build]--Lackey is a Haskell library for generating Ruby consumers of [Servant][] APIs.--Use `Lackey.rubyForAPI` to generate a string of Ruby source code for consuming-a Servant API. For example:--``` hs-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE TypeOperators #-}--import qualified Data.Proxy as Proxy-import qualified Data.Text as Text-import qualified Data.Text.IO as Text-import qualified Lackey-import Servant.API--type API = "words" :> Get '[JSON] [String]--api :: Proxy.Proxy API-api = Proxy.Proxy--ruby :: Text.Text-ruby = Lackey.rubyForAPI api--main :: IO ()-main = Text.putStrLn ruby--- def get_words(excon)excon.request(:method=>:get,:path=>"/words",:headers=>{},:body=>nil)end-```--The generated functions require [Excon][].--[Lackey]: https://github.com/tfausak/lackey-[Version badge]: https://www.stackage.org/package/lackey/badge/nightly?label=version-[version]: https://www.stackage.org/package/lackey-[Build badge]: https://travis-ci.org/tfausak/lackey.svg?branch=master-[build]: https://travis-ci.org/tfausak/lackey-[Servant]: https://haskell-servant.readthedocs.org/en/stable/-[Excon]: https://rubygems.org/gems/excon
lackey.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: dd92c1c9ffb8ae847e3fccaa2e4c22f37975103eeb770050d693e226fb396c11+-- hash: f6d519a685c6fa1ec5fa2f3ce3bccf926e94fa9a25dedc7904540c200f677265  name:           lackey-version:        1.0.1+version:        1.0.2 synopsis:       Generate Ruby clients from Servant APIs. description:    Lackey generates Ruby clients from Servant APIs. category:       Web@@ -13,14 +13,14 @@ bug-reports:    https://github.com/tfausak/lackey/issues maintainer:     Taylor Fausak license:        MIT+license-file:   LICENSE.markdown build-type:     Simple cabal-version:  >= 1.10  extra-source-files:-    CHANGELOG.md-    LICENSE.md+    CHANGELOG.markdown     package.yaml-    README.md+    README.markdown     stack.yaml  source-repository head@@ -30,12 +30,12 @@ library   hs-source-dirs:       library-  ghc-options: -Wall+  ghc-options: -Weverything -Wno-implicit-prelude -Wno-safe -Wno-unsafe   build-depends:-      base >=4.8 && <4.11-    , servant >=0.8 && <0.14-    , servant-foreign >=0.8 && <0.12-    , text >=1.2 && <1.3+      base >=4.9.0 && <4.12+    , servant >=0.8.1 && <0.14+    , servant-foreign >=0.8.1 && <0.12+    , text >=1.2.2 && <1.3   exposed-modules:       Lackey   other-modules:@@ -47,14 +47,14 @@   main-is: Main.hs   hs-source-dirs:       tests-  ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N+  ghc-options: -Weverything -Wno-implicit-prelude -Wno-safe -Wno-unsafe -rtsopts -threaded   build-depends:-      base >=4.8 && <4.11-    , hspec >=2.4.4 && <2.5+      base >=4.9.0 && <4.12+    , hspec >=2.2.3 && <2.5     , lackey-    , servant >=0.8 && <0.14-    , servant-foreign >=0.8 && <0.12-    , text >=1.2 && <1.3+    , servant >=0.8.1 && <0.14+    , servant-foreign >=0.8.1 && <0.12+    , text >=1.2.2 && <1.3   other-modules:       Paths_lackey   default-language: Haskell2010
package.yaml view
@@ -1,26 +1,29 @@ name: lackey-version: 1.0.1+version: 1.0.2  category: Web description: Lackey generates Ruby clients from Servant APIs. extra-source-files:-  - CHANGELOG.md-  - LICENSE.md+  - CHANGELOG.markdown   - package.yaml-  - README.md+  - README.markdown   - stack.yaml github: tfausak/lackey+license-file: LICENSE.markdown license: MIT maintainer: Taylor Fausak synopsis: Generate Ruby clients from Servant APIs.  dependencies:-  - base >= 4.8 && < 4.11-  - servant >= 0.8 && < 0.14-  - servant-foreign >= 0.8 && < 0.12-  - text >= 1.2 && < 1.3+  base: '>= 4.9.0 && < 4.12'+  servant: '>= 0.8.1 && < 0.14'+  servant-foreign: '>= 0.8.1 && < 0.12'+  text: '>= 1.2.2 && < 1.3' ghc-options:-  - -Wall+  - -Weverything+  - -Wno-implicit-prelude+  - -Wno-safe+  - -Wno-unsafe  library:   source-dirs: library@@ -28,11 +31,10 @@ tests:   test:     dependencies:-      - lackey-      - hspec >= 2.4.4 && < 2.5+      hspec: '>= 2.2.3 && < 2.5'+      lackey: -any     ghc-options:       - -rtsopts       - -threaded-      - -with-rtsopts=-N     source-dirs: tests     main: Main.hs
stack.yaml view
@@ -1,1 +1,1 @@-resolver: lts-10.0+resolver: lts-11.0
tests/Main.hs view
@@ -1,127 +1,127 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-} -import Data.Proxy-import Data.Text-import Lackey-import Servant.API-import Test.Hspec+import qualified Data.Proxy as Proxy+import qualified Data.Text as Text+import qualified Lackey+import qualified Servant.API as Servant+import qualified Test.Hspec as Hspec  main :: IO ()-main = hspec . parallel . describe "Lackey" . describe "rubyForAPI" $ do+main = Hspec.hspec . Hspec.parallel . Hspec.describe "Lackey" . Hspec.describe "rubyForAPI" $ do -  it "supports delete requests" $ do-    let api = Proxy :: Proxy (Delete '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports delete requests" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Delete '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "delete" "" "delete" "" "" False -  it "supports get requests" $ do-    let api = Proxy :: Proxy (Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports get requests" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" "" "get" "" "" False -  it "supports patch requests" $ do-    let api = Proxy :: Proxy (Patch '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports patch requests" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Patch '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "patch" "" "patch" "" "" False -  it "supports post requests" $ do-    let api = Proxy :: Proxy (Post '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports post requests" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Post '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "post" "" "post" "" "" False -  it "supports put requests" $ do-    let api = Proxy :: Proxy (Put '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports put requests" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Put '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "put" "" "put" "" "" False -  it "supports alternatives" $ do-    let api = Proxy :: Proxy (Get '[JSON] () :<|> Delete '[JSON] ())-    rubyForAPI api `shouldBe` mconcat+  Hspec.it "supports alternatives" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Get '[Servant.JSON] () Servant.:<|> Servant.Delete '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe` Text.concat       [ ruby "get" "" "get" "" "" False-      , singleton ';'+      , Text.singleton ';'       , ruby "delete" "" "delete" "" "" False       ] -  it "supports captures" $ do-    let api = Proxy :: Proxy (Capture "id" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports captures" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Capture "id" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get_by_id" ",id" "get" "#{id}" "" False -  it "supports query flags" $ do-    let api = Proxy :: Proxy (QueryFlag "flag" :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports query flags" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryFlag "flag" Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",flag: nil" "get" "?flag=#{flag}" "" False -  it "supports query params" $ do-    let api = Proxy :: Proxy (QueryParam "param" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports query params" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryParam "param" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",param: nil" "get" "?param=#{param}" "" False -  it "supports multiple query params" $ do-    let api = Proxy :: Proxy (QueryParams "params" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports multiple query params" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryParams "params" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",params: nil" "get" "?params=#{params}" "" False -  it "supports request bodies" $ do-    let api = Proxy :: Proxy (ReqBody '[JSON] () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports request bodies" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.ReqBody '[Servant.JSON] () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",body" "get" "" "" True -  it "supports request headers" $ do-    let api = Proxy :: Proxy (Header "cookie" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "supports request headers" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Header "cookie" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",cookie: nil" "get" "" "\"cookie\"=>cookie" False -  it "supports response headers" $ do-    let api = Proxy :: Proxy (Get '[JSON] (Headers '[] ()))-    rubyForAPI api `shouldBe`+  Hspec.it "supports response headers" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Get '[Servant.JSON] (Servant.Headers '[] ()))+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" "" "get" "" "" False -  it "puts the body param after captures" $ do-    let api = Proxy :: Proxy (Capture "segment" () :> ReqBody '[JSON] () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "puts the body param after captures" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Capture "segment" () Servant.:> Servant.ReqBody '[Servant.JSON] () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get_by_segment" ",segment,body" "get" "#{segment}" "" True -  it "puts the body param after query params" $ do-    let api = Proxy :: Proxy (QueryFlag "flag" :> ReqBody '[JSON] () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "puts the body param after query params" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryFlag "flag" Servant.:> Servant.ReqBody '[Servant.JSON] () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",flag: nil,body" "get" "?flag=#{flag}" "" True -  it "sanitizes path segments" $ do-    let api = Proxy :: Proxy ("A!" :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "sanitizes path segments" $ do+    let api = Proxy.Proxy :: Proxy.Proxy ("A!" Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get_A!" "" "get" "A!" "" False -  it "sanitizes captures" $ do-    let api = Proxy :: Proxy (Capture "A!" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "sanitizes captures" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Capture "A!" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get_by_A!" ",a_" "get" "#{a_}" "" False -  it "sanitizes query flags" $ do-    let api = Proxy :: Proxy (QueryFlag "A!" :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "sanitizes query flags" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryFlag "A!" Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",a_: nil" "get" "?A!=#{a_}" "" False -  it "sanitizes query params" $ do-    let api = Proxy :: Proxy (QueryParam "A!" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "sanitizes query params" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryParam "A!" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",a_: nil" "get" "?A!=#{a_}" "" False -  it "sanitizes multiple query params" $ do-    let api = Proxy :: Proxy (QueryParams "A!" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "sanitizes multiple query params" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.QueryParams "A!" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",a_: nil" "get" "?A!=#{a_}" "" False -  it "sanitizes headers" $ do-    let api = Proxy :: Proxy (Header "A!" () :> Get '[JSON] ())-    rubyForAPI api `shouldBe`+  Hspec.it "sanitizes headers" $ do+    let api = Proxy.Proxy :: Proxy.Proxy (Servant.Header "A!" () Servant.:> Servant.Get '[Servant.JSON] ())+    Lackey.rubyForAPI api `Hspec.shouldBe`       ruby "get" ",a_: nil" "get" "" "\"A!\"=>a_" False  -- Since every generated function has the same structure, it can be abstracted -- away behind this function.-ruby :: String -> String -> String -> String -> String -> Bool -> Text-ruby name params method path headers body = pack (mconcat+ruby :: String -> String -> String -> String -> String -> Bool -> Text.Text+ruby name params method path headers body = Text.pack (concat   [ "def ", name, "(excon", params, ")"   , "excon.request("   , ":method=>:", method, ","