2016-06-18 10:09:19 +00:00
/**
* Swagger Petstore
2017-05-05 08:20:59 +00:00
* This is a sample server Petstore server . You can find out more about Swagger at [ http : //swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
2016-06-18 10:09:19 +00:00
*
* OpenAPI spec version : 1.0 .0
2017-05-05 08:20:59 +00:00
* Contact : apiteam @ swagger . io
2016-06-18 10:09:19 +00:00
*
2017-08-25 10:35:56 +00:00
* NOTE : This class is auto generated by the swagger code generator 2.3 .0 - SNAPSHOT .
2016-06-18 10:09:19 +00:00
* https : //github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually .
*/
2016-06-14 08:33:50 +00:00
# include "StoreApi.h"
# include "IHttpBody.h"
# include "JsonBody.h"
# include "MultipartFormData.h"
# include <unordered_set>
# include <boost/algorithm/string/replace.hpp>
namespace io {
namespace swagger {
namespace client {
namespace api {
using namespace io : : swagger : : client : : model ;
StoreApi : : StoreApi ( std : : shared_ptr < ApiClient > apiClient )
: m_ApiClient ( apiClient )
{
}
StoreApi : : ~ StoreApi ( )
{
}
pplx : : task < void > StoreApi : : deleteOrder ( utility : : string_t orderId )
{
2017-04-24 14:45:16 +00:00
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
2017-11-09 09:58:21 +00:00
utility : : string_t path = utility : : conversions : : to_string_t ( " /store/order/{orderId} " ) ;
boost : : replace_all ( path , utility : : conversions : : to_string_t ( " { " ) + utility : : conversions : : to_string_t ( " orderId " ) + utility : : conversions : : to_string_t ( " } " ) , ApiClient : : parameterToString ( orderId ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2017-11-09 09:58:21 +00:00
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/xml " ) ) ;
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-12-13 07:01:48 +00:00
}
// JSON
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 400 , utility : : conversions : : to_string_t ( " StoreApi->deleteOrder does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2017-11-09 09:58:21 +00:00
headerParams [ utility : : conversions : : to_string_t ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2017-11-09 09:58:21 +00:00
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
else
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 415 , utility : : conversions : : to_string_t ( " StoreApi->deleteOrder does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
return m_ApiClient - > callApi ( path , utility : : conversions : : to_string_t ( " DELETE " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
2016-06-14 08:33:50 +00:00
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling deleteOrder: " ) + response . reason_phrase ( )
2016-11-16 13:44:49 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2017-11-09 09:58:21 +00:00
if ( response . headers ( ) . has ( utility : : conversions : : to_string_t ( " Content-Type " ) ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
utility : : string_t contentType = response . headers ( ) [ utility : : conversions : : to_string_t ( " Content-Type " ) ] ;
2016-06-14 08:33:50 +00:00
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling deleteOrder: unexpected response type: " ) + contentType
2016-06-14 08:33:50 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
return void ( ) ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < std : : map < utility : : string_t , int32_t > > StoreApi : : getInventory ( )
{
2017-04-24 14:45:16 +00:00
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
2017-11-09 09:58:21 +00:00
utility : : string_t path = utility : : conversions : : to_string_t ( " /store/inventory " ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2017-11-09 09:58:21 +00:00
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-12-13 07:01:48 +00:00
}
// JSON
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 400 , utility : : conversions : : to_string_t ( " StoreApi->getInventory does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2017-11-09 09:58:21 +00:00
headerParams [ utility : : conversions : : to_string_t ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2017-11-09 09:58:21 +00:00
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
else
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 415 , utility : : conversions : : to_string_t ( " StoreApi->getInventory does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// authentication (api_key) required
{
2017-11-09 09:58:21 +00:00
utility : : string_t apiKey = apiConfiguration - > getApiKey ( utility : : conversions : : to_string_t ( " api_key " ) ) ;
2016-06-14 08:33:50 +00:00
if ( apiKey . size ( ) > 0 )
{
2017-11-09 09:58:21 +00:00
headerParams [ utility : : conversions : : to_string_t ( " api_key " ) ] = apiKey ;
2016-06-14 08:33:50 +00:00
}
}
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
return m_ApiClient - > callApi ( path , utility : : conversions : : to_string_t ( " GET " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
2016-06-14 08:33:50 +00:00
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling getInventory: " ) + response . reason_phrase ( )
2016-11-16 13:44:49 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2017-11-09 09:58:21 +00:00
if ( response . headers ( ) . has ( utility : : conversions : : to_string_t ( " Content-Type " ) ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
utility : : string_t contentType = response . headers ( ) [ utility : : conversions : : to_string_t ( " Content-Type " ) ] ;
2016-06-14 08:33:50 +00:00
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling getInventory: unexpected response type: " ) + contentType
2016-06-14 08:33:50 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
std : : map < utility : : string_t , int32_t > result ;
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
if ( responseHttpContentType = = utility : : conversions : : to_string_t ( " application/json " ) )
2016-06-14 08:33:50 +00:00
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
for ( auto & item : json . as_object ( ) )
{
result [ item . first ] = ModelBase : : int32_tFromJson ( item . second ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
}
2017-11-09 09:58:21 +00:00
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
2016-06-14 08:33:50 +00:00
// {
2016-12-13 08:09:56 +00:00
// TODO multipart response parsing
2016-06-14 08:33:50 +00:00
// }
2016-12-13 08:09:56 +00:00
else
2016-06-14 08:33:50 +00:00
{
2016-11-16 13:44:49 +00:00
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling getInventory: unsupported response type " ) ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return result ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
2017-05-05 08:20:59 +00:00
pplx : : task < std : : shared_ptr < Order > > StoreApi : : getOrderById ( int64_t orderId )
2016-06-14 08:33:50 +00:00
{
2017-04-24 14:45:16 +00:00
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
2017-11-09 09:58:21 +00:00
utility : : string_t path = utility : : conversions : : to_string_t ( " /store/order/{orderId} " ) ;
boost : : replace_all ( path , utility : : conversions : : to_string_t ( " { " ) + utility : : conversions : : to_string_t ( " orderId " ) + utility : : conversions : : to_string_t ( " } " ) , ApiClient : : parameterToString ( orderId ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2017-11-09 09:58:21 +00:00
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/xml " ) ) ;
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-12-13 07:01:48 +00:00
}
// JSON
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 400 , utility : : conversions : : to_string_t ( " StoreApi->getOrderById does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2017-11-09 09:58:21 +00:00
headerParams [ utility : : conversions : : to_string_t ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2017-11-09 09:58:21 +00:00
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
else
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 415 , utility : : conversions : : to_string_t ( " StoreApi->getOrderById does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
return m_ApiClient - > callApi ( path , utility : : conversions : : to_string_t ( " GET " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
2016-06-14 08:33:50 +00:00
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling getOrderById: " ) + response . reason_phrase ( )
2016-11-16 13:44:49 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2017-11-09 09:58:21 +00:00
if ( response . headers ( ) . has ( utility : : conversions : : to_string_t ( " Content-Type " ) ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
utility : : string_t contentType = response . headers ( ) [ utility : : conversions : : to_string_t ( " Content-Type " ) ] ;
2016-06-14 08:33:50 +00:00
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling getOrderById: unexpected response type: " ) + contentType
2016-06-14 08:33:50 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
std : : shared_ptr < Order > result ( new Order ( ) ) ;
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
if ( responseHttpContentType = = utility : : conversions : : to_string_t ( " application/json " ) )
2016-06-14 08:33:50 +00:00
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
result - > fromJson ( json ) ;
}
2017-11-09 09:58:21 +00:00
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
2016-06-14 08:33:50 +00:00
// {
2016-12-13 08:09:56 +00:00
// TODO multipart response parsing
2016-06-14 08:33:50 +00:00
// }
2016-12-13 08:09:56 +00:00
else
2016-06-14 08:33:50 +00:00
{
2016-11-16 13:44:49 +00:00
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling getOrderById: unsupported response type " ) ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return result ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < std : : shared_ptr < Order > > StoreApi : : placeOrder ( std : : shared_ptr < Order > body )
{
2017-04-24 14:45:16 +00:00
2017-05-05 08:20:59 +00:00
// verify the required parameter 'body' is set
if ( body = = nullptr )
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 400 , utility : : conversions : : to_string_t ( " Missing required parameter 'body' when calling StoreApi->placeOrder " ) ) ;
2017-05-05 08:20:59 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
2017-11-09 09:58:21 +00:00
utility : : string_t path = utility : : conversions : : to_string_t ( " /store/order " ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2017-11-09 09:58:21 +00:00
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/xml " ) ) ;
responseHttpContentTypes . insert ( utility : : conversions : : to_string_t ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-12-13 07:01:48 +00:00
}
// JSON
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( responseHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
responseHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 400 , utility : : conversions : : to_string_t ( " StoreApi->placeOrder does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2017-11-09 09:58:21 +00:00
headerParams [ utility : : conversions : : to_string_t ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2017-11-09 09:58:21 +00:00
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " application/json " ) ;
2016-06-14 08:33:50 +00:00
web : : json : : value json ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
json = ModelBase : : toJson ( body ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
httpBody = std : : shared_ptr < IHttpBody > ( new JsonBody ( json ) ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2017-11-09 09:58:21 +00:00
else if ( consumeHttpContentTypes . find ( utility : : conversions : : to_string_t ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
requestHttpContentType = utility : : conversions : : to_string_t ( " multipart/form-data " ) ;
2016-06-14 08:33:50 +00:00
std : : shared_ptr < MultipartFormData > multipart ( new MultipartFormData ) ;
2016-12-13 08:09:56 +00:00
if ( body . get ( ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
body - > toMultipart ( multipart , utility : : conversions : : to_string_t ( " body " ) ) ;
2016-06-14 08:33:50 +00:00
}
httpBody = multipart ;
2017-11-09 09:58:21 +00:00
requestHttpContentType + = utility : : conversions : : to_string_t ( " ; boundary= " ) + multipart - > getBoundary ( ) ;
2016-06-14 08:33:50 +00:00
}
else
{
2017-11-09 09:58:21 +00:00
throw ApiException ( 415 , utility : : conversions : : to_string_t ( " StoreApi->placeOrder does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
return m_ApiClient - > callApi ( path , utility : : conversions : : to_string_t ( " POST " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
2016-06-14 08:33:50 +00:00
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling placeOrder: " ) + response . reason_phrase ( )
2016-11-16 13:44:49 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2017-11-09 09:58:21 +00:00
if ( response . headers ( ) . has ( utility : : conversions : : to_string_t ( " Content-Type " ) ) )
2016-06-14 08:33:50 +00:00
{
2017-11-09 09:58:21 +00:00
utility : : string_t contentType = response . headers ( ) [ utility : : conversions : : to_string_t ( " Content-Type " ) ] ;
2016-06-14 08:33:50 +00:00
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling placeOrder: unexpected response type: " ) + contentType
2016-06-14 08:33:50 +00:00
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
std : : shared_ptr < Order > result ( new Order ( ) ) ;
2016-12-13 08:09:56 +00:00
2017-11-09 09:58:21 +00:00
if ( responseHttpContentType = = utility : : conversions : : to_string_t ( " application/json " ) )
2016-06-14 08:33:50 +00:00
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
result - > fromJson ( json ) ;
}
2017-11-09 09:58:21 +00:00
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
2016-06-14 08:33:50 +00:00
// {
2016-12-13 08:09:56 +00:00
// TODO multipart response parsing
2016-06-14 08:33:50 +00:00
// }
2016-12-13 08:09:56 +00:00
else
2016-06-14 08:33:50 +00:00
{
2016-11-16 13:44:49 +00:00
throw ApiException ( 500
2017-11-09 09:58:21 +00:00
, utility : : conversions : : to_string_t ( " error calling placeOrder: unsupported response type " ) ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return result ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
}
}
}
}