Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Adding getLocations to pages API #111

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ public interface PageOperations {
*/
PagedList<Account> getAccounts();

/**
* Retrieves a list of Account objects for the location pages given a parent page.
* Requires "manage_pages" permission.
* @param pageId the parent page Id
*/
PagedList<Account> getLocations(String pageId);

/**
* Retrieves a list of Account objects for the location pages that the authenticated user is an administrator given a parent page id.
* Requires "manage_pages" permission.
* @param pageId the parent page Id
* @param queryParameters parameters to be included in the request.
*/
PagedList<Account> getLocations(String pageId, MultiValueMap<String, String> queryParameters);

/**
* Posts a message to a page's feed as a page administrator.
* Requires that the application is granted "manage_pages" permission and that the authenticated user be an administrator of the page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public PagedList<Account> getAccounts() {
requireAuthorization();
return graphApi.fetchConnections("me", "accounts", Account.class);
}

public PagedList<Account> getLocations(String pageId)
{
requireAuthorization();
return graphApi.fetchConnections(pageId, "locations", Account.class);
}

public PagedList<Account> getLocations(String pageId, MultiValueMap<String, String> queryParameters)
{
requireAuthorization();
return graphApi.fetchConnections(pageId, "locations", Account.class, queryParameters);
}

public String post(String pageId, String message) {
requireAuthorization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ public void getAccounts() {
assertEquals("Page", accounts.get(1).getCategory());
assertEquals("page2AccessToken", accounts.get(1).getAccessToken());
}

@Test
public void getLocations(){
mockServer.expect(requestTo("https://graph.facebook.com/214112095464587/locations"))
.andExpect(method(GET))
.andExpect(header("Authorization", "OAuth someAccessToken"))
.andRespond(withSuccess(jsonResource("place-page-locations"), MediaType.APPLICATION_JSON));

PagedList<Account> locations = facebook.pageOperations().getLocations("214112095464587");
assertTrue(locations.size() == 5);
Account page = locations.get(0);
assertEquals("251118525076385", page.getId());
}

@Test
public void post_message() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"category": "Local business",
"category_list": [
{
"id": "176139629103647",
"name": "Dance Club"
}
],
"name": "Booooooooof Miramichi",
"id": "251118525076385"
},
{
"category": "Arts/entertainment/nightlife",
"category_list": [
{
"id": "176139629103647",
"name": "Dance Club"
}
],
"name": "Booooooooof Moncton",
"id": "578747338900172"
},
{
"category": "Arts/entertainment/nightlife",
"category_list": [
{
"id": "176139629103647",
"name": "Dance Club"
}
],
"name": "Booooooooof Halifax",
"id": "223991034461281"
},
{
"category": "Arts/entertainment/nightlife",
"category_list": [
{
"id": "176139629103647",
"name": "Dance Club"
}
],
"name": "Booooooooof Saint John",
"id": "432790206855954"
},
{
"category": "Arts/entertainment/nightlife",
"category_list": [
{
"id": "176139629103647",
"name": "Dance Club"
}
],
"name": "Booooooooof Fredericton",
"id": "1384040068504197"
}