Permalink
Browse files

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

… Google Drive API
  • Loading branch information...
1 parent 7384358 commit 62dc5423417b01da522a56afc965eb9cf9f7deac @nestal nestal committed Apr 29, 2013
View
@@ -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
@@ -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
@@ -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
@@ -20,12 +20,12 @@
#include "CommonUri.hh"
#include <boost/format.hpp>
-namespace gr {
+namespace gr { namespace v1 {
std::string ChangesFeed( int changestamp )
{
boost::format feed( feed_changes + "?start-index=%1%" ) ;
return changestamp > 0 ? (feed%changestamp).str() : feed_changes ;
}
-}
+} }
@@ -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 ) ;
-}
+} }
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 ) ;
}
@@ -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 ) ;
}
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
+
Oops, something went wrong.

0 comments on commit 62dc542

Please sign in to comment.