Skip to content

Commit

Permalink
Adding search groups and get group feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Nephtys committed Sep 15, 2011
1 parent 2b73489 commit 6fcfc6e
Show file tree
Hide file tree
Showing 12 changed files with 888 additions and 2 deletions.
119 changes: 119 additions & 0 deletions src/main/java/org/springframework/social/viadeo/api/Group.java
@@ -0,0 +1,119 @@
/*
* Copyright 2011 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.viadeo.api;

import java.io.Serializable;
import java.util.Date;

/**
* Model class representing a group.
*/
public class Group implements Serializable {

private static final long serialVersionUID = -3375820553217281636L;

private final String id;

private final String name;

private final String link;

private final Date updatedDate;

private String access;

private Integer memberCount;

private String description;

private String keywords;

private String country;

private Boolean isAdmin;

public Group(String id, String name, String link, Date updatedDate) {
this.id = id;
this.name = name;
this.link = link;
this.updatedDate = updatedDate;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public String getLink() {
return link;
}

public Date getUpdatedDate() {
return updatedDate;
}

public String getAccess() {
return access;
}

public void setAccess(String access) {
this.access = access;
}

public Integer getMemberCount() {
return memberCount;
}

public void setMemberCount(Integer memberCount) {
this.memberCount = memberCount;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getKeywords() {
return keywords;
}

public void setKeywords(String keywords) {
this.keywords = keywords;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public Boolean getIsAdmin() {
return isAdmin;
}

public void setIsAdmin(Boolean isAdmin) {
this.isAdmin = isAdmin;
}

}
@@ -0,0 +1,37 @@
/*
* Copyright 2011 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.viadeo.api;

import java.util.List;

public interface GroupOperations {

/**
* Search a group on viadeo.
*
* @param query a group on a keyword.
* @return a list of groups
*/
List<Group> search(String query);

/**
* Retrieve the detail for a group.
*
* @param objectId the id of the group
* @return the detailled group
*/
Group getGroup(String objectId);
}
Expand Up @@ -16,10 +16,11 @@
package org.springframework.social.viadeo.api;

import org.springframework.social.ApiBinding;
import org.springframework.social.viadeo.api.impl.ViadeoTemplate;

/**
* Interface specifying a basic set of operations for interacting with Viadeo.
* Implemented by {@link FacebookTemplate}.
* Interface specifying a basic set of operations for interacting with Viadeo.
* Implemented by {@link ViadeoTemplate}.
*
* @author Vincent Devillers
*/
Expand All @@ -28,4 +29,7 @@ public interface Viadeo extends ApiBinding {
UserOperations userOperations();

JobOperations jobOperations();

GroupOperations groupOperations();

}
@@ -0,0 +1,44 @@
/*
* Copyright 2011 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.viadeo.api.impl;

import java.net.URI;
import java.util.List;

import org.springframework.social.viadeo.api.Group;
import org.springframework.social.viadeo.api.GroupOperations;

public class GroupTemplate extends AbstractViadeoOperations implements
GroupOperations {

public GroupTemplate(ViadeoTemplate viadeoTemplate, boolean isAuthorized) {
super(viadeoTemplate, isAuthorized);
}

@Override
public List<Group> search(String query) {
requireAuthorization();
URI uri = buildUri("search/groups").queryParam("q", query).queryParam(
"limit", "50").build();
return get(uri, GroupsResult.class).getGroups();
}

@Override
public Group getGroup(String objectId) {
requireAuthorization();
return get(objectId, Group.class);
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2011 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.viadeo.api.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.social.viadeo.api.Group;

public class GroupsResult implements Serializable {

private static final long serialVersionUID = 680503605687489167L;

private final List<Group> groups;

public List<Group> getGroups() {
return groups;
}

public GroupsResult(List<Group> groups) {
this.groups = groups;
}

}
Expand Up @@ -26,6 +26,7 @@
import org.springframework.social.oauth2.AbstractOAuth2ApiBinding;
import org.springframework.social.support.ClientHttpRequestFactorySelector;
import org.springframework.social.support.URIBuilder;
import org.springframework.social.viadeo.api.GroupOperations;
import org.springframework.social.viadeo.api.JobOperations;
import org.springframework.social.viadeo.api.UserOperations;
import org.springframework.social.viadeo.api.Viadeo;
Expand All @@ -51,6 +52,8 @@ public class ViadeoTemplate extends AbstractOAuth2ApiBinding implements Viadeo {

private JobOperations jobOperations;

private GroupOperations groupOperations;

private final String accessToken;

/**
Expand Down Expand Up @@ -96,6 +99,7 @@ private void initSubApis() {
// sub-apis
userOperations = new UserTemplate(this, isAuthorized());
jobOperations = new JobTemplate(this, isAuthorized());
groupOperations = new GroupTemplate(this, isAuthorized());
}

private void registerViadeoJsonModule() {
Expand Down Expand Up @@ -129,4 +133,8 @@ public JobOperations jobOperations() {
return jobOperations;
}

public GroupOperations groupOperations() {
return groupOperations;
}

}
@@ -0,0 +1,54 @@
/*
* Copyright 2011 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.viadeo.api.impl.json;

import java.util.Date;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;

/**
* Annotated mixin to add Jackson annotations to Group.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
abstract class GroupMixin {

@JsonCreator
GroupMixin(@JsonProperty("id") String id, @JsonProperty("name") String name,
@JsonProperty("link") String link,
@JsonProperty("updated_time") Date updatedDate) {
}

@JsonProperty("access")
String access;

@JsonProperty("member_count")
Integer memberCount;

@JsonProperty("Description")
String description;

@JsonProperty("keywords")
String keywords;

@JsonProperty("country")
String country;

@JsonProperty("is_administrator")
Boolean isAdmin;

}
@@ -0,0 +1,32 @@
/*
* Copyright 2011 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.viadeo.api.impl.json;

import java.util.List;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.social.viadeo.api.Group;


@JsonIgnoreProperties(ignoreUnknown = true)
abstract class GroupsResultMixin {

@JsonCreator
GroupsResultMixin(@JsonProperty("data") List<Group> groups) {
}
}

0 comments on commit 6fcfc6e

Please sign in to comment.