mcloud  1.0.0
MCloud API library for cmcc cloud service
mcloud::api::Client Class Reference

Mcloud API provides developer to easily access login user's cloud contents stored on mcloud, such as musics, movie, docs, images, and so on. More...

#include <client.h>

+ Collaboration diagram for mcloud::api::Client:

Public Types

typedef std::shared_ptr< ClientPtr
 
typedef std::deque< CloudResource::PtrResourceList
 
typedef std::deque< Outlink::PtrOutlinkList
 
typedef std::vector< std::string > Stringlist
 

Public Member Functions

 Client (int request_timeout=10)
 Constructs a Mcloud Client object with request_timeout seconds. Meanwhile client launches sync-up manager to deal with task download and upload by default. More...
 
 Client (const Client &)=delete
 
Clientoperator= (const Client &)=delete
 
virtual ~Client ()
 
void set_access_token (const std::string &access_token)
 Set access_token to authenticate all mcloud API calls with the bearer HTTP authorization scheme. The access token can be fetched through ubuntu sso services. More...
 
bool refresh_token (const std::string &refresh_token)
 Retrieves and refreshes access token by using refresh_token. The refresh token can be fetched through ubuntu sso services. More...
 
DiskInfo disk_info ()
 Returns login user's clcoud storage info. More...
 
std::string cloud_root_folder_id ()
 Returns root folder id on mlcoud for third-party app to use, such as mcloud-lib. More...
 
ResourceList cloud_content_list (int start_index, int count, CloudContent::Type content_type=CloudContent::Type::All, const std::string &folder_id=std::string())
 Returns a cloud item list under one specific folder folder_id with a given type content_type. if folder_id is empty, returns contents under root folder of cloud. content_type is CloudContent::Type::All by default. The fetched content count is 200 at most per call. start_index indicates the first index of the requested content list on mcloud. count indicates the maximum number of content items per call. More...
 
CloudContent::Ptr content_info (const std::string &content_id)
 Returns a cloud content object if a content content_id exists on mcloud. otherwise return nullptr. More...
 
CloudFolder::Ptr create_folder (const std::string &folder_name, const std::string &folder_id)
 Returns a cloud folder object if a folder with folder_name is created under a given folder_id folder. otherwise return nullptr. More...
 
Client::ResourceList look_up (const std::string &name, const std::string &folder_id, CloudResource::Property property=CloudResource::Property::Content)
 Returns a cloud item list if there are available items that matches with name under a given folder_id folder. property holds the property of cloud item, it can be content(default) or folder. More...
 
OutlinkList create_folder_extranet_link (const Stringlist &folder_ids)
 Creates folders extranet link object with a given folder_ids. More...
 
OutlinkList create_content_extranet_link (const Stringlist &content_ids)
 Creates a content_extranet link object with a given content_ids. More...
 
Client::Stringlist copy_folders (const Stringlist &folder_ids, const std::string &_folder_id)
 Returns folder id list if folders folder_ids are copies to another folder with a given folder_id on mcloud. More...
 
Client::Stringlist copy_contents (const Stringlist &contents_ids, const std::string &folder_id)
 Returns content id list if contents content_ids are copies to another folder with a given folder_id on mcloud. More...
 
bool move_items (const Stringlist &folder_ids, const Stringlist &content_ids, const std::string &folder_id)
 Returns true if folders with a given folder_ids and contents with a given content_ids are successfully moved to new folder with a given folder_id. More...
 
bool update_folder (const std::string &folder_id, const std::string &new_folder_name)
 Returns true if folder folder_id are updated with new_folder_name, otherwise return false. More...
 
bool delete_contents (const Stringlist &content_ids)
 Returns true if contents content_ids are deleted, otherwise return false. More...
 
bool exist_on_cloud (const std::string &file_path, const std::string &folder_id=std::string())
 Returns true if a local file file_path exists in folder with folder_id on cloud, otherwise return false. Searches root folder if folder_id is empty();. More...
 
SyncManager::Ptr syncmanager () const
 Returns a sync-up manager running on the background. sync-up manager scheduled tasks. More...
 

Detailed Description

Mcloud API provides developer to easily access login user's cloud contents stored on mcloud, such as musics, movie, docs, images, and so on.

The API enable developers to

  • retrieve authorized user cloud content list.
  • create, delete, move and update cloud resources.
  • query content infomation.
  • create an extranet link to share.
  • upload a local content to mcloud.
  • download a content from mcloud.

Also sync up manager will be running on the background when client is constructed. It handles over local content upload and cloud item download.

See also
syncmanager.
Note
Mcloud API covers cloud resourece access and content sync-up between local and cloud. It does not take responsibility of account authentication. So before using mcloud APIs, developers need to call
See also
set_access_token to manually set a valid access_token or
refresh_token to fetch access token, which is used to call mcloud APIs internally to pass through authentication.

Definition at line 66 of file client.h.

Member Typedef Documentation

Definition at line 73 of file client.h.

typedef std::shared_ptr<Client> mcloud::api::Client::Ptr

Definition at line 69 of file client.h.

Definition at line 71 of file client.h.

typedef std::vector<std::string> mcloud::api::Client::Stringlist

Definition at line 75 of file client.h.

Constructor & Destructor Documentation

mcloud::api::Client::Client ( int  request_timeout = 10)

Constructs a Mcloud Client object with request_timeout seconds. Meanwhile client launches sync-up manager to deal with task download and upload by default.

mcloud::api::Client::Client ( const Client )
delete
virtual mcloud::api::Client::~Client ( )
virtual

Member Function Documentation

ResourceList mcloud::api::Client::cloud_content_list ( int  start_index,
int  count,
CloudContent::Type  content_type = CloudContent::Type::All,
const std::string &  folder_id = std::string() 
)

Returns a cloud item list under one specific folder folder_id with a given type content_type. if folder_id is empty, returns contents under root folder of cloud. content_type is CloudContent::Type::All by default. The fetched content count is 200 at most per call. start_index indicates the first index of the requested content list on mcloud. count indicates the maximum number of content items per call.

Exceptions
std::runtime_errorif error occurs.
See also
CloudContent::Type cloud_root_folder_id()
std::string mcloud::api::Client::cloud_root_folder_id ( )

Returns root folder id on mlcoud for third-party app to use, such as mcloud-lib.

Exceptions
std::runtime_errorif error occurs.
Note
there're a few folders on a cmcc user's mcloud directory, but only one can be used for content synchronization by third-party client. We regard it as the root folder for mcloud thrid-party app.
See also
cloud_content_list()
CloudContent::Ptr mcloud::api::Client::content_info ( const std::string &  content_id)

Returns a cloud content object if a content content_id exists on mcloud. otherwise return nullptr.

Exceptions
std::runtime_errorif error occurs.
See also
delete_contents(), move_items()
Client::Stringlist mcloud::api::Client::copy_contents ( const Stringlist contents_ids,
const std::string &  folder_id 
)

Returns content id list if contents content_ids are copies to another folder with a given folder_id on mcloud.

Exceptions
std::runtime_errorif error occurs.
Note
the destination folder folder_id should not be the same as the contents' contents_ids folder id.
See also
move_items(), update_folder(), copy_folders()
Client::Stringlist mcloud::api::Client::copy_folders ( const Stringlist folder_ids,
const std::string &  _folder_id 
)

Returns folder id list if folders folder_ids are copies to another folder with a given folder_id on mcloud.

Exceptions
std::runtime_errorif error occurs.
Note
the destination folder folder_id should not be the same as the folders' folder_ids folder ids.
See also
move_items(), update_folder(), copy_contents()
OutlinkList mcloud::api::Client::create_content_extranet_link ( const Stringlist content_ids)

Creates a content_extranet link object with a given content_ids.

Exceptions
std::runtime_errorif error occurs.
See also
create_folder_extranet_link()
Returns
a list of Outlink after extranet links are created.
CloudFolder::Ptr mcloud::api::Client::create_folder ( const std::string &  folder_name,
const std::string &  folder_id 
)

Returns a cloud folder object if a folder with folder_name is created under a given folder_id folder. otherwise return nullptr.

Exceptions
std::runtime_errorif error occurs.
See also
delete_contents(), move_items()
OutlinkList mcloud::api::Client::create_folder_extranet_link ( const Stringlist folder_ids)

Creates folders extranet link object with a given folder_ids.

Exceptions
std::runtime_errorif error occurs.
See also
create_content_extranet_link()
Returns
a list of Outlink after extranet links are created.
bool mcloud::api::Client::delete_contents ( const Stringlist content_ids)

Returns true if contents content_ids are deleted, otherwise return false.

Exceptions
std::runtime_errorif error occurs.
See also
move_items(), content_info(), copy_contents()
DiskInfo mcloud::api::Client::disk_info ( )

Returns login user's clcoud storage info.

Exceptions
std::runtime_errorif error occurs.
See also
DiskInfo
bool mcloud::api::Client::exist_on_cloud ( const std::string &  file_path,
const std::string &  folder_id = std::string() 
)

Returns true if a local file file_path exists in folder with folder_id on cloud, otherwise return false. Searches root folder if folder_id is empty();.

Exceptions
std::runtime_errorif error occurs.
Client::ResourceList mcloud::api::Client::look_up ( const std::string &  name,
const std::string &  folder_id,
CloudResource::Property  property = CloudResource::Property::Content 
)

Returns a cloud item list if there are available items that matches with name under a given folder_id folder. property holds the property of cloud item, it can be content(default) or folder.

Exceptions
std::runtime_errorif error occurs.
See also
delete_contents(), move_items(), metadata()
bool mcloud::api::Client::move_items ( const Stringlist folder_ids,
const Stringlist content_ids,
const std::string &  folder_id 
)

Returns true if folders with a given folder_ids and contents with a given content_ids are successfully moved to new folder with a given folder_id.

Exceptions
std::runtime_errorif error occurs.
See also
delete_contents(), copy_folders(), copy_contents()
Client& mcloud::api::Client::operator= ( const Client )
delete
bool mcloud::api::Client::refresh_token ( const std::string &  refresh_token)

Retrieves and refreshes access token by using refresh_token. The refresh token can be fetched through ubuntu sso services.

Exceptions
std::runtime_errorif error occurs.
Returns
true if access token is refreshed, otherwise returns false.
void mcloud::api::Client::set_access_token ( const std::string &  access_token)

Set access_token to authenticate all mcloud API calls with the bearer HTTP authorization scheme. The access token can be fetched through ubuntu sso services.

SyncManager::Ptr mcloud::api::Client::syncmanager ( ) const

Returns a sync-up manager running on the background. sync-up manager scheduled tasks.

See also
start, pause, cancel for content upload and download.
bool mcloud::api::Client::update_folder ( const std::string &  folder_id,
const std::string &  new_folder_name 
)

Returns true if folder folder_id are updated with new_folder_name, otherwise return false.

Exceptions
std::runtime_errorif error occurs.
See also
delete_contents(), copy_folders(),

The documentation for this class was generated from the following file: