Browse Source

Merge pull request #1 from hallettj/pull-requests

PR looks good to me. (As a semi-relevant aside: I might eventually remove the non-Dynamic module and make Dynamic the primary way of interacting with the library. I hope that would make sense!)
G. D. Ritter 9 years ago
parent
commit
4eb40b37c0
2 changed files with 15 additions and 4 deletions
  1. 13 3
      Codec/ActivityStream/Dynamic.hs
  2. 2 1
      activitystreams-aeson.cabal

+ 13 - 3
Codec/ActivityStream/Dynamic.hs

@@ -47,6 +47,7 @@ module Codec.ActivityStream.Dynamic
        , acGenerator
        , acIcon
        , acId
+       , acObject
        , acPublished
        , acProvider
        , acTarget
@@ -56,6 +57,7 @@ module Codec.ActivityStream.Dynamic
        , acVerb
        , acRest
        , makeActivity
+       , asObject
          -- * Collection
        , Collection
        , cTotalItems
@@ -198,6 +200,9 @@ acIcon = makeAesonLensMb "icon" acRest
 acId :: Lens' Activity (Maybe Text)
 acId = makeAesonLensMb "id" acRest
 
+acObject :: Lens' Activity (Maybe Object)
+acObject = makeAesonLensMb "object" acRest
+
 acPublished :: Lens' Activity DateTime
 acPublished = makeAesonLens "published" acRest
 
@@ -221,13 +226,18 @@ acVerb = makeAesonLensMb "verb" acRest
 
 -- | Create an @Activity@ with an @actor@, @published@, and
 --   @provider@ property.
-makeActivity :: Object -> DateTime -> Object -> Activity
-makeActivity actor published provider = Activity
+makeActivity :: Object -> DateTime -> Activity
+makeActivity actor published = Activity
   $ HM.insert "actor"     (toJSON actor)
   $ HM.insert "published" (toJSON published)
-  $ HM.insert "provider"  (toJSON provider)
   $ HM.empty
 
+-- | JSON Activity Streams 1.0 specificies that an @Activity@ may be used as an
+--   @Object@. In such a case, the object may have fields permitted on either an
+--   @Activity@ or an @Object@
+asObject :: Activity -> Object
+asObject act = Object (fromActivity act)
+
 -- | Collection
 
 data Collection = Collection { fromCollection :: A.Object } deriving (Eq, Show)

+ 2 - 1
activitystreams-aeson.cabal

@@ -21,7 +21,8 @@ library
                        Codec.ActivityStream.Representation,
                        Codec.ActivityStream.Schema,
                        Codec.ActivityStream
-  other-modules:       Codec.ActivityStream.Internal
+  other-modules:       Codec.ActivityStream.Internal,
+                       Codec.ActivityStream.LensInternal
   build-depends:       base >=4.7 && <4.8,
                        aeson,
                        text,