Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit c41155c8081f8918aab83d950dcb306492dc9b69 Kannan Goundan committed Dec 29, 2011
Showing with 1,378 additions and 0 deletions.
  1. +82 −0 Examples/Simple.hs
  2. +17 −0 Examples/examples.cabal
  3. +20 −0 License.txt
  4. +25 −0 ReadMe.txt
  5. +2 −0 Setup.hs
  6. +851 −0 Source/Dropbox.hs
  7. +40 −0 dropbox-sdk.cabal
  8. +341 −0 trusted-certs.crt
@@ -0,0 +1,82 @@
+module Main where
+
+import qualified Dropbox as DB
+import System.Exit (exitFailure)
+import System.Environment (getArgs)
+import System.IO (hGetLine, hPutStrLn, stderr, stdout, stdin)
+import qualified Data.ByteString.Char8 as C8
+
+hostsDev = DB.Hosts "meta.dbdev.corp.dropbox.com" "api.dbdev.corp.dropbox.com" "api-content.dbdev.corp.dropbox.com"
+
+main :: IO ()
+main = do
+ args <- getArgs
+ case args of
+ [appKey, appSecret] -> mainProd appKey appSecret
+ _ -> do
+ putStrLn "Usage: COMMAND app-key app-secret"
+ exitFailure
+
+mainProd = main_ DB.hostsDefault
+
+mainDev = main_ hostsDev
+
+mkConfig hosts appKey appSecret = do
+ base <- DB.mkConfig DB.localeEn appKey appSecret DB.AccessTypeDropbox
+ return $ base { DB.configHosts = hosts }
+
+auth mgr config = do
+ -- OAuth
+ (requestToken, authUrl) <- DB.authStart mgr config Nothing
+ `dieOnFailure` "Couldn't get request token"
+ hPutStrLn stdout $ "Request Token: " ++ show requestToken
+ hPutStrLn stdout $ "Auth URL: " ++ authUrl
+ hGetLine stdin
+ (accessToken, userId) <- DB.authFinish mgr config requestToken
+ `dieOnFailure` "Couldn't get access token"
+ hPutStrLn stdout $ "Access Token: " ++ show accessToken
+ return accessToken
+
+accountInfo mgr session = do
+ accountInfo <- DB.getAccountInfo mgr session
+ `dieOnFailure` "Couldn't get account info"
+ hPutStrLn stdout $ "---- Account Info ----"
+ hPutStrLn stdout $ show accountInfo
+
+rootMetadata mgr session = do
+ (DB.Meta meta extra, mContents) <- DB.getMetadataWithChildren mgr session "/" Nothing
+ `dieOnFailure` "Couldn't get root folder listing"
+ (hash, children) <- case mContents of
+ Just (DB.FolderContents hash children) -> return (hash, children)
+ _ -> die "Root is not a folder? What the poop?"
+ hPutStrLn stdout $ "---- Files ----"
+ mapM_ ((hPutStrLn stdout).show) children
+ secondTime <- DB.getMetadataWithChildrenIfChanged mgr session "/" Nothing hash
+ `dieOnFailure` "Couldn't get root folder listing again"
+ hPutStrLn stdout (show secondTime) -- Will almost always print "Nothing" (i.e. "nothing has changed")
+
+addFile mgr session = do
+ DB.addFile mgr session "/Facts.txt" (DB.bsRequestBody $ C8.pack "Rian hates types.\n")
+ `dieOnFailure` "Couldn't add Facts.txt"
+
+main_ :: DB.Hosts -> String -> String -> IO ()
+main_ hosts appKey appSecret = do
+ config <- mkConfig hosts appKey appSecret
+ DB.withManager $ \mgr -> do
+ accessToken <- auth mgr config
+ let session = DB.Session config accessToken
+ accountInfo mgr session
+ rootMetadata mgr session
+ addFile mgr session
+ return ()
+
+dieOnFailure :: IO (Either String v) -> String -> IO v
+dieOnFailure action errorPrefix = do
+ ev <- action
+ case ev of
+ Left err -> die (errorPrefix ++ ": " ++ err)
+ Right result -> return result
+
+die message = do
+ hPutStrLn stderr message
+ exitFailure
@@ -0,0 +1,17 @@
+Name: dropbox-sdk-examples
+Version: 0.1
+Description: Examples that uses the dropbox-sdk package.
+License: MIT
+Author: Kannan Goundan
+Maintainer: kannan@dropbox.com
+Build-Type: Simple
+Cabal-Version: >= 1.10
+
+Executable simple
+ Build-Depends:
+ haskell2010 == 1.*,
+ bytestring == 0.9.*,
+ dropbox-sdk
+ Main-Is: Simple.hs
+ Default-Language: Haskell2010
+ Default-Extensions: ScopedTypeVariables, OverloadedStrings
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Dropbox Inc., http://www.dropbox.com/
+
+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.
@@ -0,0 +1,25 @@
+The beginnings of a Dropbox API for Haskell. Incomplete and not
+officially maintained by Dropbox.
+
+-------------------------
+Dependencies:
+
+Cabal 1.10+
+GHC 7+ (might work with earlier versions, but I haven't tested)
+
+-------------------------
+To Build:
+
+First, install all the depencies listed in dropbox-sdk.cabal
+
+Then:
+$ cabal configure
+$ cabal build
+
+-------------------------
+To Run Examples:
+
+$ cabal install (install the library, so the example can use it)
+$ cd Examples
+$ cabal build
+$ ./dist/build/simple/simple <app-key> <app-secret>
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
Oops, something went wrong.

0 comments on commit c41155c

Please sign in to comment.