Permalink
Browse files

changed to store parent IDs

  • Loading branch information...
1 parent 87d9697 commit ee6408d05f2c4577d36f4ccac71150df99df3447 @nestal nestal committed Apr 29, 2013
@@ -33,4 +33,9 @@ namespace mime_types
const std::string folder = "application/vnd.google-apps.folder" ;
}
+namespace kinds
+{
+ const std::string parent = "drive#parentReference" ;
+}
+
} } // end of namespace gr::v2
@@ -25,6 +25,7 @@
#include "protocol/Json.hh"
#include <iostream>
+#include <iterator>
namespace gr { namespace v2 {
@@ -46,14 +47,25 @@ void Drive::Refresh( http::Agent *agent )
for ( std::vector<Json>::iterator i = items.begin() ; i != items.end() ; ++i )
{
const Resource *r = Add( *i ) ;
- std::cout << r->Title() << " " << r->Mime() << std::endl ;
}
}
}
const Resource* Drive::Add( const Json& item )
{
Resource *r = new Resource( item["id"].Str(), item["mimeType"].Str(), item["title"].Str() ) ;
+
+ // initialize parent IDs
+ Json parents ;
+ if ( item.Get( "parents", parents ) )
+ {
+ std::vector<std::string> parent_ids ;
+ parents.Select<std::string>( "id", std::back_inserter(parent_ids) ) ;
+
+ r->SetParent( parent_ids.begin(), parent_ids.end() ) ;
+ std::cout << r->Title() << " " << r->ID() << " " << parent_ids.size() << std::endl ;
+ }
+
return *m_db.insert(r).first ;
}
@@ -60,9 +60,4 @@ bool Resource::IsFolder() const
return m_mime == "application/vnd.google-apps.folder" ;
}
-void Resource::Add( const std::string& child_id )
-{
- m_children.push_back( child_id ) ;
-}
-
} } // end of namespace gr::v2
@@ -30,21 +30,25 @@ class Resource
public :
Resource() ;
Resource( const std::string& id, const std::string& mime, const std::string& title ) ;
-
+
+ template <typename InputIt>
+ void SetParent( InputIt first, InputIt last )
+ {
+ m_parent.assign( first, last ) ;
+ }
+
std::string ID() const ;
std::string Mime() const ;
std::string Title() const ;
bool IsFolder() const ;
- void Add( const std::string& child_id ) ;
-
private :
std::string m_id ;
std::string m_mime ;
std::string m_title ;
- std::vector<std::string> m_children ;
+ std::vector<std::string> m_parent ;
} ;
} } // end of namespace gr::v2
@@ -100,6 +100,18 @@ public :
Json FindInArray( const std::string& key, const std::string& value ) const ;
bool FindInArray( const std::string& key, const std::string& value, Json& result ) const ;
+ /** Expect *this is a JSON array of objects. Select all "key" values inside each
+ objects in the array and copies them in the output iterator \a out.
+ */
+ template <typename T, typename Out>
+ Out Select( const std::string& key, Out out )
+ {
+ Array a = AsArray() ;
+ for ( Array::iterator i = a.begin() ; i != a.end() ; ++i )
+ *out++ = i->As<T>() ;
+ return out ;
+ }
+
friend std::ostream& operator<<( std::ostream& os, const Json& json ) ;
void Write( DataStream *out ) const ;

0 comments on commit ee6408d

Please sign in to comment.