Akihito Nakano cf657f1c7b [C++] Adjust the names (script, sample folder, generator) to lang option (#220)
* Rename script: qt5-petstore.sh -> cpp-qt5-petstore.sh

* Rename sample folder: qt5cpp -> cpp-qt5

* Rename script: cpprest-petstore.sh -> cpp-restsdk-petstore.sh

* Rename sample folder: cpprest -> cpp-restsdk

* Rename generator: CppRestClientCodegen -> CppRestSdkClientCodegen

* Rename script: tizen-petstore.sh -> cpp-tizen-petstore.sh

* Rename sample folder: tizen -> cpp-tizen

* Rename script(security): qt5cpp-petstore.sh -> cpp-qt5-petstore.sh

* Rename sample folder(security): qt5cpp -> cpp-qt5

* Rename script(windows): qt5cpp-petstore.bat -> cpp-qt5-petstore.bat

* Change sample folder

* Rename script(windows): cpprest-petstore.bat -> cpp-restsdk-petstore.bat

* Change sample folder

* Rename script(windows): tizen-petstore.bat -> cpp-tizen-petstore.bat

* Change sample folder

* Change output folder: tizen -> cpp-tizen

* Rename the scripts under bin/openapi3

cpp-restsdk is not exist under bin/openapi3

* Change sample folder
2018-06-07 16:55:43 +08:00

174 lines
2.7 KiB
C++

#include <map>
#include <cstdlib>
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include "Helpers.h"
#include "ApiResponse.h"
using namespace std;
using namespace Tizen::ArtikCloud;
ApiResponse::ApiResponse()
{
//__init();
}
ApiResponse::~ApiResponse()
{
//__cleanup();
}
void
ApiResponse::__init()
{
//code = int(0);
//type = std::string();
//message = std::string();
}
void
ApiResponse::__cleanup()
{
//if(code != NULL) {
//
//delete code;
//code = NULL;
//}
//if(type != NULL) {
//
//delete type;
//type = NULL;
//}
//if(message != NULL) {
//
//delete message;
//message = NULL;
//}
//
}
void
ApiResponse::fromJson(char* jsonStr)
{
JsonObject *pJsonObject = json_node_get_object(json_from_string(jsonStr,NULL));
JsonNode *node;
const gchar *codeKey = "code";
node = json_object_get_member(pJsonObject, codeKey);
if (node !=NULL) {
if (isprimitive("int")) {
jsonToValue(&code, node, "int", "");
} else {
}
}
const gchar *typeKey = "type";
node = json_object_get_member(pJsonObject, typeKey);
if (node !=NULL) {
if (isprimitive("std::string")) {
jsonToValue(&type, node, "std::string", "");
} else {
}
}
const gchar *messageKey = "message";
node = json_object_get_member(pJsonObject, messageKey);
if (node !=NULL) {
if (isprimitive("std::string")) {
jsonToValue(&message, node, "std::string", "");
} else {
}
}
}
ApiResponse::ApiResponse(char* json)
{
this->fromJson(json);
}
char*
ApiResponse::toJson()
{
JsonObject *pJsonObject = json_object_new();
JsonNode *node;
if (isprimitive("int")) {
int obj = getCode();
node = converttoJson(&obj, "int", "");
}
else {
}
const gchar *codeKey = "code";
json_object_set_member(pJsonObject, codeKey, node);
if (isprimitive("std::string")) {
std::string obj = getType();
node = converttoJson(&obj, "std::string", "");
}
else {
}
const gchar *typeKey = "type";
json_object_set_member(pJsonObject, typeKey, node);
if (isprimitive("std::string")) {
std::string obj = getMessage();
node = converttoJson(&obj, "std::string", "");
}
else {
}
const gchar *messageKey = "message";
json_object_set_member(pJsonObject, messageKey, node);
node = json_node_alloc();
json_node_init(node, JSON_NODE_OBJECT);
json_node_take_object(node, pJsonObject);
char * ret = json_to_string(node, false);
json_node_free(node);
return ret;
}
int
ApiResponse::getCode()
{
return code;
}
void
ApiResponse::setCode(int code)
{
this->code = code;
}
std::string
ApiResponse::getType()
{
return type;
}
void
ApiResponse::setType(std::string type)
{
this->type = type;
}
std::string
ApiResponse::getMessage()
{
return message;
}
void
ApiResponse::setMessage(std::string message)
{
this->message = message;
}