Skip to content
Merged
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
20 changes: 20 additions & 0 deletions lib/facebook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ defmodule Facebook do
|> ResponseFormatter.format_response
end

@doc """
A Picture for a Facebook User with custom dimensions

## Example
iex> Facebook.picture("<Some Id>", 480, 480, "<Access Token>")
{:ok, %{"data": "..."}}

See: https://developers.facebook.com/docs/graph-api/reference/user/picture/
"""
@spec picture(page_id, width :: integer, height :: integer, access_token) :: resp
def picture(page_id, width, height, access_token) do
params = [width: width, height: height, redirect: false]
|> add_app_secret(access_token)
|> add_access_token(access_token)

~s(/#{page_id}/picture)
|> GraphAPI.get([], params: params)
|> ResponseFormatter.format_response
end

@doc """
Likes of the currently logged in user specified by the `t:access_token/0`

Expand Down
23 changes: 23 additions & 0 deletions test/facebook_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,36 @@ defmodule FacebookTest do
end
end

test "success with custom dimensions", %{id: id, access_token: access_token} do
with_mock :hackney, GraphMock.mock_options(
fn(_) -> GraphMock.picture(:success) end
) do
{:ok, %{"data" => picture_data}} = Facebook.picture(
id,
320,
320,
access_token
)

assert(String.length(picture_data["url"]) > 0)
end
end

test "error", %{id: id, invalid_access_token: invalid_access_token} do
with_mock :hackney, GraphMock.mock_options(
fn(_) -> GraphMock.error() end
) do
assert {:error, _} = Facebook.picture(id, "small", invalid_access_token)
end
end

test "error with custom dimensions", %{id: id, invalid_access_token: invalid_access_token} do
with_mock :hackney, GraphMock.mock_options(
fn(_) -> GraphMock.error() end
) do
assert {:error, _} = Facebook.picture(id, 320, 320, invalid_access_token)
end
end
end

describe "publish" do
Expand Down