diff --git a/lib/facebook.ex b/lib/facebook.ex index 67cea6a..165a2d5 100644 --- a/lib/facebook.ex +++ b/lib/facebook.ex @@ -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("", 480, 480, "") + {: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` diff --git a/test/facebook_test.exs b/test/facebook_test.exs index e28ad9e..e0c74be 100644 --- a/test/facebook_test.exs +++ b/test/facebook_test.exs @@ -94,6 +94,21 @@ 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 @@ -101,6 +116,14 @@ defmodule FacebookTest 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