This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
676 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/Spring.Social.LinkedIn/Social/LinkedIn/Api/IConnectionOperations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#region License | ||
|
||
/* | ||
* Copyright 2002-2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#endregion | ||
|
||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
#if NET_4_0 || SILVERLIGHT_5 | ||
using System.Threading.Tasks; | ||
#else | ||
using Spring.Rest.Client; | ||
using Spring.Http; | ||
#endif | ||
|
||
namespace Spring.Social.LinkedIn.Api | ||
{ | ||
/// <summary> | ||
/// Interface defining the operations for retrieving authenticated user's connections. | ||
/// </summary> | ||
/// <author>Robert Drysdale</author> | ||
/// <author>Bruno Baia (.NET)</author> | ||
public interface IConnectionOperations | ||
{ | ||
#if NET_4_0 || SILVERLIGHT_5 | ||
/// <summary> | ||
/// Asynchronously retrieves the 1st-degree connections from the authenticated user's network. | ||
/// </summary> | ||
/// <returns> | ||
/// A <code>Task</code> that represents the asynchronous operation that can return | ||
/// a <see cref="LinkedInProfile"/> object representing the user's connections. | ||
/// </returns> | ||
/// <exception cref="LinkedInApiException">If there is an error while communicating with LinkedIn.</exception> | ||
Task<IList<LinkedInProfile>> GetConnectionsAsync(); | ||
|
||
/// <summary> | ||
/// Asynchronously retrieves network statistics for the authenticated user. | ||
/// </summary> | ||
/// <returns> | ||
/// A <code>Task</code> that represents the asynchronous operation that can return | ||
/// a <see cref="NetworkStatistics"/> that contains count of 1st-degree and second degree connections. | ||
/// </returns> | ||
/// <exception cref="LinkedInApiException">If there is an error while communicating with LinkedIn.</exception> | ||
Task<NetworkStatistics> GetNetworkStatisticsAsync(); | ||
#else | ||
#if !SILVERLIGHT | ||
/// <summary> | ||
/// Retrieves the 1st-degree connections from the authenticated user's network. | ||
/// </summary> | ||
/// <returns> | ||
/// A <see cref="LinkedInProfile"/> object representing the user's connections. | ||
/// </returns> | ||
/// <exception cref="LinkedInApiException">If there is an error while communicating with LinkedIn.</exception> | ||
IList<LinkedInProfile> GetConnections(); | ||
|
||
/// <summary> | ||
/// Retrieves network statistics for the authenticated user. | ||
/// </summary> | ||
/// <returns> | ||
/// A <see cref="NetworkStatistics"/> that contains count of 1st-degree and second degree connections. | ||
/// </returns> | ||
/// <exception cref="LinkedInApiException">If there is an error while communicating with LinkedIn.</exception> | ||
NetworkStatistics GetNetworkStatistics(); | ||
#endif | ||
|
||
/// <summary> | ||
/// Asynchronously retrieves the 1st-degree connections from the authenticated user's network. | ||
/// </summary> | ||
/// <param name="operationCompleted"> | ||
/// The <code>Action<></code> to perform when the asynchronous request completes. | ||
/// Provides a <see cref="LinkedInProfile"/> object representing the user's connections. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="RestOperationCanceler"/> instance that allows to cancel the asynchronous operation. | ||
/// </returns> | ||
/// <exception cref="LinkedInApiException">If there is an error while communicating with LinkedIn.</exception> | ||
RestOperationCanceler GetConnectionsAsync(Action<RestOperationCompletedEventArgs<IList<LinkedInProfile>>> operationCompleted); | ||
|
||
/// <summary> | ||
/// Asynchronously retrieves network statistics for the authenticated user. | ||
/// </summary> | ||
/// <param name="operationCompleted"> | ||
/// The <code>Action<></code> to perform when the asynchronous request completes. | ||
/// Provides a <see cref="NetworkStatistics"/> that contains count of 1st-degree and second degree connections. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="RestOperationCanceler"/> instance that allows to cancel the asynchronous operation. | ||
/// </returns> | ||
/// <exception cref="LinkedInApiException">If there is an error while communicating with LinkedIn.</exception> | ||
RestOperationCanceler GetNetworkStatisticsAsync(Action<RestOperationCompletedEventArgs<NetworkStatistics>> operationCompleted); | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Spring.Social.LinkedIn/Social/LinkedIn/Api/Impl/ConnectionTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#region License | ||
|
||
/* | ||
* Copyright 2002-2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
#if NET_4_0 || SILVERLIGHT_5 | ||
using System.Threading.Tasks; | ||
#endif | ||
|
||
using Spring.Http; | ||
using Spring.Rest.Client; | ||
|
||
namespace Spring.Social.LinkedIn.Api.Impl | ||
{ | ||
/// <summary> | ||
/// Implementation of <see cref="IConnectionOperations"/>, providing a binding to LinkedIn's connections-oriented REST resources. | ||
/// </summary> | ||
/// <author>Robert Drysdale</author> | ||
/// <author>Bruno Baia (.NET)</author> | ||
class ConnectionTemplate : IConnectionOperations | ||
{ | ||
private RestTemplate restTemplate; | ||
|
||
public ConnectionTemplate(RestTemplate restTemplate) | ||
{ | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
#region IConnectionOperations Members | ||
|
||
#if NET_4_0 || SILVERLIGHT_5 | ||
public Task<IList<LinkedInProfile>> GetConnectionsAsync() | ||
{ | ||
return this.restTemplate.GetForObjectAsync<IList<LinkedInProfile>>("people/~/connections:(id,first-name,last-name,headline,industry,site-standard-profile-request,public-profile-url,picture-url,summary)?format=json"); | ||
} | ||
|
||
public Task<NetworkStatistics> GetNetworkStatisticsAsync() | ||
{ | ||
return this.restTemplate.GetForObjectAsync<NetworkStatistics>("people/~/network/network-stats?format=json"); | ||
} | ||
#else | ||
#if !SILVERLIGHT | ||
public IList<LinkedInProfile> GetConnections() | ||
{ | ||
return this.restTemplate.GetForObject<IList<LinkedInProfile>>("people/~/connections:(id,first-name,last-name,headline,industry,site-standard-profile-request,public-profile-url,picture-url,summary)?format=json"); | ||
} | ||
|
||
public NetworkStatistics GetNetworkStatistics() | ||
{ | ||
return this.restTemplate.GetForObject<NetworkStatistics>("people/~/network/network-stats?format=json"); | ||
} | ||
#endif | ||
|
||
public RestOperationCanceler GetConnectionsAsync(Action<RestOperationCompletedEventArgs<IList<LinkedInProfile>>> operationCompleted) | ||
{ | ||
return this.restTemplate.GetForObjectAsync<IList<LinkedInProfile>>("people/~/connections:(id,first-name,last-name,headline,industry,site-standard-profile-request,public-profile-url,picture-url,summary)?format=json", operationCompleted); | ||
} | ||
|
||
public RestOperationCanceler GetNetworkStatisticsAsync(Action<RestOperationCompletedEventArgs<NetworkStatistics>> operationCompleted) | ||
{ | ||
return this.restTemplate.GetForObjectAsync<NetworkStatistics>("people/~/network/network-stats?format=json", operationCompleted); | ||
} | ||
#endif | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Spring.Social.LinkedIn/Social/LinkedIn/Api/Impl/Json/LinkedInProfileListDeserializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#region License | ||
|
||
/* | ||
* Copyright 2002-2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#endregion | ||
|
||
using System.Collections.Generic; | ||
|
||
using Spring.Json; | ||
|
||
namespace Spring.Social.LinkedIn.Api.Impl.Json | ||
{ | ||
/// <summary> | ||
/// JSON deserializer for list of LinkedIn user's profiles. | ||
/// </summary> | ||
/// <author>Bruno Baia</author> | ||
class LinkedInProfileListDeserializer : IJsonDeserializer | ||
{ | ||
public object Deserialize(JsonValue value, JsonMapper mapper) | ||
{ | ||
IList<LinkedInProfile> linkedInProfiles = new List<LinkedInProfile>(); | ||
JsonValue usersValue = value.IsObject ? value.GetValue("values") : value; | ||
foreach (JsonValue itemValue in usersValue.GetValues()) | ||
{ | ||
linkedInProfiles.Add(mapper.Deserialize<LinkedInProfile>(itemValue)); | ||
} | ||
return linkedInProfiles; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Spring.Social.LinkedIn/Social/LinkedIn/Api/Impl/Json/NetworkStatisticsDeserializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#region License | ||
|
||
/* | ||
* Copyright 2002-2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#endregion | ||
|
||
using System; | ||
using System.Globalization; | ||
|
||
using Spring.Json; | ||
|
||
namespace Spring.Social.LinkedIn.Api.Impl.Json | ||
{ | ||
/// <summary> | ||
/// JSON deserializer for network statistics. | ||
/// </summary> | ||
/// <author>Bruno Baia</author> | ||
class NetworkStatisticsDeserializer : IJsonDeserializer | ||
{ | ||
public object Deserialize(JsonValue json, JsonMapper mapper) | ||
{ | ||
JsonValue values = json.GetValue("values"); | ||
return new NetworkStatistics() | ||
{ | ||
FirstDegreeCount = values.GetValue<int>(0), | ||
SecondDegreeCount = values.GetValue<int>(1), | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.