mirror of https://github.com/vitalif/grive2
Added Query() helper to Feed. and common URI header
parent
209d0b5a59
commit
87d96972f7
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
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 <string>
|
||||||
|
|
||||||
|
namespace gr { namespace v2 {
|
||||||
|
|
||||||
|
namespace feeds
|
||||||
|
{
|
||||||
|
const std::string files = "https://www.googleapis.com/drive/v2/files" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace mime_types
|
||||||
|
{
|
||||||
|
const std::string folder = "application/vnd.google-apps.folder" ;
|
||||||
|
}
|
||||||
|
|
||||||
|
} } // end of namespace gr::v2
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "Drive.hh"
|
#include "Drive.hh"
|
||||||
|
|
||||||
|
#include "CommonUri.hh"
|
||||||
#include "Feed.hh"
|
#include "Feed.hh"
|
||||||
#include "protocol/Json.hh"
|
#include "protocol/Json.hh"
|
||||||
|
|
||||||
|
@ -34,16 +35,18 @@ Drive::Drive( )
|
||||||
void Drive::Refresh( http::Agent *agent )
|
void Drive::Refresh( http::Agent *agent )
|
||||||
{
|
{
|
||||||
// get all folders first
|
// get all folders first
|
||||||
Feed folders(
|
// Feed folders(
|
||||||
"https://www.googleapis.com/drive/v2/files?q=mimeType+%3d+%27application/vnd.google-apps.folder%27" ) ;
|
// "https://www.googleapis.com/drive/v2/files?q=mimeType+%3d+%27application/vnd.google-apps.folder%27" ) ;
|
||||||
|
Feed folders( feeds::files ) ;
|
||||||
|
// folders.Query( "mimeType", "application/vnd.google-apps.folder" ) ;
|
||||||
|
|
||||||
while ( folders.Next( agent ) )
|
while ( folders.Next( agent ) )
|
||||||
{
|
{
|
||||||
std::vector<Json> items = folders.Content()["items"].AsArray() ;
|
std::vector<Json> items = folders.Content()["items"].AsArray() ;
|
||||||
for ( std::vector<Json>::iterator i = items.begin() ; i != items.end() ; ++i )
|
for ( std::vector<Json>::iterator i = items.begin() ; i != items.end() ; ++i )
|
||||||
{
|
{
|
||||||
const Resource *r = Add( *i ) ;
|
const Resource *r = Add( *i ) ;
|
||||||
std::cout << r->Title() << " " << r->Mime() << std::endl ;
|
std::cout << r->Title() << " " << r->Mime() << std::endl ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,5 +57,11 @@ const Resource* Drive::Add( const Json& item )
|
||||||
return *m_db.insert(r).first ;
|
return *m_db.insert(r).first ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Resource* Drive::Find( const std::string& id )
|
||||||
|
{
|
||||||
|
details::ID::iterator i = m_db.get<details::ByID>().find(id) ;
|
||||||
|
return i != m_db.get<details::ByID>().end() ? *i : 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
} } // end of namespace gr::v2
|
} } // end of namespace gr::v2
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ public :
|
||||||
|
|
||||||
void Refresh( http::Agent *agent ) ;
|
void Refresh( http::Agent *agent ) ;
|
||||||
|
|
||||||
|
Resource* Find( const std::string& id ) ;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
const Resource* Add( const Json& item ) ;
|
const Resource* Add( const Json& item ) ;
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,12 @@ Feed::Feed( const std::string& base )
|
||||||
{
|
{
|
||||||
// Next() will grab this link
|
// Next() will grab this link
|
||||||
m_content.Add( "nextLink", Json(base) ) ;
|
m_content.Add( "nextLink", Json(base) ) ;
|
||||||
|
}
|
||||||
Json url ;
|
|
||||||
m_content.Get("nextLink", url) ;
|
void Feed::Query( const std::string& field, const std::string& value )
|
||||||
std::cout << "link = " << url.Str() << std::endl ;
|
{
|
||||||
|
std::string url = m_content["nextLink"].Str() ;
|
||||||
|
m_content.Add( "nextLink", Json( url + "?q=" + field + "+%3d+%27" + value + "%27" ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Feed::Next( http::Agent *agent )
|
bool Feed::Next( http::Agent *agent )
|
||||||
|
|
|
@ -44,6 +44,9 @@ public :
|
||||||
|
|
||||||
public :
|
public :
|
||||||
Feed( const std::string& base ) ;
|
Feed( const std::string& base ) ;
|
||||||
|
void Query( const std::string& field, const std::string& value ) ;
|
||||||
|
|
||||||
|
|
||||||
bool Next( http::Agent *agent ) ;
|
bool Next( http::Agent *agent ) ;
|
||||||
|
|
||||||
Json Content() const ;
|
Json Content() const ;
|
||||||
|
|
|
@ -20,13 +20,15 @@
|
||||||
|
|
||||||
#include "Resource.hh"
|
#include "Resource.hh"
|
||||||
|
|
||||||
|
#include "CommonUri.hh"
|
||||||
|
|
||||||
namespace gr { namespace v2 {
|
namespace gr { namespace v2 {
|
||||||
|
|
||||||
/** Default constructor construct the resource of the root folder
|
/** Default constructor construct the resource of the root folder
|
||||||
*/
|
*/
|
||||||
Resource::Resource() :
|
Resource::Resource() :
|
||||||
m_id( "root" ),
|
m_id( "root" ),
|
||||||
m_mime( "application/vnd.google-apps.folder" ),
|
m_mime( mime_types::folder ),
|
||||||
m_title( "Root folder" )
|
m_title( "Root folder" )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue