mirror of https://github.com/vitalif/grive2
adding the Feed class
parent
8466095e7b
commit
5cba612084
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "CommonUri.hh"
|
||||
#include "Entry.hh"
|
||||
#include "Feed.hh"
|
||||
|
||||
#include "http/Agent.hh"
|
||||
#include "http/ResponseLog.hh"
|
||||
|
@ -83,14 +84,15 @@ Drive::Drive( OAuth2& auth, const Json& options ) :
|
|||
m_resume_link = resp["link"].
|
||||
Find( "@rel", "http://schemas.google.com/g/2005#resumable-create-media" )["@href"] ;
|
||||
|
||||
bool has_next = false ;
|
||||
// bool has_next = false ;
|
||||
Feed feed( resp ) ;
|
||||
do
|
||||
{
|
||||
xml::NodeSet entries = resp["entry"] ;
|
||||
for ( xml::NodeSet::iterator i = entries.begin() ; i != entries.end() ; ++i )
|
||||
// xml::NodeSet entries = resp["entry"] ;
|
||||
for ( Feed::iterator i = feed.begin() ; i != feed.end() ; ++i )
|
||||
{
|
||||
if ( (*i)["content"] == "" )
|
||||
continue ;
|
||||
// if ( (*i)["content"] == "" )
|
||||
// continue ;
|
||||
|
||||
Entry entry( *i ) ;
|
||||
if ( entry.Kind() != "folder" )
|
||||
|
@ -116,15 +118,16 @@ Drive::Drive( OAuth2& auth, const Json& options ) :
|
|||
}
|
||||
}
|
||||
|
||||
xml::NodeSet nss = resp["link"].Find( "@rel", "next" ) ;
|
||||
has_next = !nss.empty() ;
|
||||
// xml::NodeSet nss = resp["link"].Find( "@rel", "next" ) ;
|
||||
// has_next = !nss.empty() ;
|
||||
|
||||
if ( has_next )
|
||||
{
|
||||
http.Get( nss["@href"], &xrsp, m_http_hdr ) ;
|
||||
resp = xrsp.Response() ;
|
||||
}
|
||||
} while ( has_next ) ;
|
||||
// std::string next_uri = feed.Next() ;
|
||||
// if ( !next_uri.empty() )
|
||||
// {
|
||||
// http.Get( next_uri, &xrsp, m_http_hdr ) ;
|
||||
// resp = xrsp.Response() ;
|
||||
// }
|
||||
} while ( feed.GetNext( &http, m_http_hdr ) ) ;
|
||||
|
||||
// pull the changes feed
|
||||
boost::format changes_uri( "https://docs.google.com/feeds/default/private/changes?start-index=%1%" ) ;
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
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/XmlResponse.hh"
|
||||
#include "xml/NodeSet.hh"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gr {
|
||||
|
||||
Feed::Feed( const xml::Node& root ) :
|
||||
m_root ( root ),
|
||||
m_entries ( m_root["entry"] )
|
||||
{
|
||||
}
|
||||
|
||||
Feed::iterator Feed::begin() const
|
||||
{
|
||||
return iterator( m_entries.begin() ) ;
|
||||
}
|
||||
|
||||
Feed::iterator Feed::end() const
|
||||
{
|
||||
return iterator( m_entries.end() ) ;
|
||||
}
|
||||
|
||||
std::string Feed::Next() const
|
||||
{
|
||||
xml::NodeSet nss = m_root["link"].Find( "@rel", "next" ) ;
|
||||
return nss.empty() ? "" : std::string(nss["@href"]) ;
|
||||
}
|
||||
|
||||
bool Feed::GetNext( http::Agent *http, const http::Header& auth )
|
||||
{
|
||||
assert( http != 0 ) ;
|
||||
|
||||
xml::NodeSet nss = m_root["link"].Find( "@rel", "next" ) ;
|
||||
if ( !nss.empty() )
|
||||
{
|
||||
http::XmlResponse xrsp ;
|
||||
http->Get( nss["@href"], &xrsp, auth ) ;
|
||||
|
||||
m_root = xrsp.Response() ;
|
||||
m_entries = m_root["entry"] ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
Feed::iterator::iterator( )
|
||||
{
|
||||
}
|
||||
|
||||
Feed::iterator::iterator( xml::Node::iterator i )
|
||||
{
|
||||
// for some reason, gcc 4.4.4 doesn't allow me to initialize the base class
|
||||
// in the initializer. I have no choice but to initialize here.
|
||||
base_reference() = i ;
|
||||
}
|
||||
|
||||
Feed::iterator::reference Feed::iterator::dereference() const
|
||||
{
|
||||
return Entry( *base_reference() ) ;
|
||||
}
|
||||
|
||||
} // end of namespace
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
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 "Entry.hh"
|
||||
|
||||
#include "xml/Node.hh"
|
||||
#include "xml/NodeSet.hh"
|
||||
|
||||
#include <boost/iterator_adaptors.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace gr {
|
||||
|
||||
namespace http
|
||||
{
|
||||
class Agent ;
|
||||
class Header ;
|
||||
}
|
||||
|
||||
class Feed
|
||||
{
|
||||
public :
|
||||
class iterator ;
|
||||
|
||||
public :
|
||||
explicit Feed( const xml::Node& root ) ;
|
||||
|
||||
iterator begin() const ;
|
||||
iterator end() const ;
|
||||
|
||||
std::string Next() const ;
|
||||
bool GetNext( http::Agent *http, const http::Header& auth ) ;
|
||||
|
||||
private :
|
||||
xml::Node m_root ;
|
||||
xml::NodeSet m_entries ;
|
||||
} ;
|
||||
|
||||
class Feed::iterator : public boost::iterator_adaptor<
|
||||
Feed::iterator,
|
||||
xml::Node::iterator,
|
||||
Entry,
|
||||
boost::random_access_traversal_tag,
|
||||
Entry
|
||||
>
|
||||
{
|
||||
public :
|
||||
iterator() ;
|
||||
explicit iterator( xml::Node::iterator i ) ;
|
||||
|
||||
private :
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
reference dereference() const ;
|
||||
} ;
|
||||
|
||||
} // end of namespace
|
|
@ -196,6 +196,10 @@ private :
|
|||
ImplVec m_children ;
|
||||
} ;
|
||||
|
||||
Node::iterator::iterator( )
|
||||
{
|
||||
}
|
||||
|
||||
Node::iterator::iterator( ImplVec::iterator i )
|
||||
{
|
||||
// for some reason, gcc 4.4.4 doesn't allow me to initialize the base class
|
||||
|
|
|
@ -100,6 +100,7 @@ class Node::iterator : public boost::iterator_adaptor<
|
|||
>
|
||||
{
|
||||
public :
|
||||
iterator( ) ;
|
||||
explicit iterator( ImplVec::iterator i ) ;
|
||||
|
||||
private :
|
||||
|
|
Loading…
Reference in New Issue