packages feed

fb 0.3 → 0.3.1

raw patch · 6 files changed

+100/−24 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Facebook: createAction :: ResourceIO m => Action -> SimpleQuery -> AccessToken User -> FacebookT Auth m Id
+ Facebook: data Action
- Facebook: getObject :: ResourceIO m => Ascii -> SimpleQuery -> Maybe (AccessToken kind) -> FacebookT anyAuth m Value
+ Facebook: getObject :: (ResourceIO m, FromJSON a) => Ascii -> SimpleQuery -> Maybe (AccessToken kind) -> FacebookT anyAuth m a
- Facebook: postObject :: ResourceIO m => Ascii -> SimpleQuery -> AccessToken kind -> FacebookT Auth m Value
+ Facebook: postObject :: (ResourceIO m, FromJSON a) => Ascii -> SimpleQuery -> AccessToken kind -> FacebookT Auth m a

Files

fb.cabal view
@@ -1,5 +1,5 @@ name:              fb-version:           0.3+version:           0.3.1 license:           BSD3 license-file:      LICENSE author:            Felipe Lessa@@ -9,7 +9,7 @@ stability:         Experimental cabal-version:     >= 1.8 build-type:        Simple-homepage:          https://github.com/meteficha/facebook+homepage:          https://github.com/meteficha/fb  description:   This package exports bindings to Facebook's APIs (see@@ -45,6 +45,7 @@     Facebook.Base     Facebook.Auth     Facebook.Graph+    Facebook.OpenGraph   build-depends:       base               >= 4       && < 5     , lifted-base        >= 0.1     && < 0.2
src/Facebook.hs view
@@ -25,6 +25,10 @@     , getUserAccessTokenStep2     , extendUserAccessToken +      -- * Facebook's Open Graph API+    , createAction+    , Action+       -- * Raw access to the Graph API     , getObject     , postObject@@ -38,3 +42,4 @@ import Facebook.Base import Facebook.Auth import Facebook.Graph+import Facebook.OpenGraph
src/Facebook/Base.hs view
@@ -2,7 +2,6 @@     ( fbreq     , ToSimpleQuery(..)     , asJson-    , asJson'     , FacebookException(..)     , fbhttp     , httpCheck@@ -60,14 +59,14 @@   -- | Converts a plain 'H.Response' coming from 'H.http' into a--- response with a JSON value.+-- JSON value. asJson :: (C.ResourceThrow m, C.IsSource bsrc, A.FromJSON a) =>           H.Response (bsrc m ByteString)-       -> FacebookT anyAuth (C.ResourceT m) (H.Response a)-asJson (H.Response status headers body) = do-  val <- lift $ body C.$$ C.sinkParser A.json'+       -> FacebookT anyAuth (C.ResourceT m) a+asJson response = do+  val <- lift $ H.responseBody response C.$$ C.sinkParser A.json'   case A.fromJSON val of-    A.Success r -> return (H.Response status headers r)+    A.Success r -> return r     A.Error str ->         E.throw $ FbLibraryException $ T.concat              [ "Facebook.Base.asJson: could not parse "@@ -75,13 +74,6 @@              , T.pack str, ")" ]  --- | Same as 'asJson', but returns only the JSON value.-asJson' :: (C.ResourceThrow m, C.IsSource bsrc, A.FromJSON a) =>-           H.Response (bsrc m ByteString)-        -> FacebookT anyAuth (C.ResourceT m) a-asJson' = fmap H.responseBody . asJson-- -- | An exception that may be thrown by functions on this -- package.  Includes any information provided by Facebook. data FacebookException =@@ -115,7 +107,7 @@     then return response     else do       let statusexc = H.StatusCodeException status headers-      val <- E.try $ asJson' response+      val <- E.try $ asJson response       case val :: Either E.SomeException FacebookException of         Right fbexc -> E.throw fbexc         Left _ -> do
src/Facebook/Graph.hs view
@@ -1,14 +1,15 @@ module Facebook.Graph     ( getObject     , postObject+    , Id(..)     ) where  --- import Control.Applicative+import Control.Applicative -- import Control.Monad (mzero) -- import Data.ByteString.Char8 (ByteString) -- import Data.Text (Text)--- import Data.Typeable (Typeable, Typeable1)+import Data.Typeable (Typeable) import Network.HTTP.Types (Ascii)  -- import qualified Control.Exception.Lifted as E@@ -26,23 +27,32 @@  -- | Make a raw @GET@ request to Facebook's Graph API.  Returns a -- raw JSON 'A.Value'.-getObject :: C.ResourceIO m =>+getObject :: (C.ResourceIO m, A.FromJSON a) =>              Ascii          -- ^ Path (should begin with a slash @\/@)           -> HT.SimpleQuery -- ^ Arguments to be passed to Facebook           -> Maybe (AccessToken kind) -- ^ Optional access token-          -> FacebookT anyAuth m A.Value+          -> FacebookT anyAuth m a getObject path query mtoken =   runResourceInFb $-    asJson' =<< fbhttp (fbreq path mtoken query)+    asJson =<< fbhttp (fbreq path mtoken query)   -- | Make a raw @POST@ request to Facebook's Graph API.  Returns -- a raw JSON 'A.Value'.-postObject :: C.ResourceIO m =>+postObject :: (C.ResourceIO m, A.FromJSON a) =>               Ascii            -- ^ Path (should begin with a slash @\/@)            -> HT.SimpleQuery   -- ^ Arguments to be passed to Facebook            -> AccessToken kind -- ^ Access token-           -> FacebookT Auth m A.Value+           -> FacebookT Auth m a postObject path query token =   runResourceInFb $-    asJson' =<< fbhttp (fbreq path (Just token) query) { H.method = HT.methodPost }+    asJson =<< fbhttp (fbreq path (Just token) query) { H.method = HT.methodPost }+++-- | The identification code of an object.+newtype Id = Id { idCode :: Ascii }+    deriving (Eq, Ord, Show, Typeable)++instance A.FromJSON Id where+    parseJSON (A.Object v) = Id <$> v A..: "id"+    parseJSON other        = Id <$> A.parseJSON other
+ src/Facebook/OpenGraph.hs view
@@ -0,0 +1,61 @@+module Facebook.OpenGraph+    ( createAction+    , Action(..)+    ) where++-- import Control.Applicative+-- import Control.Monad (mzero)+-- import Data.ByteString.Char8 (ByteString)+-- import Data.Text (Text)+-- import Data.Typeable (Typeable, Typeable1)+import Data.String (IsString(..))+import Network.HTTP.Types (Ascii)++-- import qualified Control.Exception.Lifted as E+-- import qualified Data.Aeson as A+import qualified Data.Conduit as C+-- import qualified Data.Text as T+import qualified Network.HTTP.Types as HT+++import Facebook.Types+import Facebook.Monad+-- import Facebook.Base+import Facebook.Graph+++-- | Creates an Open Graph action on the user's timeline. Returns+-- the 'Id' of the newly created action.+createAction :: C.ResourceIO m =>+                Action               -- ^ Action kind to be created.+             -> HT.SimpleQuery       -- ^ Arguments of the action.+             -> AccessToken User+             -> FacebookT Auth m Id+createAction (Action action) query token = do+  creds <- getCreds+  postObject ("/me/" <> appName creds <> ":" <> action) query token+++-- | An action of your app.  Please refer to Facebook's+-- documentation at+-- <https://developers.facebook.com/docs/opengraph/keyconcepts/#actions-objects>+-- to see how you can create actions.+--+-- This is a @newtype@ of 'Ascii' that supports only 'IsString'.+-- This means that to create an 'Action' you should use the+-- @OverloadedStrings@ language extension.  For example,+--+-- > {-# LANGUAGE OverloadedStrings #-}+-- >+-- > foo token = do+-- >   ...+-- >   createAction "cook" [...] token+newtype Action = Action { unAction :: Ascii }++instance Show Action where+    show = show . unAction++instance IsString Action where+    fromString = Action . fromString++
src/Facebook/Types.hs view
@@ -6,8 +6,10 @@     , accessTokenExpires     , User     , App+    , (<>)     ) where +import Data.Monoid (Monoid, mappend) import Data.Time (UTCTime) import Data.Typeable (Typeable, Typeable1) import Network.HTTP.Types (Ascii)@@ -70,3 +72,8 @@ -- | Phantom type used mark an 'AccessToken' as an app access -- token. data App deriving (Typeable)+++-- | Synonym for 'mappend'.+(<>) :: Monoid a => a -> a -> a+(<>) = mappend