public App() { this.serializer = new JsonSerializer (); this.result = JsonConvert.DeserializeObject ("{ \"auth\":\"12345\"}") as Dictionary<string, string>; this.restClient = new RestClient (); var request = new RestRequest (new Uri ("http://google.com"), HttpMethod.Get); this.httpContent = restClient.GetContent (request); this.imageButton = new ImageButton(); this.imageButton.Text = "Image Text"; this.imageButton.Source = "icon.png"; this.checkbox = new CheckBox (); this.checkbox.Checked = true; // The root page of your application MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { XAlign = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" } } } }; }
public async Task<Club> Get(int id) { var request = new RestRequest(EndPoint + "/{id}", Method.GET); request.AddParameter("id", id, ParameterType.UrlSegment); var response = await _client.RestClient.Execute<Club>(request); return response.Data; }
public async Task<Activity> Get(long activityId, bool includeAllEfforts = true) { var request = new RestRequest(EndPoint + "/{id}", Method.GET); request.AddParameter("id", activityId, ParameterType.UrlSegment); var response = await _client.RestClient.Execute<Activity>(request); return response.Data; }
/// <summary> /// Executes a call to a web method without any persistence. /// </summary> /// <param name="restRequest">the <see cref="RestRequest"/></param> /// <param name="attempsCount">the current attemp number</param> /// <returns>The content of the </returns> public virtual async Task<Tuple<byte[], double>> ExecuteHttpRequest(RestRequest restRequest, int attempsCount = 0) { attempsCount++; var callType = restRequest.Method.ToString(); var resource = client.BuildUri(restRequest).AbsoluteUri; Debug("Running the HTTP '" + callType + "' request '" + resource + "'"); var start = TimeSpan.FromTicks(DateTime.Now.Ticks); var rawResponse = await client.Execute(restRequest); var end = TimeSpan.FromTicks(DateTime.Now.Ticks); var responseTimeInMs = (end - start).TotalMilliseconds; var data = rawResponse.RawBytes; var tuple = new Tuple<byte[], double>(data, responseTimeInMs); var statusCode = rawResponse.StatusCode; Debug("The call to the HTTP " + callType + " request '" + resource + "' took " + responseTimeInMs + " ms and returned the status code '" + statusCode + "'"); if (statusCode != HttpStatusCode.OK) { if (attempsCount < M4MBaseWebServiceCaller.ATTEMPTS_COUNT_MAX) { tuple = await ExecuteHttpRequest(restRequest, attempsCount); } else { OnHttpStatusCodeNotOk(resource, statusCode); } } return tuple; }
public RestRequest CreateAccountInfoRequest() { var request = new RestRequest("{version}/account/info", HttpMethod.Get); request.AddParameter("version", _version, ParameterType.UrlSegment); return request; }
public RestRequest CreateAccessTokenRequest() { var request = new RestRequest("{version}/oauth/access_token", HttpMethod.Get); request.AddParameter("version", _version, ParameterType.UrlSegment); return request; }
public PubMedPublicationIdsResult GetPublicationsIds(PubMedQueryFilter filter) { var restClient = new RestClient(ServiceURLs.ESearchBaseURL); var restRequest = new RestRequest(); restRequest.AddParameter("db", databaseName, ParameterType.QueryString); restRequest.AddParameter("retmode", "json", ParameterType.QueryString); restRequest.AddParameter("retstart", (filter.Skip * filter.Take), ParameterType.QueryString); restRequest.AddParameter("term", filter.Query, ParameterType.QueryString); restRequest.AddParameter("retmax", filter.Take, ParameterType.QueryString); if (filter.RelDate != DateTime.MinValue) { var pmDate = PubMedDateOperations.DatetimeToPubMedDate(filter.RelDate); restRequest.AddParameter("reldate", pmDate, ParameterType.QueryString); } var waitTime = PubMedThrottler.GetWaitTime(); Thread.Sleep(waitTime); var response = restClient.Execute<PubMedResponse>(restRequest).Result; if (response.Data == null) throw new Exception("No Response From The Server"); var result = new PubMedPublicationIdsResult(); result.PubMedIdCollection = new List<string>(); response.Data.esearchresult.idlist.ForEach(r => result.PubMedIdCollection.Add(r)); return result; }
public int Register(string password) { var request = new RestRequest("api/Register", HttpMethod.Post); request.AddParameter("DeviceId", _deviceId); request.AddParameter("Password", password); return Execute<int>(request); }
public bool Login(string password) { var request = new RestRequest(ApiUris.Login, HttpMethod.Post); request.AddParameter("DeviceId", _deviceId); request.AddParameter("Password", password); _sessionId = Execute<string>(request); return _sessionId != null; }
public async Task<ICollection<UsuarioModel>> GetUsuarios() { var request = new RestRequest("Usuario") {Method = Method.GET}; var response = await client.Execute<ICollection<UsuarioModel>>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<List<SegmentSummary>> Explore(LatLng southWest, LatLng northEast, ActivityType activityType = ActivityType.Ride) { var request = new RestRequest(EndPoint + "/explore", Method.GET); request.AddParameter("bounds", string.Format("{0},{1},{2},{3}", southWest.Latitude.ToString(CultureInfo.InvariantCulture), southWest.Longitude.ToString(CultureInfo.InvariantCulture), northEast.Latitude.ToString(CultureInfo.InvariantCulture), northEast.Longitude.ToString(CultureInfo.InvariantCulture))); var response = await _client.RestClient.Execute<SegmentCollection>(request); return response.Data.Segments; }
public async Task<UsuarioModel> AddUsuario(UsuarioModel usuario) { var request = new RestRequest("Usuario") { Method = Method.POST //Otra forma de hacerlo }; request.AddJsonBody(usuario); var response = await client.Execute<UsuarioModel>(request); return response.IsSuccess ? response.Data : null; }
public static RestRequest CreateCountriesRequest(int page, int countriesPerPage, RequestFormat format) { var restReq = new RestRequest(HttpMethod.Get); restReq.AddQueryParameter("format", format.ToString()); restReq.AddQueryParameter("page", page); restReq.AddQueryParameter("per_page", countriesPerPage); return restReq; }
public async Task<MensajeModel> AddMensaje(MensajeModel mensaje) { var request = new RestRequest("Mensaje"); request.Method = Method.POST; request.AddJsonBody(mensaje); var response = await client.Execute<MensajeModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<UsuarioModel> GetUsuariosId(int id) { var request = new RestRequest("Usuario"); request.Method = Method.GET; request.AddQueryParameter("id", id); var response = await client.Execute<UsuarioModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<UsuarioModel> AddUsuario(UsuarioModel usuario) { var request = new RestRequest("Usuario"); request.Method = Method.POST; request.AddJsonBody(usuario); var response = await client.Execute<UsuarioModel>(request); if (response.IsSuccess) return response.Data; return null; }
public Task<Component> UpdateComponentStatusAsync(string roomId, string deviceId, bool status) { var request = new RestRequest("components?roomId={roomId}&deviceId={deviceId}&status={status}") {Method = HttpMethod.Put}; request.AddUrlSegment("roomId", roomId) .AddUrlSegment("deviceId", deviceId) .AddUrlSegment("status", status); request.AddHeader("Content-Type", "application/json"); var task = _client.Execute<Component>(request).ContinueWith(t => t.Result.Data); return task; }
public async Task<bool> UsuarioNuevo(string username) { var request = new RestRequest("Usuario"); request.Method = Method.GET; request.AddQueryParameter("Username", username); var response = await client.Execute<bool>(request); if (response.IsSuccess) return response.Data; return false; }
public async Task<bool> CheckUsuario(string email) { var request = new RestRequest("Usuario") { Method = Method.GET }; request.AddQueryParameter("email", email); var response = await _client.Execute<bool>(request); if (response.IsSuccess) return response.Data; return false; }
public async Task<UsuarioModel> ValidarUsuario(UsuarioModel usuario) { var request = new RestRequest("Usuario"); request.Method = Method.GET; request.AddQueryParameter("Username", usuario.Username); request.AddQueryParameter("Password", usuario.Password); var response = await client.Execute<UsuarioModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<List<AthleteSummary>> GetMembers(int id, int page, int itemsPerPage) { var request = new RestRequest(EndPoint + "/{id}/members", Method.GET); request.AddParameter("id", id, ParameterType.UrlSegment); if (page != 0) request.AddParameter("page", page); if (itemsPerPage != 0) request.AddParameter("per_page", itemsPerPage); var response = await _client.RestClient.Execute<List<AthleteSummary>>(request); return response.Data; }
public async Task<TareaModel> AddTarea(TareaModel tarea) { var request = new RestRequest("Tarea"); request.Method = Method.POST; request.AddJsonBody(tarea); var response = await client.Execute<TareaModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<ICollection<TareaModel>> GetByGrupo(int id) { var request = new RestRequest("Tarea"); request.Method = Method.GET; request.AddQueryParameter("idGrupo", id); var response = await client.Execute<ICollection<TareaModel>>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<GrupoModel> AddGrupo(GrupoModel grupo) { var request=new RestRequest("Grupo"); request.Method=Method.POST; request.AddJsonBody(grupo); var response = await client.Execute<GrupoModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<UsuarioModel> ValidarUsuario(UsuarioModel usuario) { var request = new RestRequest("Usuario"); //Al request se le pueden añadir Headers, y al client se le pueden añadir credentials request.Method = Method.GET; request.AddQueryParameter("login", usuario.login); request.AddQueryParameter("password", usuario.password); var reponse = await client.Execute<UsuarioModel>(request); if (reponse.IsSuccess) return reponse.Data; return null; }
public async Task<List<ContactoModel>> GetContactos(bool actuales, int id) { var request = new RestRequest("Contactos"); request.Method = Method.GET; request.AddQueryParameter("id", id); request.AddQueryParameter("amigos", actuales); var reponse = await client.Execute<List<ContactoModel>>(request); if (reponse.IsSuccess) return reponse.Data; return null; }
public async Task<ContactoModel> AddContacto(ContactoModel contacto) { var request = new RestRequest("Contactos") { Method = Method.POST }; request.AddJsonBody(contacto); var reponse = await client.Execute<ContactoModel>(request); if (reponse.IsSuccess) return reponse.Data; return null; }
public RestRequest CreateChunkedUploadRequest(ChunkedUpload upload, byte[] fileData) { var request = new RestRequest("{version}/chunked_upload", HttpMethod.Put); request.AddParameter("version", _version, ParameterType.UrlSegment); if (upload.HasUploadId) { request.AddParameter("upload_id", upload.UploadId, ParameterType.UrlSegment); request.AddParameter("offset", upload.Offset, ParameterType.UrlSegment); } request.AddParameter("file", fileData, ParameterType.RequestBody); return request; }
public async Task<String> SubirFoto(byte[] file) { var client = new RestClient(url); var request = new RestRequest(); request.Method = Method.POST; var d = new FotosModel() {Data = Convert.ToBase64String(file), idFoto = 2}; request.AddJsonBody(d); var r = await client.Execute<string>(request); return r.Data; }
public static async Task<JObject> Execute(string callback, HttpMethod httpMethod, Dictionary<string,string> parameters, Dictionary<string,string> files = null, object obj = null) { //init request var request = new RestRequest (callback, httpMethod); request.AddHeader("Content-Type", "application/json; charset=utf-8"); //add parameters foreach (var key in parameters.Keys) { request.AddParameter (key, parameters [key].ToString ()); } //add files //if (files != null && files.Keys.Count > 0) { // foreach (var key in files.Keys) { // request.AddFile( .AddFile (key, files[key]); // } //} //execute var result = await client.Execute<string>(request); //print response Debug.WriteLine (callback); Debug.WriteLine (result.Data); //save cookies //var sessionCookie = response.Cookies.SingleOrDefault(x => x.Name == "WRAD_SESSION"); //if (sessionCookie != null && APIHelper.restClient.CookieContainer==null) //{ // APIHelper.restClient.CookieContainer = new CookieContainer (); /// APIHelper.restClient.CookieContainer.Add(new Uri(APIHelper.baseUrl),new Cookie(sessionCookie.Name, sessionCookie.Value, sessionCookie.Path, sessionCookie.Domain)); //} //string to JObect deserialization try{ return JObject.Parse(result.Data); } catch(Exception ex){ Debug.WriteLine (ex.Message + (ex.InnerException != null ? ("\n" + ex.InnerException.Message) : "")); return null; } }