Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored old GDoc API into v1 namespace. using v2 namespace for new…

… Google Drive API
  • Loading branch information...
commit 62dc5423417b01da522a56afc965eb9cf9f7deac 1 parent 7384358
@nestal nestal authored
Showing with 375 additions and 36 deletions.
  1. +15 −5 bgrive/src/main.cc
  2. +1 −0  grive/src/main.cc
  3. +2 −1  libgrive/CMakeLists.txt
  4. +2 −2 libgrive/src/drive/CommonUri.cc
  5. +2 −2 libgrive/src/drive/CommonUri.hh
  6. +4 −4 libgrive/src/drive/Drive.cc
  7. +4 −2 libgrive/src/drive/Drive.hh
  8. +2 −2 libgrive/src/drive/Entry.cc
  9. +3 −1 libgrive/src/drive/Entry.hh
  10. +2 −2 libgrive/src/drive/Feed.cc
  11. +3 −1 libgrive/src/drive/Feed.hh
  12. +3 −3 libgrive/src/drive/Resource.cc
  13. +6 −3 libgrive/src/drive/Resource.hh
  14. +2 −2 libgrive/src/drive/ResourceTree.cc
  15. +3 −1 libgrive/src/drive/ResourceTree.hh
  16. +3 −3 libgrive/src/drive/State.cc
  17. +4 −1 libgrive/src/drive/State.hh
  18. +35 −0 libgrive/src/drive2/Drive.cc
  19. +45 −0 libgrive/src/drive2/Drive.hh
  20. +66 −0 libgrive/src/drive2/Feed.cc
  21. +55 −0 libgrive/src/drive2/Feed.hh
  22. +57 −0 libgrive/src/drive2/Resource.cc
  23. +49 −0 libgrive/src/drive2/Resource.hh
  24. +3 −1 libgrive/src/protocol/Json.cc
  25. +1 −0  libgrive/test/drive/EntryTest.cc
  26. +1 −0  libgrive/test/drive/ResourceTest.cc
  27. +1 −0  libgrive/test/drive/ResourceTreeTest.cc
  28. +1 −0  libgrive/test/drive/StateTest.cc
View
20 bgrive/src/main.cc
@@ -23,13 +23,11 @@
#include <QtGui/QApplication>
#include <QtCore/QDebug>
-#include "drive/CommonUri.hh"
-#include "drive/Entry.hh"
-#include "drive/Feed.hh"
+#include "drive2/Feed.hh"
#include "http/CurlAgent.hh"
#include "http/Header.hh"
-//#include "http/XmlResponse.hh"
+#include "protocol/JsonResponse.hh"
#include "protocol/Json.hh"
#include "protocol/OAuth2.hh"
@@ -38,11 +36,13 @@
#include "util/File.hh"
#include <string>
+#include <iostream>
const std::string client_id = "22314510474.apps.googleusercontent.com" ;
const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ;
using namespace gr ;
+using namespace gr::v2 ;
int main( int argc, char **argv )
{
@@ -55,7 +55,7 @@ int main( int argc, char **argv )
OAuth2 token( refresh_token, client_id, client_secret ) ;
AuthAgent agent( token, std::auto_ptr<http::Agent>( new http::CurlAgent ) ) ;
- Feed feed ;
+/* Feed feed ;
feed.Start( &agent, feed_base + "/-/folder?max-results=50&showroot=true" ) ;
do
@@ -67,6 +67,16 @@ int main( int argc, char **argv )
qDebug() << e.Name().c_str() ;
}
} while ( feed.GetNext( &agent ) ) ;
+*/
+/* http::JsonResponse jsp ;
+ 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" ) ;
+ while ( feed.Next(&agent) )
+ {
+ std::cout << feed.Content() << std::endl ;
+ }
QApplication app( argc, argv ) ;
MainWnd wnd ;
View
1  grive/src/main.cc
@@ -48,6 +48,7 @@ const std::string client_id = "22314510474.apps.googleusercontent.com" ;
const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ;
using namespace gr ;
+using namespace gr::v1 ;
namespace po = boost::program_options;
// libgcrypt insist this to be done in application, not library
View
3  libgrive/CMakeLists.txt
@@ -45,7 +45,7 @@ include_directories(
)
file(GLOB DRIVE_HEADERS
- ${libgrive_SOURCE_DIR}/src/drive/*.hh
+ ${libgrive_SOURCE_DIR}/src/drive/*.hh
)
file (GLOB PROTOCOL_HEADERS
@@ -62,6 +62,7 @@ file (GLOB XML_HEADERS
file (GLOB LIBGRIVE_SRC
src/drive/*.cc
+ src/drive2/*.cc
src/http/*.cc
src/protocol/*.cc
src/util/*.cc
View
4 libgrive/src/drive/CommonUri.cc
@@ -20,7 +20,7 @@
#include "CommonUri.hh"
#include <boost/format.hpp>
-namespace gr {
+namespace gr { namespace v1 {
std::string ChangesFeed( int changestamp )
{
@@ -28,4 +28,4 @@ std::string ChangesFeed( int changestamp )
return changestamp > 0 ? (feed%changestamp).str() : feed_changes ;
}
-}
+} }
View
4 libgrive/src/drive/CommonUri.hh
@@ -21,7 +21,7 @@
#include <string>
-namespace gr
+namespace gr { namespace v1
{
const std::string feed_base = "https://docs.google.com/feeds/default/private/full" ;
const std::string feed_changes = "https://docs.google.com/feeds/default/private/changes" ;
@@ -33,4 +33,4 @@ namespace gr
"https://docs.google.com/feeds/upload/create-session/default/private/full" ;
std::string ChangesFeed( int changestamp ) ;
-}
+} }
View
8 libgrive/src/drive/Drive.cc
@@ -44,15 +44,15 @@
// for debugging only
#include <iostream>
-namespace gr {
+namespace gr { namespace v1 {
namespace
{
const std::string state_file = ".grive_state" ;
}
-Drive::Drive( http::Agent *http, const Json& options ) :
- m_http ( http ),
+Drive::Drive( http::Agent *agent, const Json& options ) :
+ m_http ( agent ),
m_root ( options["path"].Str() ),
m_state ( m_root / state_file, options ),
m_options ( options )
@@ -197,4 +197,4 @@ void Drive::UpdateChangeStamp( )
std::atoi(xrsp.Response()["docs:largestChangestamp"]["@value"].front().Value().c_str()) ) ;
}
-} // end of namespace
+} } // end of namespace gr::v1
View
6 libgrive/src/drive/Drive.hh
@@ -35,12 +35,14 @@ namespace http
class Agent ;
}
+namespace v1 {
+
class Entry ;
class Drive
{
public :
- Drive( http::Agent *http, const Json& options ) ;
+ Drive( http::Agent *agent, const Json& options ) ;
void DetectChanges() ;
void Update() ;
@@ -64,4 +66,4 @@ private :
Json m_options ;
} ;
-} // end of namespace
+} } // end of namespace
View
4 libgrive/src/drive/Entry.cc
@@ -29,7 +29,7 @@
#include <algorithm>
#include <iterator>
-namespace gr {
+namespace gr { namespace v1 {
/// construct an entry for the root folder
Entry::Entry( ) :
@@ -195,4 +195,4 @@ std::string Entry::Name() const
return (m_kind == "file" || m_kind == "pdf") ? m_filename : m_title ;
}
-} // end of namespace
+} } // end of namespace gr::v1
View
4 libgrive/src/drive/Entry.hh
@@ -33,6 +33,8 @@ namespace xml
class Node ;
}
+namespace v1 {
+
/*! \brief corresponds to an "entry" in the resource feed
This class is decodes an entry in the resource feed. It will stored the properties like
@@ -95,4 +97,4 @@ private :
bool m_is_removed ;
} ;
-} // end of namespace
+} } // end of namespace gr::v1
View
4 libgrive/src/drive/Feed.cc
@@ -29,7 +29,7 @@
#include <cassert>
-namespace gr {
+namespace gr { namespace v1 {
Feed::Feed( )
{
@@ -123,4 +123,4 @@ const xml::Node& Feed::Root() const
return m_root ;
}
-} // end of namespace
+} } // end of namespace gr::v1
View
4 libgrive/src/drive/Feed.hh
@@ -36,6 +36,8 @@ namespace http
class Header ;
}
+namespace v1 {
+
class Feed
{
public :
@@ -88,4 +90,4 @@ private :
reference dereference() const ;
} ;
-} // end of namespace
+} } // end of namespace
View
6 libgrive/src/drive/Resource.cc
@@ -45,7 +45,7 @@
// for debugging
#include <iostream>
-namespace gr {
+namespace gr { namespace v1 {
// hard coded XML file
const std::string xml_meta =
@@ -668,11 +668,11 @@ bool Resource::HasID() const
return !m_href.empty() && !m_id.empty() ;
}
-} // end of namespace
+} } // end of namespace
namespace std
{
- void swap( gr::Resource& c1, gr::Resource& c2 )
+ void swap( gr::v1::Resource& c1, gr::v1::Resource& c2 )
{
c1.Swap( c2 ) ;
}
View
9 libgrive/src/drive/Resource.hh
@@ -34,9 +34,12 @@ namespace http
class Agent ;
}
-class Entry ;
class Json ;
+namespace v1 {
+
+class Entry ;
+
/*! \brief A resource can be a file or a folder in the google drive
The google drive contains a number of resources, which is represented by this class.
@@ -158,9 +161,9 @@ private :
State m_state ;
} ;
-} // end of namespace
+} } // end of namespace gr::v1
namespace std
{
- void swap( gr::Resource& c1, gr::Resource& c2 ) ;
+ void swap( gr::v1::Resource& c1, gr::v1::Resource& c2 ) ;
}
View
4 libgrive/src/drive/ResourceTree.cc
@@ -27,7 +27,7 @@
#include <algorithm>
#include <cassert>
-namespace gr {
+namespace gr { namespace v1 {
using namespace details ;
@@ -155,4 +155,4 @@ ResourceTree::iterator ResourceTree::end()
return m_set.get<ByIdentity>().end() ;
}
-} // end of namespace
+} } // end of namespace gr::v1
View
4 libgrive/src/drive/ResourceTree.hh
@@ -32,6 +32,8 @@ namespace gr {
class Json ;
+namespace v1 {
+
namespace details
{
using namespace boost::multi_index ;
@@ -96,4 +98,4 @@ private :
Resource* m_root ;
} ;
-} // end of namespace
+} } // end of namespace gr::v1
View
6 libgrive/src/drive/State.cc
@@ -31,7 +31,7 @@
#include <fstream>
-namespace gr {
+namespace gr { namespace v1 {
State::State( const fs::path& filename, const Json& options ) :
m_res ( options["path"].Str() ),
@@ -63,7 +63,7 @@ bool State::IsIgnore( const std::string& filename )
return filename[0] == '.' ;
}
-void State::FromLocal( const fs::path& p, gr::Resource* folder )
+void State::FromLocal( const fs::path& p, Resource* folder )
{
assert( folder != 0 ) ;
assert( folder->IsFolder() ) ;
@@ -294,4 +294,4 @@ void State::ChangeStamp( long cstamp )
m_cstamp = cstamp ;
}
-} // end of namespace
+} } // end of namespace gr::v1
View
5 libgrive/src/drive/State.hh
@@ -34,6 +34,9 @@ namespace http
}
class Json ;
+
+namespace v1 {
+
class Resource ;
class Entry ;
@@ -80,4 +83,4 @@ private :
std::vector<Entry> m_unresolved ;
} ;
-} // end of namespace
+} } // end of namespace gr::v1
View
35 libgrive/src/drive2/Drive.cc
@@ -0,0 +1,35 @@
+/*
+ grive: an GPL program to sync a local directory with Google Drive
+ Copyright (C) 2013 Wan Wai Ho
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+*/
+
+#include "Drive.hh"
+
+namespace gr { namespace v2 {
+
+Drive::Drive( ) :
+ m_root( "", "", "" )
+{
+}
+
+void Drive::Refresh( http::Agent *agent )
+{
+}
+
+} } // end of namespace gr::v2
+
View
45 libgrive/src/drive2/Drive.hh
@@ -0,0 +1,45 @@
+/*
+ grive: an GPL program to sync a local directory with Google Drive
+ Copyright (C) 2013 Wan Wai Ho
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+*/
+
+#pragma once
+
+#include "Resource.hh"
+
+namespace gr {
+
+namespace http
+{
+ class Agent ;
+}
+
+namespace v2 {
+
+class Drive
+{
+public :
+ Drive( ) ;
+
+ void Refresh( http::Agent *agent ) ;
+
+private :
+ Resource m_root ;
+} ;
+
+} } // end of namespace gr::v2
View
66 libgrive/src/drive2/Feed.cc
@@ -0,0 +1,66 @@
+/*
+ grive: an GPL program to sync a local directory with Google Drive
+ Copyright (C) 2012 Wan Wai Ho
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include "Feed.hh"
+
+#include "http/Agent.hh"
+#include "http/Header.hh"
+#include "protocol/JsonResponse.hh"
+
+#include <iostream>
+
+namespace gr { namespace v2 {
+
+Feed::Feed( const std::string& base )
+{
+ // Next() will grab this link
+ m_content.Add( "nextLink", Json(base) ) ;
+
+ Json url ;
+ m_content.Get("nextLink", url) ;
+ std::cout << "link = " << url.Str() << std::endl ;
+}
+
+bool Feed::Next( http::Agent *agent )
+{
+ Json url ;
+ if ( !m_content.Get("nextLink", url) )
+ return false ;
+
+ http::JsonResponse out ;
+ try
+ {
+ agent->Get( url.Str(), &out, http::Header() ) ;
+ }
+ catch ( Exception& e )
+ {
+ e << DriveFeed_( m_content ) ;
+ throw ;
+ }
+ m_content = out.Response() ;
+
+ return true ;
+}
+
+Json Feed::Content() const
+{
+ return m_content ;
+}
+
+} } // end of namespace
View
55 libgrive/src/drive2/Feed.hh
@@ -0,0 +1,55 @@
+/*
+ grive: an GPL program to sync a local directory with Google Drive
+ Copyright (C) 2012 Wan Wai Ho
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#pragma once
+
+#include "protocol/Json.hh"
+#include "util/Exception.hh"
+
+#include <string>
+
+namespace gr
+{
+namespace http
+{
+ class Agent ;
+ class Header ;
+}
+
+class Json ;
+
+namespace v2 {
+
+class Feed
+{
+public :
+ // exception info
+ typedef boost::error_info<struct DriveFeed, Json> DriveFeed_ ;
+
+public :
+ Feed( const std::string& base ) ;
+ bool Next( http::Agent *agent ) ;
+
+ Json Content() const ;
+
+private :
+ Json m_content ;
+} ;
+
+} } // end of namespace gr::v2
View
57 libgrive/src/drive2/Resource.cc
@@ -0,0 +1,57 @@
+/*
+ grive: an GPL program to sync a local directory with Google Drive
+ Copyright (C) 2013 Wan Wai Ho
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+*/
+
+#include "Resource.hh"
+
+namespace gr { namespace v2 {
+
+Resource::Resource( const std::string& id, const std::string& mime, const std::string& title ) :
+ m_id( id ),
+ m_mime( mime ),
+ m_title( title )
+{
+}
+
+std::string Resource::ID() const
+{
+ return m_id ;
+}
+
+std::string Resource::Mime() const
+{
+ return m_mime ;
+}
+
+std::string Resource::Title() const
+{
+ return m_title ;
+}
+
+bool Resource::IsFolder() const
+{
+ return m_mime == "application/vnd.google-apps.folder" ;
+}
+
+void Resource::Add( const Resource& child )
+{
+ m_children.push_back( child ) ;
+}
+
+} } // end of namespace gr::v2
View
49 libgrive/src/drive2/Resource.hh
@@ -0,0 +1,49 @@
+/*
+ grive: an GPL program to sync a local directory with Google Drive
+ Copyright (C) 2013 Wan Wai Ho
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+*/
+
+#pragma once
+
+#include <string>
+#include <vector>
+
+namespace gr { namespace v2 {
+
+class Resource
+{
+public :
+ 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 ) ;
+
+private :
+ std::string m_id ;
+ std::string m_mime ;
+ std::string m_title ;
+
+ std::vector<Resource> m_children ;
+} ;
+
+} } // end of namespace gr::v2
View
4 libgrive/src/protocol/Json.cc
@@ -63,9 +63,11 @@ Json::Json( const char *str ) :
) ;
}
+/** Note that json_object_new_string_len() is not used.
+*/
struct json_object* Json::InitStr( const char *str, std::size_t n )
{
- struct json_object *j = ::json_object_new_string_len( str, n ) ;
+ struct json_object *j = ::json_object_new_string( str ) ;
if ( j == 0 )
BOOST_THROW_EXCEPTION(
Error()
View
1  libgrive/test/drive/EntryTest.cc
@@ -31,6 +31,7 @@
namespace grut {
using namespace gr ;
+using namespace gr::v1 ;
EntryTest::EntryTest( )
{
View
1  libgrive/test/drive/ResourceTest.cc
@@ -31,6 +31,7 @@
namespace grut {
using namespace gr ;
+using namespace gr::v1 ;
ResourceTest::ResourceTest( )
{
View
1  libgrive/test/drive/ResourceTreeTest.cc
@@ -29,6 +29,7 @@
namespace grut {
using namespace gr ;
+using namespace gr::v1 ;
ResourceTreeTest::ResourceTreeTest( )
{
View
1  libgrive/test/drive/StateTest.cc
@@ -30,6 +30,7 @@
namespace grut {
using namespace gr ;
+using namespace gr::v1 ;
StateTest::StateTest( )
{
Please sign in to comment.
Something went wrong with that request. Please try again.