Commit 265b29a6 authored by A. Wilcox's avatar A. Wilcox

Etsy: Store tags and materials for an item.

parent e8003c0e
......@@ -224,6 +224,67 @@ EtsyItem::EtsyItem(EtsySite *site, JSONNode json)
updateWithJSON(json);
}
libAPI vector<const char *> *EtsyItem::getTags(void)
{
vector <const char *> *tags = new vector<const char *>;
for(unsigned long next_tag = 0; next_tag < this->_tags.size(); next_tag++)
tags->push_back(this->_tags.at(next_tag));
return tags;
}
libAPI vector<const char *> *EtsyItem::getMaterials(void)
{
vector <const char *> *materials = new vector<const char *>;
for(unsigned long next_mat = 0; next_mat < this->_materials.size(); next_mat++)
materials->push_back(this->_materials.at(next_mat));
return materials;
}
void EtsyItem::loadTagsFromJSON(JSONNode tags)
{
for(unsigned long next_tag = 0; next_tag < this->_tags.size(); next_tag++)
free(this->_tags.at(next_tag));
this->_tags.clear();
for(JSONNode::iterator tag_iter = tags.begin();
tag_iter != tags.end();
tag_iter++)
{
JSONNode curr_tag = *tag_iter;
this->_tags.push_back(strdup(curr_tag.as_string().c_str()));
}
return;
}
void EtsyItem::loadMaterialsFromJSON(JSONNode materials)
{
for(unsigned long next_mat = 0; next_mat < this->_materials.size(); next_mat++)
free(this->_materials.at(next_mat));
this->_materials.clear();
for(JSONNode::iterator mat_iter = materials.begin();
mat_iter != materials.end();
mat_iter++)
{
JSONNode curr_material = *mat_iter;
this->_materials.push_back(strdup(curr_material.as_string().c_str()));
}
return;
}
void EtsyItem::updateWithJSON(JSONNode json)
{
JSONNode *listing_json = NULL, *transaction_json = NULL;
......@@ -395,6 +456,16 @@ void EtsyItem::updateWithJSON(JSONNode json)
this->_condition = NULL;
if(listing_json->find("tags") != listing_json->end())
{
loadTagsFromJSON(listing_json->at("tags"));
}
if(listing_json->find("materials") != listing_json->end())
{
loadMaterialsFromJSON(listing_json->at("materials"));
}
if(json.find("who_made") != json.end())
{
const char *metadata_value;
......
......@@ -52,6 +52,10 @@ public:
libAPI virtual ~EtsyItem();
libAPI EtsyItemState getItemState(void) { return this->_itemState; };
libAPI vector<const char *> *getTags(void);
libAPI vector<const char *> *getMaterials(void);
private:
/*!
@brief Initialise an Etsy item from Etsy JSON.
......@@ -61,10 +65,15 @@ private:
libAPI EtsyItem(EtsySite *site, JSONNode json);
libAPI void updateWithJSON(JSONNode json);
void loadTagsFromJSON(JSONNode tags);
void loadMaterialsFromJSON(JSONNode materials);
EtsyItemState _itemState;
friend class EtsySite;
vector<char *> _tags;
vector<char *> _materials;
};
#endif /*!__AUCTIONS_COMMON_ETSY_ITEM_H_*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment