Esempio n. 1
0
        private static async Task TestAsync(Config config)
        {
            var connection = new IS24Connection
            {
                ConsumerKey = config.ConsumerKey,
                ConsumerSecret = config.ConsumerSecret,
                AccessToken = config.AccessToken,
                AccessTokenSecret = config.AccessSecret,
                BaseUrlPrefix = @"https://rest.sandbox-immobilienscout24.de/restapi/api"
            };

            var searchResource = new SearchResource(connection);
            var query = new RadiusQuery
            {
                Latitude = 52.49023,
                Longitude =  13.35939,
                Radius = 1,
                RealEstateType = RealEstateType.APARTMENT_RENT,
                Parameters = new
                {
                    Price = new DecimalRange { Max = 1000 },
                    LivingSpace = new DecimalRange { Min = 100 },
                    NumberOfRooms = new DecimalRange { Min = 4 },
                    Equipment = "balcony"
                },
                Channel = new HomepageChannel("me")
            };
            var results = await searchResource.Search(query);

            var api = new ImportExportClient(connection);
            RealtorContactDetails contact = null;

            try
            {
                contact = await api.Contacts.GetAsync("Hans Meiser", isExternal: true);
            }
            catch (IS24Exception ex)
            {
                if (ex.Messages.Message.First().MessageCode != MessageCode.ERROR_RESOURCE_NOT_FOUND) throw;
            }

            if (contact == null)
            {
                contact = new RealtorContactDetails
                {
                    Lastname = "Meiser",
                    Firstname = "Hans",
                    Address = new Address
                    {
                        Street = "Hauptstraße",
                        HouseNumber = "1",
                        Postcode = "10827",
                        City = "Berlin",
                        InternationalCountryRegion = new CountryRegion { Country = CountryCode.DEU, Region = "Berlin" }
                    },
                    Email = "*****@*****.**",
                    ExternalId = "Hans Meiser"
                };

                await api.Contacts.CreateAsync(contact);

                contact.Address.HouseNumber = "1a";
                await api.Contacts.UpdateAsync(contact);
            }

            IRealEstate realEstate = null;

            try
            {
                realEstate = await api.RealEstates.GetAsync("Hauptstraße 1", isExternal: true);
            }
            catch (IS24Exception ex)
            {
                if (ex.Messages.Message.First().MessageCode != MessageCode.ERROR_RESOURCE_NOT_FOUND) throw;
            }

            if (realEstate == null)
            {
                var re = new ApartmentRent
                {
                    Contact = new RealEstateContact { Id = contact.Id },
                    ExternalId = "Hauptstraße 1",
                    Title = "IS24RestApi Test",
                    Address = new Wgs84Address { Street = "Hauptstraße", HouseNumber = "1", City = "Berlin", Postcode = "10827" },
                    BaseRent = 500.0,
                    LivingSpace = 100.0,
                    NumberOfRooms = 4.0,
                    ShowAddress = true,
                    Courtage = new CourtageInfo { HasCourtage = YesNoNotApplicableType.NO }
                };

                await api.RealEstates.CreateAsync(re);

                re.BaseRent += 100.0;
                await api.RealEstates.UpdateAsync(re);

                realEstate = new RealEstateItem(re, connection);
            }
            else
            {
                var re = (ApartmentRent)realEstate.RealEstate;
                re.BaseRent += 100.0;
                await api.RealEstates.UpdateAsync(re);
                re.BaseRent -= 100.0;
                await api.RealEstates.UpdateAsync(re);
            }

            var projects = await api.RealEstateProjects.GetAllAsync();
            if (projects.RealEstateProject.Any())
            {
                var project = projects.RealEstateProject.First();
                var entries = await api.RealEstateProjects.GetAllAsync(project.Id.Value);
                if (!entries.RealEstateProjectEntry.Any(e => e.RealEstateId.Value == realEstate.RealEstate.Id.Value))
                    await api.RealEstateProjects.AddAsync(project.Id.Value, realEstate.RealEstate);
            }

            var placement = await realEstate.PremiumPlacements.GetAsync();

            var atts = await realEstate.Attachments.GetAsync();
            if (atts == null || !atts.Any())
            {
                var att = new Picture
                {
                    Floorplan = false,
                    TitlePicture = true,
                    Title = "Zimmer",
                };

                await realEstate.Attachments.CreateAsync(att, @"..\..\test.jpg");

                att.Title = "Zimmer 1";
                await realEstate.Attachments.UpdateAsync(att);

                var link = new Link { Title = "Test", Url = "http://www.example.com/" };

                await realEstate.Attachments.CreateAsync(link);

                var video = new StreamingVideo { Title = "Video" };
                await realEstate.Attachments.CreateStreamingVideoAsync(video, @"..\..\test.avi");
            }

            var res = new List<RealEstate>();
            await api.RealEstates.GetAsync().ForEachAsync(x => res.Add(x.RealEstate));
        }
Esempio n. 2
0
        private static async Task TestAsync()
        {
            var config = RestSharp.SimpleJson.DeserializeObject<Config>(File.ReadAllText("config.json"));
            var connection = new IS24Connection
            {
                ConsumerKey = config.ConsumerKey,
                ConsumerSecret = config.ConsumerSecret,
                AccessToken = config.AccessToken,
                AccessTokenSecret = config.AccessSecret,
                BaseUrlPrefix = @"http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0"
            };

            var api = new ImportExportClient(connection);
            RealtorContactDetails contact = null;

            try
            {
                contact = await api.Contacts.GetAsync("Hans Meiser", isExternal: true);
            }
            catch (IS24Exception ex)
            {
                if (ex.Messages.message.First().messageCode != MessageCode.ERROR_RESOURCE_NOT_FOUND) throw;
            }

            if (contact == null)
            {
                contact = new RealtorContactDetails
                {
                    lastname = "Meiser",
                    firstname = "Hans",
                    email = "*****@*****.**",
                    address = new Address
                    {
                        street = "Hauptstraße",
                        houseNumber = "1",
                        postcode = "10827",
                        city = "Berlin",
                        internationalCountryRegion = new CountryRegion { country = CountryCode.DEU, region = "Berlin" }
                    },
                    externalId = "Hans Meiser"
                };

                await api.Contacts.CreateAsync(contact);

                contact.address.houseNumber = "1a";
                await api.Contacts.UpdateAsync(contact);
            }

            IRealEstate realEstate = null;

            try
            {
                realEstate = await api.RealEstates.GetAsync("Hauptstraße 1", isExternal: true);
            }
            catch (IS24Exception ex)
            {
                if (ex.Messages.message.First().messageCode != MessageCode.ERROR_RESOURCE_NOT_FOUND) throw;
            }

            if (realEstate == null)
            {
                var re = new ApartmentRent
                {
                    contact = new RealEstateContact { id = contact.id, idSpecified = true },
                    externalId = "Hauptstraße 1",
                    title = "IS24RestApi Test",
                    address = new Wgs84Address { street = "Hauptstraße", houseNumber = "1", city = "Berlin", postcode = "10827" },
                    baseRent = 500.0,
                    livingSpace = 100.0,
                    numberOfRooms = 4.0,
                    showAddress = true,
                    courtage = new CourtageInfo { hasCourtage = YesNoNotApplicableType.NO }
                };

                await api.RealEstates.CreateAsync(re);

                re.baseRent += 100.0;
                await api.RealEstates.UpdateAsync(re);

                realEstate = new RealEstateItem(re, connection);
            }

            var atts = await realEstate.Attachments.GetAsync();
            if (atts == null || !atts.Any())
            {
                var att = new Picture
                {
                    floorplan = false,
                    titlePicture = true,
                    title = "Zimmer",
                };

                await realEstate.Attachments.CreateAsync(att, @"..\..\test.jpg");

                att.title = "Zimmer 1";
                await realEstate.Attachments.UpdateAsync(att);
            }

            await api.Publish.PublishAsync(realEstate.RealEstate);
            await api.Publish.UnpublishAsync(realEstate.RealEstate);

            var res = new List<RealEstate>();
            await api.RealEstates.GetAsync().ForEachAsync(x => res.Add(x.RealEstate));
        }