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;
 }
        /// <summary>
        /// Gets the posts from the api.
        /// </summary>
        /// <param name="sorting">Current sorting</param>
        public async Task GetPostsAsync(Sorting sorting = Sorting.Latest)
        {
            this.currentSorting = sorting;

            using (var client = new RestClient("http://localhost:55298/api/"))
            {
                var request = new RestRequest("posts/{sorting}", Method.GET);
                request.AddUrlSegment("sorting", sorting.ToString());

                var result = await client.Execute<List<Post>>(request);

                this.Posts = result.Data;
            }
        }
Exemple #3
0
 async static Task MainAsync(string[] args, CancellationTokenSource cts)
 {
     using (RestClient client = new RestClient("http://localhost:4711") { Timeout = new TimeSpan(0, 0, 10) })
     {
         while (!cts.Token.IsCancellationRequested)
         {
             if (Console.KeyAvailable)
             {
                 var key = Console.ReadKey();
                 switch (key.KeyChar)
                 {
                     case 'a':
                         {
                             RestRequest request = new RestRequest("Hello", RestSharp.Portable.Method.POST);
                             request.AddJsonBody(new HelloRequest
                                 {
                                     Text = "HelloText",
                                     Id = 1,
                                 });
                             var response = await client.Execute<HelloResponse>(request);
                             Console.WriteLine($"Hello Response Text={response.Data.Text} Id={response.Data.Id}");
                             break;
                         }
                     case'b':
                         {
                             RestRequest request = new RestRequest("User/{id}", RestSharp.Portable.Method.GET);
                             request.AddUrlSegment("id", 1);
                             var response = await client.Execute<string>(request);
                             Console.WriteLine($"User Response Text={Encoding.UTF8.GetString(response.RawBytes)}");
                             break;
                         }
                     case 'c':
                         {
                             RestRequest request = new RestRequest("User/{id}", RestSharp.Portable.Method.GET);
                             request.AddUrlSegment("id", 666);
                             var response = await client.Execute(request);
                             Console.WriteLine($"User Response Text={Encoding.UTF8.GetString(response.RawBytes)}");
                             break;
                         }
                     case '\n':
                         cts.Cancel();
                         return;
                 }
             }
             else
                 Thread.Sleep(100);
         }
     } 
 }
Exemple #4
0
        private async Task CallMethodAsync(string method, string customerId, HttpMethod httpMethod, object data)
        {
            var request = new RestRequest(method)
            {
                Method = httpMethod,
                Serializer = new SerializerWrapper(this._jsonSerializer)
            };
            
            if (customerId != null)
            {
                request.AddUrlSegment(@"customer_id", customerId);
            }
            request.AddBody(data);

            var response = await this._client.Execute(request).ConfigureAwait(false);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new CustomerIoApiException(response.StatusCode);
            }
        }
 public static async Task<List<List<string>>> GetEventRankings(string key)
 {
     var request = new RestRequest(ApiUrl.EventRankings);
     request.AddUrlSegment("key", key);
     return await MakeRequest<List<List<string>>>(request);
 }
 public static Task<EventStats> GetEventStats(string key)
 {
     var request = new RestRequest(ApiUrl.EventStats);
     request.AddUrlSegment("key", key);
     return MakeRequest<EventStats>(request);
 }
 public static Task<List<Team>> GetEventTeams(string key)
 {
     var request = new RestRequest(ApiUrl.EventTeams);
     request.AddUrlSegment("key", key);
     return MakeRequest<List<Team>>(request);
 }
 public static Task<List<Event>> GetEvents(int year)
 {
     var request = new RestRequest(ApiUrl.EventList);
     request.AddUrlSegment("year", year);
     return MakeRequest<List<Event>>(request);
 }
 public static async Task<List<Team>> GetTeams(int page)
 {
     var request = new RestRequest(ApiUrl.TeamPage);
     request.AddUrlSegment("page", page);
     return await MakeRequest<List<Team>>(request);
 }