public String JsonArrayToList(String JsonResp, String AttrName) { RestSharp.RestResponse response = new RestSharp.RestResponse(); response.Content = JsonResp; RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); AllSlackUsers x = deserial.Deserialize <AllSlackUsers>(response); String Resp = ""; foreach (var Member in x.members) { String AttrToAdd = ""; if (AttrName.Equals("name")) { AttrToAdd = Member.name; } if (AttrName.Equals("id")) { AttrToAdd = Member.id; } if (Resp.Equals("")) { Resp = AttrToAdd; } else { Resp = Resp + "," + AttrToAdd; } } return(Resp); }
public CommandResponse Hangup(string callId) { CommandResponse retVal = null; RestSharp.RestRequest request = new RestSharp.RestRequest(RestSharp.Method.GET); request.Resource = HANGUP_RESOURCE; request.AddParameter(HangupParams.CALL_ID, callId); try { RestSharp.RestResponse response = (RestSharp.RestResponse)restClient.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { retVal = JsonConvert.DeserializeObject <CommandResponse>(response.Content); } else { //TODO: Add Log entry retVal = new CommandResponse(); retVal.callId = callId; retVal.status = -10; retVal.errorMsg = response.Content; } } catch (WebException exc) { //TODO: Add Log entry retVal = new CommandResponse(); retVal.callId = callId; retVal.status = -20; retVal.errorMsg = exc.Message; } return(retVal); }
private void btnGetRESTEntities_Click(object sender, RoutedEventArgs e) { Wizard.Functions.K2CRMConfig config = new Wizard.Functions.K2CRMConfig { User = "******", Domain = "Denallix", Password = "******" }; Wizard.Functions.CRMEntityList el = new Wizard.Functions.CRMEntityList(); K2.Demo.CRM.Wizard.Functions.WizardFunctions functions = new Wizard.Functions.WizardFunctions(); RestSharp.RestResponse <Wizard.Functions.CRMEntityList> a = functions.GetAllEntities(el, config); int q = 0; }
public async Task <ActionResult> updateScore(string quiz, string state, string question, string student, string comment, string score) { // Load saved state _logger.Error("Pulling in a saved state: " + state); oauthHelper oauth = Newtonsoft.Json.JsonConvert.DeserializeObject <oauthHelper>(sqlHelper.getStateJson(Guid.Parse(state))); oauth.accessToken = sqlHelper.getUserAccessToken(long.Parse(oauth.custom_canvas_user_id)); _logger.Error("State loaded: " + state); if (oauth.accessToken != null) { _logger.Error("Checking token validity for state: " + state); //now validate the token to make sure it's still good //if the token is no good try to refresh it if (oauth.accessToken.tokenRefreshRequired) { if (await userCalls.requestUserToken(oauth, oauth.accessToken.responseUrl, "refresh_token", null, oauth.accessToken.refreshToken) == false) { /***********************************************************/ // If we're here it the user may have deleted the access token in their profile. // In this case we will request a brand new token, forcing the user to "Authorize" again. // To test this, delete the token in your Canvas user profile. /***********************************************************/ _logger.Error("Token bad, renewal failed! state: " + state); return(Json(new { Result = "AUTHFAIL" })); } _logger.Error("token renewed! state: " + state); } } //get submission ID (SQL) string submissionID = sqlHelper.getSubmissionID(quiz, oauth.custom_canvas_course_id, question, student); //put score in SQL database sqlHelper.updateStudentSubmissionSQL(quiz, oauth.custom_canvas_course_id, question, student, score, comment); //put score in canvas! RestSharp.RestResponse finalSubmitTest = await userCalls.putQuizQuestionScoreComment(oauth.accessToken.accessToken, "https://" + oauth.host, oauth.custom_canvas_course_id, quiz, submissionID, question, score, comment); //TODO: return status of how stuff went. Probably just this tbh, but more varied reports would be good return(Json(new { Result = "GOO!" })); }
public void NumberOfUnitsTest() { var response = new RestSharp.RestResponse(); response.Content = $@"{{ ""NumberOfUnits"": [ 20.00, 20, 123.123123 ] }}"; var deserializer = new CustomJsonCodec(new Configuration()); var actual = deserializer.Deserialize <TimesheetLine>(response); Assert.Equal(20f, actual.NumberOfUnits[0]); Assert.Equal(20f, actual.NumberOfUnits[1]); Assert.Equal(123.123123, actual.NumberOfUnits[2], precision: 6); }
public String JsonArrayToCSVArray(String JsonResp) { RestSharp.RestResponse response = new RestSharp.RestResponse(); response.Content = JsonResp; RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); AllSlackUsers x = deserial.Deserialize <AllSlackUsers>(response); String Resp = "id" + ColumnSeparator + "name" + ColumnSeparator + "team_id" + ColumnSeparator + "deleted" + ColumnSeparator + "real_name" + ColumnSeparator + "tz" + ColumnSeparator + "tz_label" + ColumnSeparator + "is_admin" + ColumnSeparator + "is_owner" + ColumnSeparator + "is_bot" + RowSeparator; foreach (var Member in x.members) { Resp = Resp + Member.id + ColumnSeparator + Member.name + ColumnSeparator + Member.team_id + ColumnSeparator + Member.deleted + ColumnSeparator + Member.real_name + ColumnSeparator + Member.tz + ColumnSeparator + Member.tz_label + ColumnSeparator + Member.is_admin + ColumnSeparator + Member.is_owner + ColumnSeparator + Member.is_bot + RowSeparator; } return(Resp); }
static TokenModel RenewToken() { Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("grant_type", "refresh_token"); values.Add("client_id", "5520"); values.Add("client_secret", "c5d3cbf06f8ea359f29f41967c5538d5dbe41306"); values.Add("refresh_token", "7039eb70dfab3517b12134c4f8ae2c69d5986386"); Configuration.DefaultApiClient.RestClient.BaseUrl = "https://www.strava.com/oauth"; RestSharp.RestResponse result = Configuration.DefaultApiClient.CallApi("token", RestSharp.Method.POST, values, "grant_type=refresh_token&client_id=5520&client_secret=c5d3cbf06f8ea359f29f41967c5538d5dbe41306&refresh_token=7039eb70dfab3517b12134c4f8ae2c69d5986386", values, values, new Dictionary <string, RestSharp.FileParameter>(), new string[0] { }) as RestSharp.RestResponse; if (result.StatusCode == System.Net.HttpStatusCode.OK) { Configuration.DefaultApiClient.RestClient.BaseUrl = Configuration.DefaultApiClient.BasePath; return(JsonConvert.DeserializeObject <TokenModel>(result.Content)); } return(new TokenModel()); }
public static StravaToken RenewToken(string clientId, string clientSecret, string refreshToken) { Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("grant_type", "refresh_token"); values.Add("client_id", clientId); values.Add("client_secret", clientSecret); values.Add("refresh_token", refreshToken); Configuration.DefaultApiClient.RestClient.BaseUrl = "https://www.strava.com/oauth"; RestSharp.RestResponse result = Configuration.DefaultApiClient.CallApi("token", RestSharp.Method.POST, values, "grant_type=refresh_token&client_id=55818&client_secret=f7517d6028515a37d54eb5a22f2d1a252d93097c&refresh_token=ed9d3d6c85b3806a03bfb75e5b9bc41ee6edddfb", values, values, new Dictionary <string, RestSharp.FileParameter>(), new string[0] { }) as RestSharp.RestResponse; if (result.StatusCode == System.Net.HttpStatusCode.OK) { Configuration.DefaultApiClient.RestClient.BaseUrl = Configuration.DefaultApiClient.BasePath; return(Newtonsoft.Json.JsonConvert.DeserializeObject <StravaToken>(result.Content)); } return(new StravaToken()); }
string GetToken() { var requestUrl = "https://www.reddit.com/api/v1/access_token"; RestSharp.RestClient rc = new RestSharp.RestClient(); RestSharp.RestRequest request = new RestSharp.RestRequest(requestUrl, RestSharp.Method.POST); var appId = Configuration["RedditSecretBot:AppId"]; var Secret = Configuration["RedditSecretBot:Secret"]; request.AddHeader("Authorization", "Basic " + Base64Encode(appId + ":" + Secret)); request.AddParameter("grant_type", "client_credentials"); RestSharp.RestResponse restResponse = (RestSharp.RestResponse)rc.Execute(request); RestSharp.ResponseStatus responseStatus = restResponse.ResponseStatus; if (responseStatus == RestSharp.ResponseStatus.Completed) { var response = restResponse.Content.ToString(); var convertedResponse = JsonConvert.DeserializeObject <TokenResponse>(response); return(convertedResponse.access_token); } return(String.Empty); // The response from this request, //if successful, will be JSON of the following format: //{ // "access_token": Your access token, // "token_type": "bearer", // "expires_in": Unix Epoch Seconds, // "scope": A scope string, //} }
private void Can_Upload_Large_File_Async_Success(RestSharp.RestResponse response) { Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); }
/// <summary> /// Initializes collections /// Should only be called once /// Assumes that the GetInstance function handles locking /// </summary> private Collections() { //Load the JSON file string text = File.ReadAllText(CollectionsJsonPath); RestSharp.RestResponse r = new RestSharp.RestResponse(); r.Content = text; //Parse the JSON file JsonDeserializer deserializer = new JsonDeserializer(); var collection = deserializer.Deserialize<Dictionary<String,String>>(r); m_collection = new Dictionary<string, Collection>(); //Go through and turn the JSON strings into the appropriate classes (for some reason this didn't work automatically) foreach (string k in collection.Keys) { r.Content = collection[k]; //Collections will automatically parse themselves recursively Collection c = deserializer.Deserialize<Collection>(r); m_collection.Add(k, c); } }
private void Can_Upload_File_Async_Callback(RestSharp.RestResponse response) { Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.OK); }
/// <summary> /// Generate a call. /// </summary> /// <param name="destinationType">Type of destination can be one of the following: number – dial normal phone number, ip – dial to an external ip</param> /// <param name="destination">Destination number or ip destination</param> /// <param name="url">Url to send events to</param> /// <param name="appId">Application ID</param> /// <param name="fallbackUrl">Optional - Url to call in case ‘url’ fails</param> /// <param name="dialTimeout">Optional - Timeout for answer on this dial. Default: 30</param> /// <param name="callerIdNum">Optional - Caller ID number. Default: anonymous</param> /// <param name="callerIdName">Optional - Caller id name. Default: anonymous</param> /// <param name="delay">Optional - Delay in seconds before switch will originate the call. Default: none</param> /// <returns></returns> public CommandResponse Dial( eDialDestinationType destinationType, string destination, string url, int appId, string fallbackUrl, int?dialTimeout, string callerIdNum, string callerIdName, int?delay, string trunk, params CustomParam[] customParams) { RestSharp.RestRequest request = new RestSharp.RestRequest(RestSharp.Method.GET); request.Resource = DIAL_RESOURCE; request.AddParameter(DialParams.DEST_TYPE, destinationType.ToString()); request.AddParameter(DialParams.DEST, destination); url = Utils.AddCustomParamsToUrl(url, customParams); request.AddParameter(DialParams.URL, url); request.AddParameter(DialParams.APP_ID, appId); request.AddParameter(DialParams.TRUNK, trunk); if (!string.IsNullOrEmpty(fallbackUrl)) { fallbackUrl = Utils.AddCustomParamsToUrl(fallbackUrl, customParams); request.AddParameter(DialParams.FALLBACK_URL, fallbackUrl); } if (dialTimeout.HasValue) { request.AddParameter(DialParams.DIAL_TIMEOUT, dialTimeout.Value); } if (!string.IsNullOrEmpty(callerIdNum)) { request.AddParameter(DialParams.CALLER_ID_NUM, callerIdNum); } if (!string.IsNullOrEmpty(callerIdName)) { request.AddParameter(DialParams.CALLER_ID_NAME, callerIdName); } if (delay.HasValue) { request.AddParameter(DialParams.DELAY, delay.Value); } CommandResponse retVal = null; try { RestSharp.RestResponse response = (RestSharp.RestResponse)restClient.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { retVal = JsonConvert.DeserializeObject <CommandResponse>(response.Content); } else { //TODO: Add Log entry retVal = new CommandResponse(); retVal.callId = null; retVal.errorMsg = response.Content; retVal.status = -10; } } catch (WebException exc) { //TODO: Add Log entry retVal = new CommandResponse(); retVal.callId = null; retVal.errorMsg = exc.Message; retVal.status = -20; } return(retVal); }
public DropNetResult(RestSharp.RestResponse m) { StatusCode = m.StatusCode; }