packages feed

funbot-ext-events (empty) → 0.1.0.0

raw patch · 9 files changed

+500/−0 lines, 9 filesdep +aesondep +basedep +textsetup-changed

Dependencies added: aeson, base, text

Files

+ AUTHORS view
@@ -0,0 +1,3 @@+The Freepost community <https://freepo.st>. Specifically, the following people:++fr33domlover <fr33domlover@rel4tion.org>
+ COPYING view
@@ -0,0 +1,121 @@+Creative Commons Legal Code++CC0 1.0 Universal++    CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE+    LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN+    ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS+    INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES+    REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS+    PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM+    THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED+    HEREUNDER.++Statement of Purpose++The laws of most jurisdictions throughout the world automatically confer+exclusive Copyright and Related Rights (defined below) upon the creator+and subsequent owner(s) (each and all, an "owner") of an original work of+authorship and/or a database (each, a "Work").++Certain owners wish to permanently relinquish those rights to a Work for+the purpose of contributing to a commons of creative, cultural and+scientific works ("Commons") that the public can reliably and without fear+of later claims of infringement build upon, modify, incorporate in other+works, reuse and redistribute as freely as possible in any form whatsoever+and for any purposes, including without limitation commercial purposes.+These owners may contribute to the Commons to promote the ideal of a free+culture and the further production of creative, cultural and scientific+works, or to gain reputation or greater distribution for their Work in+part through the use and efforts of others.++For these and/or other purposes and motivations, and without any+expectation of additional consideration or compensation, the person+associating CC0 with a Work (the "Affirmer"), to the extent that he or she+is an owner of Copyright and Related Rights in the Work, voluntarily+elects to apply CC0 to the Work and publicly distribute the Work under its+terms, with knowledge of his or her Copyright and Related Rights in the+Work and the meaning and intended legal effect of CC0 on those rights.++1. Copyright and Related Rights. A Work made available under CC0 may be+protected by copyright and related or neighboring rights ("Copyright and+Related Rights"). Copyright and Related Rights include, but are not+limited to, the following:++  i. the right to reproduce, adapt, distribute, perform, display,+     communicate, and translate a Work;+ ii. moral rights retained by the original author(s) and/or performer(s);+iii. publicity and privacy rights pertaining to a person's image or+     likeness depicted in a Work;+ iv. rights protecting against unfair competition in regards to a Work,+     subject to the limitations in paragraph 4(a), below;+  v. rights protecting the extraction, dissemination, use and reuse of data+     in a Work;+ vi. database rights (such as those arising under Directive 96/9/EC of the+     European Parliament and of the Council of 11 March 1996 on the legal+     protection of databases, and under any national implementation+     thereof, including any amended or successor version of such+     directive); and+vii. other similar, equivalent or corresponding rights throughout the+     world based on applicable law or treaty, and any national+     implementations thereof.++2. Waiver. To the greatest extent permitted by, but not in contravention+of, applicable law, Affirmer hereby overtly, fully, permanently,+irrevocably and unconditionally waives, abandons, and surrenders all of+Affirmer's Copyright and Related Rights and associated claims and causes+of action, whether now known or unknown (including existing as well as+future claims and causes of action), in the Work (i) in all territories+worldwide, (ii) for the maximum duration provided by applicable law or+treaty (including future time extensions), (iii) in any current or future+medium and for any number of copies, and (iv) for any purpose whatsoever,+including without limitation commercial, advertising or promotional+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each+member of the public at large and to the detriment of Affirmer's heirs and+successors, fully intending that such Waiver shall not be subject to+revocation, rescission, cancellation, termination, or any other legal or+equitable action to disrupt the quiet enjoyment of the Work by the public+as contemplated by Affirmer's express Statement of Purpose.++3. Public License Fallback. Should any part of the Waiver for any reason+be judged legally invalid or ineffective under applicable law, then the+Waiver shall be preserved to the maximum extent permitted taking into+account Affirmer's express Statement of Purpose. In addition, to the+extent the Waiver is so judged Affirmer hereby grants to each affected+person a royalty-free, non transferable, non sublicensable, non exclusive,+irrevocable and unconditional license to exercise Affirmer's Copyright and+Related Rights in the Work (i) in all territories worldwide, (ii) for the+maximum duration provided by applicable law or treaty (including future+time extensions), (iii) in any current or future medium and for any number+of copies, and (iv) for any purpose whatsoever, including without+limitation commercial, advertising or promotional purposes (the+"License"). The License shall be deemed effective as of the date CC0 was+applied by Affirmer to the Work. Should any part of the License for any+reason be judged legally invalid or ineffective under applicable law, such+partial invalidity or ineffectiveness shall not invalidate the remainder+of the License, and in such case Affirmer hereby affirms that he or she+will not (i) exercise any of his or her remaining Copyright and Related+Rights in the Work or (ii) assert any associated claims and causes of+action with respect to the Work, in either case contrary to Affirmer's+express Statement of Purpose.++4. Limitations and Disclaimers.++ a. No trademark or patent rights held by Affirmer are waived, abandoned,+    surrendered, licensed or otherwise affected by this document.+ b. Affirmer offers the Work as-is and makes no representations or+    warranties of any kind concerning the Work, express, implied,+    statutory or otherwise, including without limitation warranties of+    title, merchantability, fitness for a particular purpose, non+    infringement, or the absence of latent or other defects, accuracy, or+    the present or absence of errors, whether or not discoverable, all to+    the greatest extent permissible under applicable law.+ c. Affirmer disclaims responsibility for clearing rights of other persons+    that may apply to the Work or any use thereof, including without+    limitation any person's Copyright and Related Rights in the Work.+    Further, Affirmer disclaims responsibility for obtaining any necessary+    consents, permissions or other rights required for any use of the+    Work.+ d. Affirmer understands and acknowledges that Creative Commons is not a+    party to this document and has no duty or obligation with respect to+    this CC0 or use of the Work.
+ ChangeLog view
@@ -0,0 +1,6 @@+If you have a local clone of the repository, you can see a detailed list of+changes using:++  $ git log++There is also a web interface in NotABug which can display commit history.
+ INSTALL view
@@ -0,0 +1,13 @@+Install from Hackage:++    $ cabal install funbot-ext-events++Install from unpacked release tarball or source repo:++    $ cd funbot-ext-events+    $ cabal install++Just play with it without installing:++    $ cabal build+    $ cabal repl
+ NEWS view
@@ -0,0 +1,23 @@+This file lists the user-visible interesting changes between releases. For a+full list of changes to the source, see the ChangeLog.++++funbot-ext-events 0.1.0.0 -- 2015-09-19+=======================================++General, build and documentation changes:++* (This is the first release, so everything is new)++New APIs, features and enhancements:++* (This is the first release, so everything is a new feature)++Bug fixes:++* (This is just the first release, many bugs haven't been discovered yet)++Dependency changes:++* (This is the first release)
+ README.md view
@@ -0,0 +1,35 @@+# funbot-ext-events++This is a Haskell library providing types and tools for interacting with+[FunBot][funbot]'s external events. The code was extracted from FunBot itself,+so that independent programs can interact with it using its client API.++Since the provided types change every time an external event type is added or+modified, many of this library's releases are expected to break compatibility.+In most cases you should either use a higher-level library such as+[funbot-client][funbot-client], or perhaps create one yourself.++[funbot]:        https://notabug.org/fr33domlover/funbot.git+[funbot-client]: https://notabug.org/fr33domlover/funbot-client.git++See the .cabal file for more info and link to project website and version+control.++The official download location is the Git repository:++<https://notabug.org/fr33domlover/funbot-ext-events.git>++Occasionally, releases may be made to Hackage, the Haskell package repository.+See <http://hackage.haskell.org/package/funbot-ext-events>.++This library is free software, and is committed to software freedom. It is+released to the public domain using the CC0 Public Domain Dedication. For the+boring "legal" details see the file `COPYING`.++See the file `INSTALL` for hints on installation. The file `ChangeLog` explains+how to see the history log of the changes done in the code. `NEWS` provides a+friendly overview of the changes for each release.++## Bug and Patches++See [here](https://notabug.org/fr33domlover/funbot#reporting-bugs-and-suggesting-features).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ funbot-ext-events.cabal view
@@ -0,0 +1,40 @@+name:                funbot-ext-events+version:             0.1.0.0+synopsis:            Interact with FunBot's external events.+description:+  This is a library providing types and tools for interacting with+  <https://notabug.org/fr33domlover/funbot.git FunBot>'s external events. The+  code was extracted from FunBot itself, so that independent programs can+  interact with it, e.g. by using its client API.++  Since the provided types change every time an external event type is added or+  modified, many of this library's releases are expected to break+  compatibility.  In most cases you should either use a higher-level library+  such as <https://notabug.org/fr33domlover/funbot-client.git funbot-client>,+  or perhaps create one yourself.+homepage:            https://notabug.org/fr33domlover/funbot-ext-events/+bug-reports:         https://notabug.org/fr33domlover/funbot-ext-events/issues/+license:             PublicDomain+license-file:        COPYING+author:              fr33domlover+maintainer:          fr33domlover@riseup.net+copyright:           ♡ Copying is an act of love. Please copy, reuse and share.+category:            Network, Web+build-type:          Simple+extra-source-files:  AUTHORS ChangeLog COPYING INSTALL NEWS README.md+cabal-version:       >=1.10++source-repository head+  type:                git+  location:            https://notabug.org/fr33domlover/funbot-ext-events.git++library+  exposed-modules:     FunBot.ExtEvents+  -- other-modules:       +  -- other-extensions:    +  build-depends:       aeson >=0.7+                     , base  >=4.7 && <5+                     , text+  hs-source-dirs:      src+  default-language:    Haskell2010+  ghc-options:         -Wall
+ src/FunBot/ExtEvents.hs view
@@ -0,0 +1,257 @@+{- This file is part of funbot-ext-events.+ -+ - Written in 2015 by fr33domlover <fr33domlover@rel4tion.org>.+ -+ - ♡ Copying is an act of love. Please copy, reuse and share.+ -+ - The author(s) have dedicated all copyright and related and neighboring+ - rights to this software to the public domain worldwide. This software is+ - distributed without any warranty.+ -+ - You should have received a copy of the CC0 Public Domain Dedication along+ - with this software. If not, see+ - <http://creativecommons.org/publicdomain/zero/1.0/>.+ -}++-- For json field names+{-# LANGUAGE OverloadedStrings #-}++module FunBot.ExtEvents+    ( Branch (..)+    , Commit (..)+    , Push (..)+    , Tag (..)+    , MergeRequest (..)+    , NewsItem (..)+    , Paste (..)+    , ExtEvent (..)+    )+where++import Control.Applicative+import Control.Monad (mzero)+import Data.Aeson+import Data.Aeson.Types (Parser)++import qualified Data.Text as T++data Branch = Branch+    { branchName      :: String+    , branchRepo      :: String+    , branchRepoOwner :: String+    }+    deriving Show++data Commit = Commit+    { commitAuthor :: String+    , commitTitle  :: String+    , commitUrl    :: String+    }+    deriving Show++data Push = Push+    { pushBranch  :: Branch+    , pushCommits :: [Commit]+    }+    deriving Show++data Tag = Tag+    { tagAuthor    :: String+    , tagRef       :: String+    , tagRepo      :: String+    , tagRepoOwner :: String+    }+    deriving Show++data MergeRequest = MergeRequest+    { mrAuthor    :: String+    , mrId        :: Int+    , mrRepo      :: String+    , mrRepoOwner :: String+    , mrTitle     :: String+    , mrUrl       :: String+    , mrAction    :: String+    }+    deriving Show++data NewsItem = NewsItem+    { itemFeedLabel :: String+    , itemFeedTitle :: Maybe String+    , itemTitle     :: String+    , itemAuthor    :: Maybe String+    , itemUrl       :: Maybe String+    }+    deriving Show++data Paste = Paste+    { pasteAuthor  :: String+    , pasteVerb    :: String+    , pasteTitle   :: String+    , pasteUrl     :: String+    , pasteChannel :: String+    }+    deriving Show++-- | An event coming from one of the external event sources.+data ExtEvent+    = GitPushEvent Push+    | GitTagEvent Tag+    | MergeRequestEvent MergeRequest+    | NewsEvent NewsItem+    | PasteEvent Paste+    deriving Show++instance FromJSON Branch where+    parseJSON (Object o) =+        Branch <$>+        o .: "name" <*>+        o .: "repo" <*>+        o .: "user"+    parseJSON _          = mzero++instance ToJSON Branch where+    toJSON (Branch name repo owner) = object+        [ "name" .= name+        , "repo" .= repo+        , "user" .= owner+        ]++instance FromJSON Commit where+    parseJSON (Object o) =+        Commit <$>+        o .: "author" <*>+        o .: "title" <*>+        o .: "url"+    parseJSON _          = mzero++instance ToJSON Commit where+    toJSON (Commit author title url) = object+        [ "author" .= author+        , "title"  .= title+        , "url"    .= url+        ]++instance FromJSON Push where+    parseJSON (Object o) =+        Push <$>+        o .: "branch" <*>+        o .: "commits"+    parseJSON _          = mzero++instance ToJSON Push where+    toJSON (Push branch commits) = object+        [ "branch"  .= branch+        , "commits" .= commits+        ]++instance FromJSON Tag where+    parseJSON (Object o) =+        Tag <$>+        o .: "author" <*>+        o .: "ref" <*>+        o .: "repo" <*>+        o .: "user"+    parseJSON _          = mzero++instance ToJSON Tag where+    toJSON tag = object+        [ "author" .= tagAuthor tag+        , "ref"    .= tagRef tag+        , "repo"   .= tagRepo tag+        , "user"   .= tagRepoOwner tag+        ]++instance FromJSON MergeRequest where+    parseJSON (Object o) =+        MergeRequest <$>+        o .: "author" <*>+        o .: "id" <*>+        o .: "repo" <*>+        o .: "user" <*>+        o .: "title" <*>+        o .: "url" <*>+        o .: "action"+    parseJSON _          = mzero++instance ToJSON MergeRequest where+    toJSON mr = object+        [ "author" .= mrAuthor mr+        , "id"     .= mrId mr+        , "repo"   .= mrRepo mr+        , "user"   .= mrRepoOwner mr+        , "title"  .= mrTitle mr+        , "url"    .= mrUrl mr+        , "action" .= mrAction mr+        ]++instance FromJSON NewsItem where+    parseJSON (Object o) =+        NewsItem <$>+        o .: "feed-label" <*>+        o .: "feed-title" <*>+        o .: "title" <*>+        o .: "author" <*>+        o .: "url"+    parseJSON _          = mzero++instance ToJSON NewsItem where+    toJSON (NewsItem fLabel fTitle title author url) = object+        [ "feed-label" .= fLabel+        , "feed-title" .= fTitle+        , "title"      .= title+        , "author"     .= author+        , "url"        .= url+        ]++instance FromJSON Paste where+    parseJSON (Object o) =+        Paste <$>+        o .: "author" <*>+        o .: "verb" <*>+        o .: "title" <*>+        o .: "url" <*>+        o .: "channel"+    parseJSON _          = mzero++instance ToJSON Paste where+    toJSON (Paste author verb title url chan) = object+        [ "author"  .= author+        , "verb"    .= verb+        , "title"   .= title+        , "url"     .= url+        , "channel" .= chan+        ]++text :: Parser T.Text -> T.Text -> Parser T.Text+text parser expected = do+    got <- parser+    if got == expected+        then return got+        else mzero++instance FromJSON ExtEvent where+    parseJSON (Object o) =+        let kind = text $ o .: "type"+        in  kind "push"  *> (GitPushEvent      <$> o .: "data") <|>+            kind "tag"   *> (GitTagEvent       <$> o .: "data") <|>+            kind "mr"    *> (MergeRequestEvent <$> o .: "data") <|>+            kind "news"  *> (NewsEvent         <$> o .: "data") <|>+            kind "paste" *> (PasteEvent        <$> o .: "data")+    parseJSON _          = mzero++instance ToJSON ExtEvent where+    toJSON (GitPushEvent commits) = object [ "type" .= ("push" :: T.Text)+                                           , "data" .= commits+                                           ]+    toJSON (GitTagEvent tag)      = object [ "type" .= ("tag" :: T.Text)+                                           , "data" .= tag+                                           ]+    toJSON (MergeRequestEvent mr) = object [ "type" .= ("mr" :: T.Text)+                                           , "data" .= mr+                                           ]+    toJSON (NewsEvent item)       = object [ "type" .= ("news" :: T.Text)+                                           , "data" .= item+                                           ]+    toJSON (PasteEvent paste)     = object [ "type" .= ("paste" :: T.Text)+                                           , "data" .= paste+                                           ]