mirror of https://github.com/vitalif/grive2
Merge branch 'v0.0.4' into working
Conflicts: libgrive/src/drive/Drive.ccpull/40/head
commit
7363c7a49a
|
@ -53,28 +53,21 @@ Drive::Drive( OAuth2& auth ) :
|
||||||
m_http_hdr.push_back( "Authorization: Bearer " + m_auth.AccessToken() ) ;
|
m_http_hdr.push_back( "Authorization: Bearer " + m_auth.AccessToken() ) ;
|
||||||
m_http_hdr.push_back( "GData-Version: 3.0" ) ;
|
m_http_hdr.push_back( "GData-Version: 3.0" ) ;
|
||||||
|
|
||||||
|
http::Agent http ;
|
||||||
|
ConstructDirTree( &http ) ;
|
||||||
|
|
||||||
http::JsonResponse str ;
|
http::JsonResponse str ;
|
||||||
http::Agent agent ;
|
http.Get( root_url + "?alt=json&showfolders=true", &str, m_http_hdr ) ;
|
||||||
agent.Get( root_url + "?alt=json&showfolders=true", &str, m_http_hdr ) ;
|
|
||||||
Json resp = str.Response() ;
|
Json resp = str.Response() ;
|
||||||
/*
|
|
||||||
http::XmlResponse xml ;
|
|
||||||
agent.Get( root_url, &xml, m_http_hdr ) ;
|
|
||||||
xml::Node nroot = xml.Response() ;
|
|
||||||
*/
|
|
||||||
Json resume_link ;
|
Json resume_link ;
|
||||||
if ( resp["feed"]["link"].FindInArray( "rel", "http://schemas.google.com/g/2005#resumable-create-media", resume_link ) )
|
if ( resp["feed"]["link"].FindInArray( "rel", "http://schemas.google.com/g/2005#resumable-create-media", resume_link ) )
|
||||||
m_resume_link = resume_link["href"].As<std::string>() ;
|
m_resume_link = resume_link["href"].As<std::string>() ;
|
||||||
/*
|
|
||||||
std::string next_link ;
|
|
||||||
Json next_link_json ;
|
|
||||||
if ( resp["feed"]["link"].FindInArray( "rel", "next", next_link_json ) )
|
|
||||||
next_link = next_link_json["href"].As<std::string>() ;
|
|
||||||
std::cout << "next link = " << next_link << std::endl ;
|
|
||||||
*/
|
|
||||||
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
|
|
||||||
ConstructDirTree( entries ) ;
|
|
||||||
|
|
||||||
|
bool has_next = false ;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
|
||||||
for ( Json::Array::iterator i = entries.begin() ; i != entries.end() ; ++i )
|
for ( Json::Array::iterator i = entries.begin() ; i != entries.end() ; ++i )
|
||||||
{
|
{
|
||||||
if ( !Collection::IsCollection( *i ) )
|
if ( !Collection::IsCollection( *i ) )
|
||||||
|
@ -82,6 +75,16 @@ std::cout << "next link = " << next_link << std::endl ;
|
||||||
UpdateFile( *i ) ;
|
UpdateFile( *i ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json next ;
|
||||||
|
has_next = resp["feed"]["link"].FindInArray( "rel", "next", next ) ;
|
||||||
|
|
||||||
|
if ( has_next )
|
||||||
|
{
|
||||||
|
http.Get( next["href"].Str(), &str, m_http_hdr ) ;
|
||||||
|
resp = str.Response() ;
|
||||||
|
}
|
||||||
|
} while ( has_next ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Drive::~Drive( )
|
Drive::~Drive( )
|
||||||
|
@ -109,10 +112,18 @@ Drive::FolderListIterator Drive::FindFolder( const std::string& href )
|
||||||
return (it != m_coll.end() && it->Href() == href) ? it : m_coll.end() ;
|
return (it != m_coll.end() && it->Href() == href) ? it : m_coll.end() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drive::ConstructDirTree( const std::vector<Json>& entries )
|
void Drive::ConstructDirTree( http::Agent *http )
|
||||||
{
|
{
|
||||||
|
http::JsonResponse jrsp ;
|
||||||
|
http->Get( root_url + "/-/folder?alt=json", &jrsp, m_http_hdr ) ;
|
||||||
|
Json resp = jrsp.Response() ;
|
||||||
|
|
||||||
assert( m_coll.empty() ) ;
|
assert( m_coll.empty() ) ;
|
||||||
|
|
||||||
std::map<std::string, std::string> parent_href ;
|
std::map<std::string, std::string> parent_href ;
|
||||||
|
while ( true )
|
||||||
|
{
|
||||||
|
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
|
||||||
|
|
||||||
// first, get all collections from the query result
|
// first, get all collections from the query result
|
||||||
for ( Json::Array::const_iterator i = entries.begin() ; i != entries.end() ; ++i )
|
for ( Json::Array::const_iterator i = entries.begin() ; i != entries.end() ; ++i )
|
||||||
|
@ -128,6 +139,14 @@ void Drive::ConstructDirTree( const std::vector<Json>& entries )
|
||||||
}
|
}
|
||||||
assert( m_coll.size() == parent_href.size() ) ;
|
assert( m_coll.size() == parent_href.size() ) ;
|
||||||
|
|
||||||
|
Json next ;
|
||||||
|
if ( !resp["feed"]["link"].FindInArray( "rel", "next", next ) )
|
||||||
|
break ;
|
||||||
|
|
||||||
|
http->Get( next["href"].Str(), &jrsp, m_http_hdr ) ;
|
||||||
|
resp = jrsp.Response() ;
|
||||||
|
}
|
||||||
|
|
||||||
// second, build up linkage between parent and child
|
// second, build up linkage between parent and child
|
||||||
std::sort( m_coll.begin(), m_coll.end(), SortCollectionByHref() ) ;
|
std::sort( m_coll.begin(), m_coll.end(), SortCollectionByHref() ) ;
|
||||||
for ( FolderListIterator i = m_coll.begin() ; i != m_coll.end() ; ++i )
|
for ( FolderListIterator i = m_coll.begin() ; i != m_coll.end() ; ++i )
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
|
|
||||||
namespace gr {
|
namespace gr {
|
||||||
|
|
||||||
|
namespace http
|
||||||
|
{
|
||||||
|
class Agent ;
|
||||||
|
}
|
||||||
|
|
||||||
class OAuth2 ;
|
class OAuth2 ;
|
||||||
class Json ;
|
class Json ;
|
||||||
|
|
||||||
|
@ -42,7 +47,7 @@ public :
|
||||||
private :
|
private :
|
||||||
void UpdateFile( const Json& entry ) ;
|
void UpdateFile( const Json& entry ) ;
|
||||||
|
|
||||||
void ConstructDirTree( const std::vector<Json>& entries ) ;
|
void ConstructDirTree( http::Agent *http ) ;
|
||||||
|
|
||||||
FolderListIterator FindFolder( const std::string& href ) ;
|
FolderListIterator FindFolder( const std::string& href ) ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue