Permalink
Browse files

License changed to MIT.

  • Loading branch information...
karpaczio committed Jun 22, 2012
1 parent 6425a4e commit 102df7ec2fa9ee74797f45259aa347ebc0ce032e
Showing with 163 additions and 109 deletions.
  1. +2 −2 pom.xml
  2. +8 −4 src/main/java/pl/nk/social/api/connect/NkConnectionFactory.java
  3. +32 −12 src/main/java/pl/nk/social/api/connect/NkServiceProvider.java
  4. +18 −8 src/main/java/pl/nk/social/api/impl/AbstractNkTemplate.java
  5. +2 −2 src/main/java/pl/nk/social/api/impl/AbusesTemplate.java
  6. +2 −2 src/main/java/pl/nk/social/api/impl/ActivityTemplate.java
  7. +0 −5 src/main/java/pl/nk/social/api/impl/AlbumMixIn.java
  8. +2 −2 src/main/java/pl/nk/social/api/impl/AlbumTemplate.java
  9. +2 −2 src/main/java/pl/nk/social/api/impl/ApplicationTemplate.java
  10. +2 −2 src/main/java/pl/nk/social/api/impl/CommentTemplate.java
  11. +4 −0 src/main/java/pl/nk/social/api/impl/CommonOpenSocialOperations.java
  12. +2 −2 src/main/java/pl/nk/social/api/impl/GiftTemplate.java
  13. +2 −2 src/main/java/pl/nk/social/api/impl/GroupTemplate.java
  14. +2 −2 src/main/java/pl/nk/social/api/impl/MediaItemTemplate.java
  15. +2 −2 src/main/java/pl/nk/social/api/impl/MessageTemplate.java
  16. +24 −18 src/main/java/pl/nk/social/api/impl/NkModule.java
  17. +7 −0 src/main/java/pl/nk/social/api/impl/NkPersonMixIn.java
  18. +29 −14 src/main/java/pl/nk/social/api/impl/NkTemplate.java
  19. +2 −2 src/main/java/pl/nk/social/api/impl/PaymentTemplate.java
  20. +2 −2 src/main/java/pl/nk/social/api/impl/PeopleTemplate.java
  21. +2 −2 src/main/java/pl/nk/social/api/impl/PublicTemplate.java
  22. +2 −2 src/main/java/pl/nk/social/api/impl/RateTemplate.java
  23. +2 −2 src/main/java/pl/nk/social/api/impl/RecommendTemplate.java
  24. +2 −3 src/test/java/pl/nk/social/api/impl/ActivityTemplateTest.java
  25. +3 −5 src/test/java/pl/nk/social/api/impl/AlbumTemplateTest.java
  26. +2 −4 src/test/java/pl/nk/social/api/impl/MediaItemTemplateTest.java
  27. +4 −6 src/test/java/pl/nk/social/api/impl/PeopleTemplateTest.java
View
@@ -14,8 +14,8 @@
<url>https://github.com/karpaczio/spring-social-nk</url>
<licenses>
<license>
<name>GNU General Public License v3.0</name>
<url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
<name>The MIT License (MIT)</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
@@ -1,6 +1,5 @@
package pl.nk.social.api.connect;
import org.springframework.security.oauth.consumer.ProtectedResourceDetails;
import org.springframework.social.connect.support.OAuth2ConnectionFactory;
import pl.nk.social.api.Nk;
@@ -13,10 +12,15 @@
* Constructor for NkConnectionFactory.
* @param clientKey String
* @param clientSecret String
* @param resource ProtectedResourceDetails
*/
public NkConnectionFactory(String clientKey, String clientSecret, ProtectedResourceDetails resource) {
public NkConnectionFactory(String clientKey, String clientSecret) {
super("nk", new NkServiceProvider(clientKey, clientSecret, resource), new NkApiAdapter());
super("nk", new NkServiceProvider(clientKey, clientSecret), new NkApiAdapter());
}
public NkConnectionFactory(String clientKey, String clientSecret, String authenticationServerUrl, String resourceServerUrl) {
super("nk", new NkServiceProvider(clientKey, clientSecret, authenticationServerUrl, resourceServerUrl), new NkApiAdapter());
}
}
@@ -1,5 +1,8 @@
package pl.nk.social.api.connect;
import org.springframework.security.oauth.common.signature.SharedConsumerSecret;
import org.springframework.security.oauth.common.signature.SignatureSecret;
import org.springframework.security.oauth.consumer.BaseProtectedResourceDetails;
import org.springframework.security.oauth.consumer.ProtectedResourceDetails;
import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
import org.springframework.social.oauth2.OAuth2Template;
@@ -8,35 +11,52 @@
import pl.nk.social.api.impl.NkTemplate;
/**
* @author karpaczio
*/
public class NkServiceProvider extends AbstractOAuth2ServiceProvider<Nk> {
private final static String AUTHENTICATION_SERVER_URL_DEFAULT = "https://nk.pl";
private final static String LOGIN_ENDPOINT_SUFFIX = "/oauth2/login";
private final static String TOKEN_ENDPOINT_SUFFIX = "/oauth2/token";
/**
* Field resource.
*/
private final ProtectedResourceDetails resource;
/**
* @param clientKey
* @param clientSecret
* @param resource
*/
public NkServiceProvider(String clientKey, String clientSecret, ProtectedResourceDetails resource) {
super(new OAuth2Template(clientKey, clientSecret, "https://nk.pl/oauth2/login",
// "http://ssl.3pp.omega.nknet/oauth/authenticate",
"https://nk.pl/oauth2/token"));
this.resource = resource;
private final String resourceServerUrl;
public NkServiceProvider(String clientKey, String clientSecret) {
this(clientKey, clientSecret, AUTHENTICATION_SERVER_URL_DEFAULT, null);
}
public NkServiceProvider(String clientKey, String clientSecret, String authenticationServerUrl,
String resourceServerUrl) {
super(new OAuth2Template(clientKey, clientSecret, authenticationServerUrl + LOGIN_ENDPOINT_SUFFIX,
authenticationServerUrl + TOKEN_ENDPOINT_SUFFIX));
BaseProtectedResourceDetails baseResource = new BaseProtectedResourceDetails();
baseResource.setConsumerKey(clientKey);
SignatureSecret secret = new SharedConsumerSecret(clientSecret);
baseResource.setSharedSecret(secret);
baseResource.setId("nk");
this.resource = baseResource;
this.resourceServerUrl = resourceServerUrl;
}
/**
* Method getApi.
* @param accessToken String
*
* @param accessToken
* String
* @return Nk
* @see org.springframework.social.oauth2.OAuth2ServiceProvider#getApi(String)
*/
public Nk getApi(String accessToken) {
return new NkTemplate(accessToken, this.resource);
if (resourceServerUrl != null) {
return new NkTemplate(accessToken, this.resource, this.resourceServerUrl);
} else {
return new NkTemplate(accessToken, this.resource);
}
}
}
@@ -22,15 +22,14 @@
public abstract class AbstractNkTemplate<E extends AbstractNkTemplate> extends AbstractOpenSearchOperations<E> {
/**
* Field SOCIAL_REST_URL_BASE.
* (value is ""http://opensocial.nk-net.pl/v09/social/rest"")
* Url where resource server exposes social resources (e.g. profiles, photos).
*/
public static final String SOCIAL_REST_URL_BASE = "http://opensocial.nk-net.pl/v09/social/rest";
private String socialResourceUrl;
/**
* Field COMMON_URL_BASE.
* (value is ""http://opensocial.nk-net.pl/v09/common"")
* Url where common (not social) resources are exposed (e.g. container version).
*/
public static final String COMMON_URL_BASE = "http://opensocial.nk-net.pl/v09/common";
private String commonResourceUrl;
/**
* Field APPLICATION_JSON_CONTENT_TYPE.
@@ -66,11 +65,22 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public AbstractNkTemplate(RestTemplate restTemplate, boolean isAuthorized) {
public AbstractNkTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
this.restTemplate = restTemplate;
this.isAuthorized = isAuthorized;
this.socialResourceUrl = socialResourceUrl;
this.commonResourceUrl = commonResourceUrl;
}
public String getSocialResourceUrl() {
return socialResourceUrl;
}
public String getCommonResourceUrl() {
return commonResourceUrl;
}
/**
* Method getRestTemplate.
* @return RestTemplate
@@ -95,7 +105,7 @@ protected void requireAuthorization() {
* @return URI
*/
protected URI buildUri(String path, MultiValueMap<String, String> parameters) {
return URIBuilder.fromUri(SOCIAL_REST_URL_BASE + path).queryParams(parameters).build();
return URIBuilder.fromUri(socialResourceUrl + path).queryParams(parameters).build();
}
/**
@@ -13,7 +13,7 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public AbusesTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public AbusesTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
}
@@ -20,8 +20,8 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public ActivityTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public ActivityTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
/**
@@ -4,16 +4,11 @@
import java.util.List;
import org.apache.shindig.social.core.model.AlbumImpl;
import org.apache.shindig.social.opensocial.model.MediaItem;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonValue;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.ser.std.EnumSerializer;
import pl.nk.opensocial.model.ApplicationMediaItem;
import pl.nk.opensocial.model.NkPersonImpl;
/**
*/
@@ -18,8 +18,8 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public AlbumTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public AlbumTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
/**
@@ -13,7 +13,7 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public ApplicationTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public ApplicationTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
}
@@ -13,7 +13,7 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public CommentTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public CommentTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
}
@@ -26,4 +26,8 @@
* @return T
*/
T setFields(Collection<?> fields);
String getSocialResourceUrl();
String getCommonResourceUrl();
}
@@ -13,7 +13,7 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public GiftTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public GiftTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
}
@@ -13,8 +13,8 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public GroupTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public GroupTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
}
@@ -29,8 +29,8 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public MediaItemTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public MediaItemTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
/**
@@ -13,8 +13,8 @@
* @param restTemplate RestTemplate
* @param isAuthorized boolean
*/
public MessageTemplate(RestTemplate restTemplate, boolean isAuthorized) {
super(restTemplate, isAuthorized);
public MessageTemplate(RestTemplate restTemplate, boolean isAuthorized, String socialResourceUrl, String commonResourceUrl) {
super(restTemplate, isAuthorized, socialResourceUrl, commonResourceUrl);
}
}
@@ -1,15 +1,12 @@
package pl.nk.social.api.impl;
import java.util.HashMap;
import org.apache.shindig.protocol.RestfulCollection;
import org.apache.shindig.social.core.model.AlbumImpl;
import org.apache.shindig.social.opensocial.model.Album;
import org.apache.shindig.social.opensocial.model.MediaItem;
import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
import org.codehaus.jackson.map.module.SimpleModule;
import org.codehaus.jackson.map.util.EnumResolver;
import pl.nk.opensocial.model.ApplicationMediaItem;
import pl.nk.opensocial.model.ApplicationMediaItemImpl;
@@ -26,7 +23,7 @@
* Constructor for NkModule.
*/
public NkModule() {
super("NkModule", new Version(0, 0, 1, "SNAPSHOT"));
super("NkModule", new Version(1, 0, 1, "SNAPSHOT"));
}
/**
@@ -36,37 +33,46 @@ public NkModule() {
@Override
public void setupModule(SetupContext context) {
setMixInAnnotation(Album.class, AlbumMixIn.class);
setMixInAnnotation(AlbumImpl.class, AlbumMixIn.class);
setMixInAnnotation(ApplicationMediaItem.class, ApplicationMediaItemMixIn.class);
setMixInAnnotation(ApplicationMediaItemImpl.class, ApplicationMediaItemMixIn.class);
setMixInAnnotation(NkActivity.class, NkActivityMixIn.class);
setMixInAnnotation(NkActivityImpl.class, NkActivityMixIn.class);
setMixInAnnotation(NkPerson.class, NkPersonMixIn.class);
setMixInAnnotation(NkPersonImpl.class, NkPersonMixIn.class);
setMixInAnnotation(RestfulCollection.class, RestfulCollectionMixIn.class);
setMixInAnnotation(context, Album.class, AlbumMixIn.class);
setMixInAnnotation(context, AlbumImpl.class, AlbumMixIn.class);
setMixInAnnotation(context, ApplicationMediaItem.class, ApplicationMediaItemMixIn.class);
setMixInAnnotation(context, ApplicationMediaItemImpl.class, ApplicationMediaItemMixIn.class);
setMixInAnnotation(context, NkActivity.class, NkActivityMixIn.class);
setMixInAnnotation(context, NkActivityImpl.class, NkActivityMixIn.class);
setMixInAnnotation(context, NkPerson.class, NkPersonMixIn.class);
setMixInAnnotation(context, NkPersonImpl.class, NkPersonMixIn.class);
setMixInAnnotation(context, RestfulCollection.class, RestfulCollectionMixIn.class);
// This is because instead of IMAGE we receive image in case of MediaItem.Type
// In jackson-2.0.0 use @JsonValue instead
context.insertAnnotationIntrospector(new NkJacksonAnnotationIntrospector());
super.setupModule(context);
}
private void setMixInAnnotation(SetupContext context, Class<?> target, Class<?> mixinSource) {
context.setMixInAnnotations(target, mixinSource);
// context.getSerializationConfig().addMixInAnnotations(target, mixinSource);
// context.getDeserializationConfig().addMixInAnnotations(target, mixinSource);
}
/**
*/
/* *//**
*//*
class CustomEnumResolver<T extends Enum<T>> extends EnumResolver<T> {
/**
*//**
* Constructor for CustomEnumResolver.
* @param enumClass Class<T>
* @param enums T[]
* @param map HashMap<String,T>
*/
*//*
CustomEnumResolver(Class<T> enumClass, T[] enums, HashMap<String, T> map) {
super(enumClass, enums, map);
}
}
*/
/**
*/
class NkJacksonAnnotationIntrospector extends JacksonAnnotationIntrospector {
@@ -107,4 +107,11 @@
@JsonProperty("urls")
@JsonDeserialize(as = ArrayList.class, contentAs = UrlImpl.class)
private List<Url> urls;
/**
* Field urls.
*/
@JsonProperty("emails")
@JsonDeserialize(as = ArrayList.class, contentAs = ListFieldImpl.class)
private List<ListField> emails;
}
Oops, something went wrong.

0 comments on commit 102df7e

Please sign in to comment.