Permalink
Browse files

Merge pull request #57 from habuma/master

Initial cut of Java-config support for Facebook connection factory and API binding.
  • Loading branch information...
2 parents 3e0b742 + 2309e40 commit 521bc1d511c98fa259bf7afd18b6911cf71714b1 @habuma habuma committed Sep 14, 2012
@@ -195,13 +195,7 @@ public void deletePost(String id) {
}
public List<Post> searchPublicFeed(String query, int offset, int limit) {
- URI uri = URIBuilder.fromUri("https://graph.facebook.com/search")
- .queryParam("q", query)
- .queryParam("type", "post")
- .queryParam("offset", String.valueOf(offset))
- .queryParam("limit", String.valueOf(limit))
- .build();
- JsonNode responseNode = restTemplate.getForObject(uri, JsonNode.class);
+ JsonNode responseNode = restTemplate.getForObject("https://graph.facebook.com/search?q={query}&type=post&offset={offset}&limit={limit}", JsonNode.class, query, offset, limit);
return deserializeList(responseNode, null, Post.class);
}
@@ -0,0 +1,54 @@
+/*
+ * Copyright 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.
+ */
+package org.springframework.social.facebook.config.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.context.annotation.Import;
+import org.springframework.social.connect.ConnectionFactoryLocator;
+import org.springframework.social.connect.ConnectionRepository;
+import org.springframework.social.facebook.api.Facebook;
+import org.springframework.social.facebook.connect.FacebookConnectionFactory;
+
+/**
+ * Annotation to enable Facebook in a Spring Social application.
+ * Configures a {@link FacebookConnectionFactory} bean (and a {@link ConnectionFactoryLocator} bean if one isn't already registered).
+ * Also configures a request-scoped {@link Facebook} bean fetched from the current user's {@link ConnectionRepository}.
+ * @author Craig Walls
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@Import(FacebookProviderConfigRegistrar.class)
+public @interface EnableFacebook {
+
+ /**
+ * The application's App ID as issued by Facebook.
+ */
+ String appId();
+
+ /**
+ * The application's App Secret as issued by Facebook.
+ */
+ String appSecret();
+
+}
@@ -0,0 +1,67 @@
+/*
+ * Copyright 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.
+ */
+package org.springframework.social.facebook.config.annotation;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
+import org.springframework.social.config.annotation.ProviderConfigRegistrarSupport;
+import org.springframework.social.config.xml.ApiHelper;
+import org.springframework.social.config.xml.UserIdSource;
+import org.springframework.social.connect.Connection;
+import org.springframework.social.connect.UsersConnectionRepository;
+import org.springframework.social.facebook.api.Facebook;
+import org.springframework.social.facebook.api.impl.FacebookTemplate;
+import org.springframework.social.facebook.connect.FacebookConnectionFactory;
+
+/**
+ * {@link ImportBeanDefinitionRegistrar} for configuring a {@link FacebookConnectionFactory} bean and a request-scoped {@link Facebook} bean.
+ * @author Craig Walls
+ */
+public class FacebookProviderConfigRegistrar extends ProviderConfigRegistrarSupport {
+
+ public FacebookProviderConfigRegistrar() {
+ super(EnableFacebook.class, FacebookConnectionFactory.class, FacebookApiHelper.class);
+ }
+
+ static class FacebookApiHelper implements ApiHelper<Facebook> {
+
+ private final UsersConnectionRepository usersConnectionRepository;
+
+ private final UserIdSource userIdSource;
+
+ private FacebookApiHelper(UsersConnectionRepository usersConnectionRepository, UserIdSource userIdSource) {
+ this.usersConnectionRepository = usersConnectionRepository;
+ this.userIdSource = userIdSource;
+ }
+
+ public Facebook getApi() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Getting API binding instance for Facebook provider");
+ }
+
+ Connection<Facebook> connection = usersConnectionRepository.createConnectionRepository(userIdSource.getUserId()).findPrimaryConnection(Facebook.class);
+ if (logger.isDebugEnabled() && connection == null) {
+ logger.debug("No current connection; Returning default FacebookTemplate instance.");
+ }
+ return connection != null ? connection.getApi() : new FacebookTemplate();
+ }
+
+ private final static Log logger = LogFactory.getLog(FacebookApiHelper.class);
+
+ }
+
+}
@@ -15,6 +15,8 @@
*/
package org.springframework.social.facebook.config.xml;
+import java.util.Map;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -27,8 +29,6 @@
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.impl.FacebookTemplate;
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
/**
* Implementation of {@link AbstractConnectionFactoryBeanDefinitionParser} that creates a {@link FacebookConnectionFactory}.
@@ -41,11 +41,10 @@ public FacebookConfigBeanDefinitionParser() {
}
@Override
- protected BeanDefinition getConnectionFactoryBeanDefinition(String appId, String appSecret, NamedNodeMap allAttributes) {
+ protected BeanDefinition getConnectionFactoryBeanDefinition(String appId, String appSecret, Map<String, String> allAttributes) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FacebookConnectionFactory.class).addConstructorArgValue(appId).addConstructorArgValue(appSecret);
- Node appNamespaceAttribute = allAttributes.getNamedItem("app-namespace");
- if (appNamespaceAttribute != null) {
- builder.addConstructorArgValue(appNamespaceAttribute.getNodeValue());
+ if (allAttributes.containsKey("app-namespace")) {
+ builder.addConstructorArgValue(allAttributes.get("app-namespace"));
}
return builder.getBeanDefinition();
}
@@ -511,7 +511,7 @@ public void deleteFeedEntry_unauthorized() {
@Test
public void searchPublicFeed() {
- mockServer.expect(requestTo("https://graph.facebook.com/search?q=Dr+Seuss&type=post&offset=0&limit=25"))
+ mockServer.expect(requestTo("https://graph.facebook.com/search?q=Dr%20Seuss&type=post&offset=0&limit=25"))
.andExpect(method(GET))
.andExpect(header("Authorization", "OAuth someAccessToken"))
.andRespond(withSuccess(jsonResource("testdata/post-list"), MediaType.APPLICATION_JSON));
@@ -521,7 +521,7 @@ public void searchPublicFeed() {
@Test
public void searchPublicFeed_withOffsetAndLimit() {
- mockServer.expect(requestTo("https://graph.facebook.com/search?q=Dr+Seuss&type=post&offset=40&limit=10"))
+ mockServer.expect(requestTo("https://graph.facebook.com/search?q=Dr%20Seuss&type=post&offset=40&limit=10"))
.andExpect(method(GET))
.andExpect(header("Authorization", "OAuth someAccessToken"))
.andRespond(withSuccess(jsonResource("testdata/post-list"), MediaType.APPLICATION_JSON));
View
@@ -1,13 +1,47 @@
-Spring Social Facebook 1.1.0.M1 (TBD)
-=====================================
+Spring Social Facebook 1.1.0.M1 (October 15, 2012)
+==================================================
Bug Fixes
* Handle HTTP 404 from Graph API by throwing ResourceNotFoundException
(SOCIALFB-42)
* Handle error where Facebook says that status is duplicate or similar
to a recent post to Twitter by throwing DuplicateStatusException
(SOCIALFB-57)
+ * Fixed handling of errors to throw an InsufficientPermissionException
+ when an OperationNotPermittedException was being thrown. (SOCIALFB-80)
+ * Fixed problem with Facebook image sizes after Facebook started sending
+ additional image sizes in the Graph API. (SOCIALFB-76)
+ * Fixed NullPointerException thrown in FqlResult.getList() when field value
+ is null. (SOCIALFB-75)
+ * Fixed duplicate invocation of FacebookTemplate.initialize() in constructor.
+ (SOCIALFB-97)
Improvements
+ * Added XML configuration support for Facebook connection factory and API
+ binding beans. (SOCIAL-292)
+ * Added a sharesCount attribute to Post. (SOCIALFB-56)
+ * Added a commentCount property to Post. (SOCIALFB-51)
+ * Added coverPhotoId property to Album class that can be used to retrieve
+ a Photo object. (SOCIALFB-68)
+ * Added support for getting the signed_request as a Spring MVC controller
+ argument. (SOCIALFB-23)
+ * Support for OpenGraph operations in API Binding (SOCIALFB-64)
+ * Added questions operations in API binding (SOCIALFB-37)
+ * New DisconnectController to handle deauthorization callback from Facebook
+ (SOCIALFB-69)
+ * Facebook Query Language (FQL) support in API binding. (SOCIALFB-8)
+ * Added getSubscribers() and getSubscribedTo() methods to FriendOperations
+ to read a user's subscribers/subscriptions. (SOCIALFB-58)
+ * Added getFamily() to FriendOperations to allow for fetching a list of a user's
+ family members. (SOCIALFB-61)
+ * Added getMutualFriends() method to FriendOperations to allow for fetching
+ of a list of friends that the authenticated user has in common with another
+ user. (SOCIALFB-62)
+ * Added getGames() to LikeOperations to retrieve a list of games that the
+ user has connections to. (SOCIALFB-35)
+ * Fetch list of users who have liked a post instead of just a count. (SOCIALFB-41)
+ * Added ability to configure the application namespace on the Facebook connection
+ factory. This makes it possible to use OpenGraph operations when working with
+ a FacebookTemplate provided via the connection factory. (SOCIALFB-96)
Spring Social Facebook 1.0.2 (September 3, 2012)
================================================

0 comments on commit 521bc1d

Please sign in to comment.