Skip to content

Commit

Permalink
Integrated with head of origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Falco20019 committed Feb 24, 2015
2 parents 2811be0 + 35db2f4 commit 9d0373a
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 621 deletions.
4 changes: 2 additions & 2 deletions IS24RestApi.Tests/IS24RestApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="XmlSchemaClassGenerator, Version=0.4.5463.24795, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="XmlSchemaClassGenerator, Version=0.5.5494.29733, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\XmlSchemaClassGenerator-beta.0.4.5463.24795-beta\lib\net45\XmlSchemaClassGenerator.dll</HintPath>
<HintPath>..\packages\XmlSchemaClassGenerator-beta.0.5.5494.29733-beta\lib\net45\XmlSchemaClassGenerator.dll</HintPath>
</Reference>
<Reference Include="xunit.abstractions">
<HintPath>..\packages\xunit.abstractions.2.0.0-beta5-build2785\lib\net35\xunit.abstractions.dll</HintPath>
Expand Down
66 changes: 63 additions & 3 deletions IS24RestApi.Tests/PublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,71 @@ public async Task Publish_UnpublishList_RequestsCorrectResource()
{
Assert.Equal("DELETE", m);
Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/publish/list", Http.Url.GetLeftPart(UriPartial.Path));
Assert.Equal("4711_10000,4712_10000,4713_10000", Http.Parameters.Single(p => p.Name == "publishids").Value);
return new PublishObjects { PublishObject = { new PublishObject { Id = "4711" }, new PublishObject { Id = "4712" }, new PublishObject { Id = "4713" } } };
Assert.Equal("4711_10000,4711_10001,4712_10000,4712_10001,4713_10000,4713_10001", Http.Parameters.Single(p => p.Name == "publishids").Value);
return new PublishObjects
{
PublishObject = { new PublishObject { Id = "4711" }, new PublishObject { Id = "4711" }, new PublishObject { Id = "4712" },
new PublishObject { Id = "4712" }, new PublishObject { Id = "4713" }, new PublishObject { Id = "4714" } }
};
});

await Client.Publish.UnpublishAsync(new[] { new ApartmentRent { Id = 4711 }, new ApartmentRent { Id = 4712 }, new ApartmentRent { Id = 4713 } });
await Client.Publish.UnpublishAsync(new[] { new ApartmentRent { Id = 4711 }, new ApartmentRent { Id = 4712 }, new ApartmentRent { Id = 4713 } },
new[] { 10000, 10001 });
}

[Fact]
public async Task Publish_UnpublishPairList_RequestsCorrectResource()
{
Http.RespondWith(m =>
{
Assert.Equal("DELETE", m);
Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/publish/list", Http.Url.GetLeftPart(UriPartial.Path));
Assert.Equal("4711_10000,4712_10001", Http.Parameters.Single(p => p.Name == "publishids").Value);
return new PublishObjects
{
PublishObject = { new PublishObject { Id = "4711" }, new PublishObject { Id = "4712" } }
};
});

await Client.Publish.UnpublishAsync(new[] { new KeyValuePair<RealEstate, int>(new ApartmentRent { Id = 4711 }, 10000),
new KeyValuePair<RealEstate, int>(new ApartmentRent { Id = 4712 }, 10001) });
}

[Fact]
public async Task Publish_PublishList_RequestsCorrectResource()
{
Http.RespondWith(m =>
{
Assert.Equal("POST", m);
Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/publish/list", Http.Url.GetLeftPart(UriPartial.Path));
Assert.Equal("4711_10000,4711_10001,4712_10000,4712_10001,4713_10000,4713_10001", Http.Parameters.Single(p => p.Name == "publishids").Value);
return new PublishObjects
{
PublishObject = { new PublishObject { Id = "4711" }, new PublishObject { Id = "4711" }, new PublishObject { Id = "4712" },
new PublishObject { Id = "4712" }, new PublishObject { Id = "4713" }, new PublishObject { Id = "4714" } }
};
});

await Client.Publish.PublishAsync(new[] { new ApartmentRent { Id = 4711 }, new ApartmentRent { Id = 4712 }, new ApartmentRent { Id = 4713 } },
new[] { 10000, 10001 });
}

[Fact]
public async Task Publish_PublishPairList_RequestsCorrectResource()
{
Http.RespondWith(m =>
{
Assert.Equal("POST", m);
Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/publish/list", Http.Url.GetLeftPart(UriPartial.Path));
Assert.Equal("4711_10000,4712_10001", Http.Parameters.Single(p => p.Name == "publishids").Value);
return new PublishObjects
{
PublishObject = { new PublishObject { Id = "4711" }, new PublishObject { Id = "4712" } }
};
});

await Client.Publish.PublishAsync(new[] { new KeyValuePair<RealEstate, int>(new ApartmentRent { Id = 4711 }, 10000),
new KeyValuePair<RealEstate, int>(new ApartmentRent { Id = 4712 }, 10001) });
}
}
}
12 changes: 6 additions & 6 deletions IS24RestApi.Tests/RealEstateCountsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public async Task RealEstateCounts_Get_RequestsCorrectResource()
Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestatecounts", Http.Url.GetLeftPart(UriPartial.Path));
return new Realestate.Counts.RealEstateCounts
{
Is24publishedRealEstatesCount = 10,
Is24notPublishedRealEstatesCount = 20
Is24PublishedRealEstatesCount = 10,
Is24NotPublishedRealEstatesCount = 20
};
});

Expand All @@ -42,15 +42,15 @@ public async Task RealEstateCounts_Get_CanDeserializeResponse()
{
Http.RespondWith(m => new Realestate.Counts.RealEstateCounts
{
Is24publishedRealEstatesCount = 10,
Is24notPublishedRealEstatesCount = 20
Is24PublishedRealEstatesCount = 10,
Is24NotPublishedRealEstatesCount = 20
});

var re = await Client.RealEstateCounts.GetAsync();

Assert.IsType<Realestate.Counts.RealEstateCounts>(re);
Assert.Equal(10, re.Is24publishedRealEstatesCount);
Assert.Equal(20, re.Is24notPublishedRealEstatesCount);
Assert.Equal(10, re.Is24PublishedRealEstatesCount);
Assert.Equal(20, re.Is24NotPublishedRealEstatesCount);
}
}
}
2 changes: 1 addition & 1 deletion IS24RestApi.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<package id="Rx-Linq" version="2.2.5" targetFramework="net45" />
<package id="Rx-Main" version="2.2.5" targetFramework="net45" />
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="net45" />
<package id="XmlSchemaClassGenerator-beta" version="0.4.5463.24795-beta" targetFramework="net45" />
<package id="XmlSchemaClassGenerator-beta" version="0.5.5494.29733-beta" targetFramework="net45" />
<package id="xunit" version="2.0.0-beta5-build2785" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0-beta5-build2785" targetFramework="net45" />
<package id="xunit.assert" version="2.0.0-beta5-build2785" targetFramework="net45" />
Expand Down
6 changes: 4 additions & 2 deletions IS24RestApi/BaseXmlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Xml.Linq;
using RestSharp;
using RestSharp.Deserializers;
using System.Xml;

namespace IS24RestApi
{
Expand Down Expand Up @@ -51,10 +52,11 @@ public T Deserialize<T>(IRestResponse response)
if (derivedType != null) type = derivedType;
}

using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(response.Content)))
using (var sr = new StringReader(response.Content))
using (var xr = XmlReader.Create(sr, new XmlReaderSettings { XmlResolver = null }))
{
var serializer = new System.Xml.Serialization.XmlSerializer(type);
return (T)serializer.Deserialize(stream);
return (T)serializer.Deserialize(xr);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions IS24RestApi/IS24RestApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
<DocumentationFile>bin\Release\IS24RestApi.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Threading.Tasks">
Expand Down
2 changes: 1 addition & 1 deletion IS24RestApi/IS24RestApi.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<projectUrl>https://github.com/mganss/IS24RestApi</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Add RealEstateCounts resource, add GetSummaries on RealEstate.</releaseNotes>
<releaseNotes>Add new publish methods.</releaseNotes>
<copyright>Copyright 2013-2015 IS24RestApi project contributors</copyright>
<tags>Immobilienscout24 Immoscout IS24 REST API</tags>
</metadata>
Expand Down
61 changes: 61 additions & 0 deletions IS24RestApi/ImportExport/IPublishResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,47 @@ public interface IPublishResource : IResource
/// <param name="publishChannel">The channel to publish to.</param>
Task PublishAsync(RealEstate realEstate, PublishChannel publishChannel);

/// <summary>
/// Publishes a list of RealEstate objects.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelId">The channelId of the channel to publish to.</param>
/// <exception cref="IS24Exception"></exception>
Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, int channelId);

/// <summary>
/// Publishes a list of RealEstate objects.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="publishChannel">The channel to publish to.</param>
Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, PublishChannel publishChannel);

/// <summary>
/// Publishes a list of RealEstate objects to the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelIds">The channelIds of the channels to publish to.</param>
Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<int> channelIds);

/// <summary>
/// Publishes a list of RealEstate objects to the specified channels.
/// </summary>
/// <param name="realEstateChannelIds">The pairs of RealEstate objects and channelIds to publish to.</param>
Task<PublishObjects> PublishAsync(IEnumerable<KeyValuePair<RealEstate, int>> realEstateChannelIds);

/// <summary>
/// Publishes a list of RealEstate objects to the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="publishChannels">The channels to publish to.</param>
Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<PublishChannel> publishChannels);

/// <summary>
/// Publishes a list of RealEstate objects to the IS24 channel.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates);

/// <summary>
/// Depublishes a list of RealEstate objects.
/// </summary>
Expand All @@ -73,6 +114,26 @@ public interface IPublishResource : IResource
/// <param name="publishChannel">The channel to depublish from.</param>
Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, PublishChannel publishChannel);

/// <summary>
/// Depublishes a list of RealEstate objects from the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelIds">The channelIds of the channels to depublish from.</param>
Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<int> channelIds);

/// <summary>
/// Depublishes a list of RealEstate objects from the specified channels.
/// </summary>
/// <param name="realEstateChannelIds">The pairs of RealEstate objects and channelIds to depublish from.</param>
Task<PublishObjects> UnpublishAsync(IEnumerable<KeyValuePair<RealEstate, int>> realEstateChannelIds);

/// <summary>
/// Depublishes a list of RealEstate objects from the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="publishChannels">The channels to depublish from.</param>
Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<PublishChannel> publishChannels);

/// <summary>
/// Depublishes a list of RealEstate objects from the IS24 channel.
/// </summary>
Expand Down
115 changes: 110 additions & 5 deletions IS24RestApi/ImportExport/PublishResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,85 @@ public Task PublishAsync(RealEstate realEstate, PublishChannel publishChannel)
}

/// <summary>
/// Depublishes a list of RealEstate objects.
/// Publishes a list of RealEstate objects.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelId">The channelId of the channel to depublish from.</param>
/// <param name="channelId">The channelId of the channel to publish to.</param>
/// <exception cref="IS24Exception"></exception>
public async Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, int channelId)
public Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, int channelId)
{
var req = Connection.CreateRequest("publish/list", Method.DELETE);
req.AddParameter("publishids", string.Join(",", realEstates.Select(r => r.Id.Value.ToString() + "_" + channelId)));
return PublishAsync(realEstates, new[] { channelId });
}

/// <summary>
/// Publishes a list of RealEstate objects.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="publishChannel">The channel to publish to.</param>
public Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, PublishChannel publishChannel)
{
return PublishAsync(realEstates, (int)publishChannel.Id.Value);
}

/// <summary>
/// Publishes a list of RealEstate objects to the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelIds">The channelIds of the channels to publish to.</param>
/// <exception cref="IS24Exception"></exception>
public async Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<int> channelIds)
{
var req = Connection.CreateRequest("publish/list", Method.POST);
req.AddParameter("publishids",
string.Join(",", realEstates.SelectMany(r => channelIds.Select(c => r.Id.Value.ToString() + "_" + c))));
var pos = await ExecuteAsync<PublishObjects>(Connection, req);
return pos;
}

/// <summary>
/// Publishes a list of RealEstate objects to the specified channels.
/// </summary>
/// <param name="realEstateChannelIds">The pairs of RealEstate objects and channelIds to publish to.</param>
/// <exception cref="IS24Exception"></exception>
public async Task<PublishObjects> PublishAsync(IEnumerable<KeyValuePair<RealEstate, int>> realEstateChannelIds)
{
var req = Connection.CreateRequest("publish/list", Method.POST);
req.AddParameter("publishids",
string.Join(",", realEstateChannelIds.Select(rc => rc.Key.Id.Value.ToString() + "_" + rc.Value)));
var pos = await ExecuteAsync<PublishObjects>(Connection, req);
return pos;
}

/// <summary>
/// Publishes a list of RealEstate objects to the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="publishChannels">The channels to publish to.</param>
public Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<PublishChannel> publishChannels)
{
return PublishAsync(realEstates, publishChannels.Select(c => (int)c.Id.Value));
}

/// <summary>
/// Publishes a list of RealEstate objects to the IS24 channel.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
public Task<PublishObjects> PublishAsync(IEnumerable<RealEstate> realEstates)
{
return PublishAsync(realEstates, ImportExportClient.ImmobilienscoutPublishChannelId);
}

/// <summary>
/// Depublishes a list of RealEstate objects.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelId">The channelId of the channel to depublish from.</param>
/// <exception cref="IS24Exception"></exception>
public Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, int channelId)
{
return UnpublishAsync(realEstates, new[] { channelId });
}

/// <summary>
/// Depublishes a list of RealEstate objects.
/// </summary>
Expand All @@ -161,6 +227,45 @@ public Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates,
return UnpublishAsync(realEstates, (int)publishChannel.Id.Value);
}

/// <summary>
/// Depublishes a list of RealEstate objects from the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="channelIds">The channelIds of the channels to depublish from.</param>
/// <exception cref="IS24Exception"></exception>
public async Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<int> channelIds)
{
var req = Connection.CreateRequest("publish/list", Method.DELETE);
req.AddParameter("publishids",
string.Join(",", realEstates.SelectMany(r => channelIds.Select(c => r.Id.Value.ToString() + "_" + c))));
var pos = await ExecuteAsync<PublishObjects>(Connection, req);
return pos;
}

/// <summary>
/// Depublishes a list of RealEstate objects from the specified channels.
/// </summary>
/// <param name="realEstateChannelIds">The pairs of RealEstate objects and channelIds to depublish from.</param>
/// <exception cref="IS24Exception"></exception>
public async Task<PublishObjects> UnpublishAsync(IEnumerable<KeyValuePair<RealEstate, int>> realEstateChannelIds)
{
var req = Connection.CreateRequest("publish/list", Method.DELETE);
req.AddParameter("publishids",
string.Join(",", realEstateChannelIds.Select(rc => rc.Key.Id.Value.ToString() + "_" + rc.Value)));
var pos = await ExecuteAsync<PublishObjects>(Connection, req);
return pos;
}

/// <summary>
/// Depublishes a list of RealEstate objects from the specified channels.
/// </summary>
/// <param name="realEstates">The RealEstate objects.</param>
/// <param name="publishChannels">The channels to depublish from.</param>
public Task<PublishObjects> UnpublishAsync(IEnumerable<RealEstate> realEstates, IEnumerable<PublishChannel> publishChannels)
{
return UnpublishAsync(realEstates, publishChannels.Select(c => (int)c.Id.Value));
}

/// <summary>
/// Depublishes a list of RealEstate objects from the IS24 channel.
/// </summary>
Expand Down
Loading

0 comments on commit 9d0373a

Please sign in to comment.