RestSharp c# code -> c++

  • Thread starter Thread starter rladygks20
  • Start date Start date
R

rladygks20

Guest
How can I code below with c++?? plaese help me.


[Entitlement API - c#]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net; // for HttpStatusCode
// Added for REST API
// We are using C# REST library called RestShap
// See RestSharp - Simple REST and HTTP Client for .NET for detail
//
using RestSharp;
using RestSharp.Deserializers;

/// Revit 2016 has added two methods to help exchange store app publishers
/// to check a store app entitlement, i.e., to check if the user has purchase or not.
/// This is a minimum sample to show the usage.
///
namespace EntitlementAPIRevit
{
public class EntitlementAPI
{
// Get the user id, and check entitlement

string _appId = "appid";
string userId = "userid";
bool isValid = CheckEntitlement(_appId, userId);

if (isValid)
{
// The usert has a valid entitlement, i.e.,
// if paid app, purchase the app from the store.
}

// For now, display the result
string msg = "userId = " + userId
+ "\nappId = " + _appId
+ "\nisValid = " + isValid.ToString();
TaskDialog.Show("Entitlement API", msg);

return Result.Succeeded;
}

private bool CheckEntitlement(string appId, string userId)
{
// REST API call for the entitlement API.
// We are using RestSharp for simplicity.
// You may choose to use other library.

// (1) Build request
var client = new RestClient();
client.BaseUrl = new System.Uri(_baseApiUrl);

// Set resource/end point
var request = new RestRequest();
request.Resource = "webservices/checkentitlement";
request.Method = Method.GET;

// Add parameters
request.AddParameter("userid", userId);
request.AddParameter("appid", appId);

// (2) Execute request and get response
IRestResponse response = client.Execute(request);

// (3) Parse the response and get the value of IsValid.
bool isValid = false;
if (response.StatusCode == HttpStatusCode.OK)
{
JsonDeserializer deserial = new JsonDeserializer();
EntitlementResponse entitlementResponse = deserial.Deserialize<EntitlementResponse>(response);
isValid = entitlementResponse.IsValid;
}

return isValid;
}

[Serializable]
public class EntitlementResponse
{
public string UserId { get; set; }
public string AppId { get; set; }
public bool IsValid { get; set; }
public string Message { get; set; }
}

}
}

Continue reading...
 
Back
Top