~gary-wzl77/storage-provider-onedrive/merge-devel

« back to all changes in this revision

Viewing changes to src/onedrive/api/cloudfolder.cpp

  • Committer: Tarmac
  • Author(s): Gary.Wzl
  • Date: 2016-12-08 04:11:32 UTC
  • mfrom: (1.1.57 provider)
  • Revision ID: tarmac-20161208041132-e3irhhvex05wc8ta
The implementation of provider and regarding test cases writing with storagw-fw client v2 API.

Approved by James Henstridge, unity-api-1-bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3,
 
6
 * as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Gary Wang <gary.wang@canonical.com>
 
17
 */
 
18
 
 
19
#include <onedrive/api/cloudfolder.h>
 
20
 
 
21
#include <json/json.h>
 
22
 
 
23
#include <time.h>
 
24
#include <iostream>
 
25
#include <sstream>
 
26
 
 
27
namespace json = Json;
 
28
 
 
29
using namespace onedrive::api;
 
30
using namespace std;
 
31
 
 
32
class CloudFolder::Priv {
 
33
  public:
 
34
    Priv(const json::Value &root) {
 
35
        id_ = root["id"].asString();
 
36
        updated_date_ = root["lastModifiedDateTime"].asString();
 
37
        created_date_ = root["createdDateTime"].asString();
 
38
        etag_  = root["eTag"].asString();
 
39
        name_  = root["name"].asString();
 
40
        owner_ = root["createdBy"]["user"]["displayName"].asString();
 
41
        folder_id_ = root.isMember("parentReference") ?
 
42
                     root["parentReference"]["id"].asString() : "";
 
43
        children_count_ = root["folder"]["childCount"].asInt();
 
44
 
 
45
        for (const auto & thumbnail: root["thumbnails"]) {
 
46
            thumbnails_.large_url =  thumbnail["large"]["url"].asString();
 
47
            thumbnails_.medium_url = thumbnail["medium"]["url"].asString();
 
48
            thumbnails_.small_url = thumbnail["small"]["url"].asString();
 
49
        }
 
50
#ifndef NDEBUG
 
51
        cout << "id: " << id_ << " name: " << name_ << "  etag: " << etag_ << endl;
 
52
#endif
 
53
    }
 
54
 
 
55
    string id_;
 
56
 
 
57
    string name_;
 
58
 
 
59
    string created_date_;
 
60
 
 
61
    string updated_date_;
 
62
 
 
63
    string download_url_;
 
64
 
 
65
    string folder_id_;
 
66
 
 
67
    string etag_;
 
68
 
 
69
    string owner_;
 
70
 
 
71
    int children_count_;
 
72
 
 
73
    thumbnail_set thumbnails_;
 
74
};
 
75
 
 
76
CloudFolder::CloudFolder(const json::Value &root)
 
77
    : p(new Priv(root)) {
 
78
}
 
79
 
 
80
CloudFolder::~CloudFolder() {
 
81
}
 
82
 
 
83
const string &CloudFolder::id() const {
 
84
    return p->id_;
 
85
}
 
86
 
 
87
const string &CloudFolder::name() const {
 
88
    return p->name_;
 
89
}
 
90
 
 
91
const string &CloudFolder::created_date() const {
 
92
    return p->created_date_;
 
93
}
 
94
 
 
95
const string &CloudFolder::updated_date() const {
 
96
    return p->updated_date_;
 
97
}
 
98
 
 
99
const string &CloudFolder::download_url() const {
 
100
    return p->download_url_;
 
101
}
 
102
 
 
103
const string &CloudFolder::parent_folder_id() const {
 
104
    return p->folder_id_;
 
105
}
 
106
 
 
107
int CloudFolder::children_count() const {
 
108
    return p->children_count_;
 
109
}
 
110
 
 
111
const string &CloudFolder::etag() const {
 
112
    return p->etag_;
 
113
}
 
114
 
 
115
const string &CloudFolder::owner() const {
 
116
    return p->owner_;
 
117
}
 
118
 
 
119
CloudResource::Property CloudFolder::property() const {
 
120
    return CloudResource::Property::Folder;
 
121
}
 
122
 
 
123
const CloudResource::thumbnail_set &CloudFolder::thumbnails() const {
 
124
    return p->thumbnails_;
 
125
}