Permalink
Browse files

added code to fetch all folders

  • Loading branch information...
1 parent 62dc542 commit 209d0b5a59ec001b4b4204e30a64256141e0e760 @nestal nestal committed Apr 29, 2013
View
7 bgrive/src/main.cc
@@ -23,7 +23,7 @@
#include <QtGui/QApplication>
#include <QtCore/QDebug>
-#include "drive2/Feed.hh"
+#include "drive2/Drive.hh"
#include "http/CurlAgent.hh"
#include "http/Header.hh"
@@ -72,11 +72,14 @@ int main( int argc, char **argv )
agent.Get( "https://www.googleapis.com/drive/v2/files", &jsp, http::Header() ) ;
std::cout << jsp.Response() << std::endl ;
*/
- Feed feed( "https://www.googleapis.com/drive/v2/files" ) ;
+/* Feed feed( "https://www.googleapis.com/drive/v2/files" ) ;
while ( feed.Next(&agent) )
{
std::cout << feed.Content() << std::endl ;
}
+*/
+ Drive drive ;
+ drive.Refresh( &agent ) ;
QApplication app( argc, argv ) ;
MainWnd wnd ;
View
27 libgrive/src/drive2/Drive.cc
@@ -20,15 +20,38 @@
#include "Drive.hh"
+#include "Feed.hh"
+#include "protocol/Json.hh"
+
+#include <iostream>
+
namespace gr { namespace v2 {
-Drive::Drive( ) :
- m_root( "", "", "" )
+Drive::Drive( )
{
}
void Drive::Refresh( http::Agent *agent )
{
+ // get all folders first
+ Feed folders(
+ "https://www.googleapis.com/drive/v2/files?q=mimeType+%3d+%27application/vnd.google-apps.folder%27" ) ;
+
+ while ( folders.Next( agent ) )
+ {
+ std::vector<Json> items = folders.Content()["items"].AsArray() ;
+ for ( std::vector<Json>::iterator i = items.begin() ; i != items.end() ; ++i )
+ {
+ const Resource *r = Add( *i ) ;
+ std::cout << r->Title() << " " << r->Mime() << std::endl ;
+ }
+ }
+}
+
+const Resource* Drive::Add( const Json& item )
+{
+ Resource *r = new Resource( item["id"].Str(), item["mimeType"].Str(), item["title"].Str() ) ;
+ return *m_db.insert(r).first ;
}
} } // end of namespace gr::v2
View
31 libgrive/src/drive2/Drive.hh
@@ -22,15 +22,41 @@
#include "Resource.hh"
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/identity.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+
namespace gr {
namespace http
{
class Agent ;
}
+class Json ;
+
namespace v2 {
+namespace details
+{
+ using namespace boost::multi_index ;
+ struct ByID {} ;
+ struct ByHref {} ;
+ struct ByIdentity {} ;
+
+ typedef multi_index_container<
+ Resource*,
+ indexed_by<
+ hashed_unique<tag<ByIdentity>, identity<Resource*> >,
+ hashed_non_unique<tag<ByID>, const_mem_fun<Resource, std::string, &Resource::ID> >
+ >
+ > DB ;
+
+ typedef DB::index<ByID>::type ID ;
+ typedef DB::index<ByIdentity>::type Set ;
+}
+
class Drive
{
public :
@@ -39,7 +65,10 @@ public :
void Refresh( http::Agent *agent ) ;
private :
- Resource m_root ;
+ const Resource* Add( const Json& item ) ;
+
+private :
+ details::DB m_db ;
} ;
} } // end of namespace gr::v2
View
13 libgrive/src/drive2/Resource.cc
@@ -22,6 +22,15 @@
namespace gr { namespace v2 {
+/** Default constructor construct the resource of the root folder
+*/
+Resource::Resource() :
+ m_id( "root" ),
+ m_mime( "application/vnd.google-apps.folder" ),
+ m_title( "Root folder" )
+{
+}
+
Resource::Resource( const std::string& id, const std::string& mime, const std::string& title ) :
m_id( id ),
m_mime( mime ),
@@ -49,9 +58,9 @@ bool Resource::IsFolder() const
return m_mime == "application/vnd.google-apps.folder" ;
}
-void Resource::Add( const Resource& child )
+void Resource::Add( const std::string& child_id )
{
- m_children.push_back( child ) ;
+ m_children.push_back( child_id ) ;
}
} } // end of namespace gr::v2
View
9 libgrive/src/drive2/Resource.hh
@@ -28,22 +28,23 @@ namespace gr { namespace v2 {
class Resource
{
public :
+ Resource() ;
Resource( const std::string& id, const std::string& mime, const std::string& title ) ;
std::string ID() const ;
std::string Mime() const ;
std::string Title() const ;
bool IsFolder() const ;
-
- void Add( const Resource& child ) ;
-
+
+ void Add( const std::string& child_id ) ;
+
private :
std::string m_id ;
std::string m_mime ;
std::string m_title ;
- std::vector<Resource> m_children ;
+ std::vector<std::string> m_children ;
} ;
} } // end of namespace gr::v2

0 comments on commit 209d0b5

Please sign in to comment.