Esempio n. 1
0
        static void Main(string[] args)
        {
            var adapter = new RestAdapter("https://jsonplaceholder.typicode.com/");
            var service = adapter.Create <IUserService>();

            var response = service.GetUsers();

            Console.WriteLine($"Request: {response.ResponseStatus}");
            var listOfUser = response.Data;

            listOfUser.ForEach(Console.WriteLine);

            var response2 = service.GetUser(1);
            var user      = response2.Data;

            Console.WriteLine(user.ToString());
            Console.WriteLine($"Request: {response2.ResponseStatus}");

            var response3 = service.AddUser(new User {
                Name = "minh"
            });

            Console.WriteLine($"Request: {response3.ResponseStatus}");

            response3 = service.UpdateUser(1, new User {
                Name = "minh"
            });
            Console.WriteLine($"Request: {response3.ResponseStatus}");

            response3 = service.DeleteUser(1);
            Console.WriteLine($"Request: {response3.ResponseStatus}");

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            var restClient = new RestClient("http://danabus.vn/data/2/");
            var adapter    = new RestAdapter(restClient);
            var service    = adapter.Create <IBusService>();

            var respone = service.GetBusService();

            Console.WriteLine(respone.ResponseStatus);

            var obj       = respone.Data;
            var xmlString = ObjectToXmlString(obj);

            Console.WriteLine(xmlString);

            var folder = "../../../XmlFile/";

            SaveAsXml(xmlString, folder, "");

            var id        = "12";
            var responeId = service.GetBusServiceId(id);

            Console.WriteLine(responeId.ResponseStatus);

            var objId = JsonConvert.DeserializeObject <BusServiceId>(responeId.Content);

            SaveBusServiceIdtoXml(id, objId, folder);

            Console.ReadKey();
        }
        public Customer GetCustomer(CustomerIdentifier customerId)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Got message: {0}", customerId.Id);

            var typeNameSerialzier = new TypeNameSerializer();
            Console.WriteLine("Response Type: {0}", typeNameSerialzier.Serialize(typeof(Customer)));
            Console.WriteLine("Request Type: {0}", typeNameSerialzier.Serialize(typeof(CustomerIdentifier)));

            Console.ResetColor();

            var messageDescription = MessageDescriptionFormat.Json;
            var translationFileUri = "./Translations/Json/JavascriptTranslations/GetCustomerTranslation.js";
            var translationReturnType = typeof(Customer);
            var configurationJsonUri = "./ServiceConfigurations/GetCustomerConfiguration.json";

            // Wrap the message
            var wrappedMessage = MessageDescription.Create(
                customerId,
                messageDescription,
                translationFileUri,
                translationReturnType);

            // Get Params
            var @params = translationService.GetMessageParts(wrappedMessage);

            // Known the appropriate Adaptor
            var adapter = new RestAdapter();
            adapter.Initialize(configurationJsonUri, @params);

            var result = adapter.Send<Customer>();

            return result;
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var restClient = new RestClient("http://api.openweathermap.org/data/2.5/");

            restClient.Authenticator = new HttpBasicAuthenticator("Default", "32e86d2782c009304019c7b0526d0155");
            restClient.AddDefaultHeader("content-type", "application/json; charset=utf-8");
            restClient.AddDefaultHeader("charset", "utf-8");

            var adapter = new RestAdapter(restClient);
            var service = adapter.Create <IService>();

            var response = service.GetWeatherFollowGeoLocation("16", "108");

            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);

            response = service.GetWeatherFollowId("1905468");
            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);

            response = service.GetWeatherFollowZipCode("70055");
            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);

            response = service.GetWeatherFollowCityName("Danang");
            Console.WriteLine($"Request: {response.ResponseStatus}");
            Console.WriteLine(response.Content);
            Console.ReadKey();
        }
Esempio n. 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_rest);
            client = new HttpClient();

            get             = FindViewById <Button>(Resource.Id.btn_get);
            getResponse     = FindViewById <TextView>(Resource.Id.tv_get_response);
            getProgress     = FindViewById <ProgressBar>(Resource.Id.pb_get_response);
            getList         = FindViewById <ListView>(Resource.Id.lv_rest);
            adapter         = new RestAdapter(this);
            getList.Adapter = adapter;
            get.Click      += async delegate
            {
                getProgress.Visibility = ViewStates.Visible;
                Uri url = new Uri("https://jsonplaceholder.typicode.com/posts");
                try
                {
                    var response = await client.GetAsync(url);

                    getProgress.Visibility = ViewStates.Invisible;
                    var json = await response.Content.ReadAsStringAsync();

                    Post[] posts = Newtonsoft.Json.JsonConvert.DeserializeObject <Post[]>(json);
                    adapter.data = posts;
                    adapter.NotifyDataSetChanged();
                    getResponse.Text = "llegaron " + posts.Length + " Posts";
                }
                catch (Exception e)
                {
                    getResponse.Text       = "Fallo la peticion: " + e.Message;
                    getProgress.Visibility = ViewStates.Invisible;
                }
            };
        }
Esempio n. 6
0
        public void testApiLoginSuccessful()
        {
            JsonObject loginBody = new JsonObject();

            loginBody.Add("token", ConfigReader.GetLoginToken());
            Assert.AreEqual(HttpStatusCode.OK, RestAdapter.POST("/Auth/Login", loginBody).StatusCode,
                            "Login with correct token was unsuccessful");
        }
Esempio n. 7
0
        public void DoApiLogin()
        {
            RestAdapter.Client.CookieContainer = new CookieContainer();
            JsonObject loginBody = new JsonObject();

            loginBody.Add("token", ConfigReader.GetLoginToken());
            RestAdapter.POST("/Auth/Login", loginBody);
        }
Esempio n. 8
0
        public void testApiLoginFailedForIncorrectToken()
        {
            JsonObject loginBody = new JsonObject();

            loginBody.Add("token", RandomStringUtil.RandomAlphaNumericString(12));
            Assert.AreEqual(HttpStatusCode.BadRequest, RestAdapter.POST("/Auth/Login", loginBody).StatusCode,
                            "Login with wrong toked was successful");
        }
Esempio n. 9
0
        public static bool MachineIsRegistered2()
        {
            RestAdapter            adapter         = new RestAdapter("http://localhost:5400/api/v1/machine");
            IMachine               service         = adapter.Create <IMachine>();
            RestResponse <Machine> machineResponse = service.AutenticateMachine(service.GetMachineIdLocal());
            Machine machine = machineResponse.Data;

            return(false);
        }
Esempio n. 10
0
        public void Init()
        {
            RestClient = new RestAdapter(EYDX_URL);

            //Authorize
            var access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyIsImtpZCI6Im5PbzNaRHJPRFhFSzFqS1doWHNsSFJfS1hFZyJ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CM2l0czdMVVNRR1hSU1hqWkpBQSIsInZlciI6IjEuMCJ9.BF6RbbHfKlcZFuAB94fKFldcIv3HjPoZMvfkxaFVQkPIe62y1UyxNCn7O1vA6MGvcXWJr3nNivNkwGuAQWblph3TQTFGXg2zQPWWLBW-GVY3Ds3RUnIMpZNWOSkZtq_vSrL9SpQm9yVVdWgxgCgNiv179WshUHe5ObRql5gsOg0RfdcsHkS228xZndNUI-UARQaDlEFXVNZAFMl-CY4Mg6vMD6_S9uNV3kCbK_IUx_9svAmVNzDqm9edve_P4w2EdR2SfzuPYtcO6g-3OTafXfk6Xj7Y60wqAoCEMSNe4Tg1hQVsMOjkURu9pS2K04ov6m6eHf-hG592cIy5SyuVgQ";

            RestClient.Authorize(access_token);
        }
Esempio n. 11
0
        public void Init()
        {
            RestClient = new RestAdapter(CTP_URL);
            serializer = new RestSerializer();
            //Authorize
            var access_token = "B~9!6RY6}*MFbDlPeNo7bHYLojM4I5xnYNgMe5YIDtJAeocLF";

            RestClient.Authorize(access_token);
        }
Esempio n. 12
0
        public static void CreateCategoryViaApi(Category category)
        {
            var json = new JsonObject();

            json.Add("categoryName", category.Name());
            var createCategoryResponse = RestAdapter.POST("/Category/Create", json);

            SetIdForCategoryFromResponse(category, createCategoryResponse);
        }
Esempio n. 13
0
        public void testApiDeleteCategoryRestResponse()
        {
            Category category = new Category("Category" + RandomStringUtil.RandomAlphaNumericString(5));

            DoApiLogin();
            CategoryActions.CreateCategoryViaApi(category);

            Assert.AreEqual(HttpStatusCode.OK, RestAdapter.DELETE(String.Format("/Category/Delete/{0}", category.categoryId)).StatusCode,
                            "Category deletion failed");
        }
Esempio n. 14
0
        public void Init()
        {
            RestClient = new RestAdapter(ROOTSITE_URL);
            serializer = new RestSerializer();
            //Authorize
            var access_token = "eyJhbGciOiJSUzI1NiIsImtpZCI6Inh1ak16em5rdmFjWEg1Zmx5NVRCd2ciLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE2MDI2MjQzOTAsImV4cCI6MTYwMjYzMTU5MCwiaXNzIjoiaHR0cHM6Ly9pZGVudGl0eS1xYS5jdHAuZXkuY29tIiwiYXVkIjoicmJhYyIsImNsaWVudF9pZCI6IkdhaWEtUUEiLCJzdWIiOiJlajhIQ1lEeXhXUkZkckZDS0kwbmhycWQ0UEthbTlRTWl0MzQ3RHRnaVVJIiwiYXV0aF90aW1lIjoxNjAyNTk0OTU2LCJpZHAiOiJhYWQiLCJuYW1lIjoiSnVhbiBQZXJleXJhIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiSnVhbi5QZXJleXJhQGV5LmNvbSIsImludGVybmFsX2lkIjoiNzBlMzVkOWUtMDEzNC00NDcyLTgxYzQtY2MxNWE4NzcxMzFmIiwic2NvcGUiOlsib3BlbmlkIiwicHJvZmlsZSIsImVwbXAiLCJyYmFjIl0sImFtciI6WyJleHRlcm5hbCJdfQ.Qhh13cZBqgCIVf-05N4FhhXfVEmF4xXG8QDWwuX5KzvAIHY94Di7TqFzqs6ltoAKyqGC1jNAq9RCG_w_iW0-t70p9lCvNhw33soKZsQvmrwSoP5OvNXcKxSfDL0ZPByBY3BM9-iK984FUO9LHPMLAFGEtlGq6IceNj-xozirBx0j8ncwXyQwUTZwZMgAFRjXq0aStAmxYFFTdaXIImsQc5aOyeMvNAKshY65ZEWp32RVP4xJJDtLtR1oB9Y8Ek0aMhe5gz0Sag8ayYm6gaazlEwzwWt7TAFOTiL_9BuQ3G7QqlIJABY4DUIyhhk41_IbNsJ1FQtyPLC3AUxvQOOnPg";

            RestClient.Authorize(access_token);
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
        }
Esempio n. 15
0
        public void testApiDeletedCategoryIsNotInCategoriesList()
        {
            Category category = new Category("Category" + RandomStringUtil.RandomAlphaNumericString(5));

            DoApiLogin();
            CategoryActions.CreateCategoryViaApi(category);
            category.stock = 0;
            RestAdapter.DELETE(String.Format("/Category/Delete/{0}", category.categoryId));
            List <Category> categories = jsonDeserializer.Deserialize <List <Category> >(RestAdapter.GET("/Category/Index"));

            CollectionAssert.DoesNotContain(categories, category, "Deleted category is in categories list");
        }
Esempio n. 16
0
        public void testApiCreateCategoryRestResponse()
        {
            DoApiLogin();
            Category category = new Category("Category" + RandomStringUtil.RandomAlphaNumericString(5));

            var json = new JsonObject();

            json.Add("categoryName", category.Name());

            var createCategoryResponse = RestAdapter.POST("/Category/Create", json);

            Assert.AreEqual(HttpStatusCode.OK, createCategoryResponse.StatusCode,
                            "Category creation failed");
        }
        static void SendEmail(string emailString, string content)
        {
            var restClient = new RestClient("https://us17.api.mailchimp.com/3.0/");

            restClient.Authenticator = new HttpBasicAuthenticator("username", ApiKey);
            restClient.AddDefaultHeader("content-type", "application/json");

            var adapter = new RestAdapter(restClient);
            var service = adapter.Create <IService>();

            var email = new Email {
                EmailAddress = emailString, Status = "subscribed"
            };

            SimpleJson.CurrentJsonSerializerStrategy = new SerializerStrategy();
            var responseAddEmail = service.AddEmail(IdList, email);

            var campaign = new
            {
                recipients = new { list_id = IdList },
                type       = "regular",
                settings   = new
                {
                    subject_line = "Only Test 1",
                    reply_to     = "*****@*****.**",
                    from_name    = "minh"
                }
            };
            var responseCreateCampaign = service.CreateCampaign(campaign);

            IdCompaign = JsonConvert.DeserializeObject <Campaign>(responseCreateCampaign.Content).id;

            var responseSetContent = service.SetContent(IdCompaign, new { html = content });

            var responseSendContent = service.SendContent(IdCompaign);

            if (responseAddEmail.ResponseStatus.ToString().Contains("Completed") && responseCreateCampaign.ResponseStatus.ToString().Contains("Completed") && responseSetContent.ResponseStatus.ToString().Contains("Completed") && responseSendContent.StatusCode.ToString().Contains("NoContent"))
            {
                Console.WriteLine("Send: complete");
            }
            else
            {
                Console.WriteLine("Send: error");
                Console.WriteLine($"Add email: {responseAddEmail.ResponseStatus}");
                Console.WriteLine($"Create campaign: {responseCreateCampaign.ResponseStatus}");
                Console.WriteLine($"Set content: {responseSetContent.ResponseStatus}");
                Console.WriteLine($"Send content: {responseSendContent.StatusCode}");
            }
        }
Esempio n. 18
0
        public ActionResult MakeCall([FromBody] RestCall callDescription)
        {
            try
            {
                var restAdapter = new RestAdapter(callDescription);
                return(Ok(JObject.Parse(restAdapter.ExecuteRestCall())));
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(TimeoutException))
                {
                    return(StatusCode(408, new { MessageError = ex.Message }));
                }

                return(BadRequest(new { MessageError = ex.Message.ToString() }));
            }
        }
Esempio n. 19
0
        public void PostAutomationTriggerTestWithoutToken()
        {
            PostAutomationTrigger request = new PostAutomationTrigger();

            request.RequestingUser      = "";
            request.ProjectName         = "";
            request.ProjectTeamMembers  = new string[] { };
            request.ServiceLine         = "";
            request.ServiceInstanceName = "";
            request.OfferingName        = "";
            request.Location            = "";
            request.EngagementCode      = "";
            request.Sponsor             = "";
            request.Environment         = "";
            request.Parameters          = new Dictionary <string, string>()
            {
            };
            request.ContentType = "application/json";

            RestAdapter   RestClientWithoutToken = new RestAdapter(CTP_URL);
            IRestResponse response = RestClientWithoutToken.Create(request);

            Assert.That((int)response.StatusCode, Is.EqualTo(401), "Automation Trigger endpoint is not working properly");
        }
Esempio n. 20
0
        public void testApiCreatedCategoryIsInTheCategoriesList()
        {
            Category category = new Category("Category" + RandomStringUtil.RandomAlphaNumericString(5));

            DoApiLogin();
            CategoryActions.CreateCategoryViaApi(category);
            category.stock = 0;

            List <Category> categories = jsonDeserializer.Deserialize <List <Category> >(RestAdapter.GET("/Category/Index"));

            CollectionAssert.Contains(categories, category, "Created category is not in categories list");
        }
        public void AddCustomer(Customer customer)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Got message: {0}", customer.Id);
            Console.WriteLine("First Name: {0}", customer.Name.FirstName);
            Console.WriteLine("First Last Name: {0}", customer.Name.LastName);
            Console.ResetColor();

            var messageDescription = MessageDescriptionFormat.Json;
            var translationFileUri = "./Translations/Json/JavascriptTranslations/CustomerToCustomerTranslation.js";
            var translationReturnType = typeof(Customer);
            var configurationJsonUri = "./ServiceConfigurations/CustomerConfiguration.json";

            // Wrap the message
            var wrappedMessage = MessageDescription.Create(
                customer,
                messageDescription,
                translationFileUri,
                translationReturnType);

            // Get Params
            var @params = translationService.GetMessageParts(wrappedMessage);
            // Call the translation on customer
            var translated = translationService.Translate<Customer, Customer>(wrappedMessage);            

            // Known the appropriate Adaptor
            var adapter = new RestAdapter();
            adapter.Initialize(configurationJsonUri);

            // Send to the Adaptor
            adapter.SendAsync(translated);
        }
Esempio n. 22
0
 public void SetUp()
 {
     restClient = Substitute.For <IRestClient>();
     adapter    = new RestAdapter(restClient);
     client     = adapter.Create <IRestInterface>();
 }
 public void SetUp()
 {
     adapter = new RestAdapter("http://jordanthoms.apiary.io/");
     service = adapter.Create<IPeopleService>();
 }
Esempio n. 24
0
 public void Init()
 {
     RestClient = new RestAdapter(Content_URL);
 }
Esempio n. 25
0
 public void SetUp()
 {
     restClient = Substitute.For<IRestClient>();
     adapter = new RestAdapter(restClient);
     client = adapter.Create<IRestInterface>();
 }
Esempio n. 26
0
 public void SetUp()
 {
     adapter = new RestAdapter("http://jordanthoms.apiary.io/");
     service = adapter.Create <IPeopleService>();
 }
 public BaseConsulSender()
 {
     adapter = new RestAdapter();
 }