Skip to content

Commit

Permalink
Fix publishing a new status (Fixes: #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
milmazz committed Mar 20, 2019
1 parent a27c030 commit 33d6c68
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/hunter/api/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ defmodule Hunter.Api.HTTPClient do
end

def create_status(conn, status, options) do
body = Keyword.put(options, :status, status)
body = options |> Keyword.put(:status, status) |> Map.new()

"/api/v1/statuses"
|> process_url(conn)
Expand Down Expand Up @@ -352,7 +352,7 @@ defmodule Hunter.Api.HTTPClient do
defp get_headers(nil), do: []

defp get_headers(%Hunter.Client{bearer_token: token}) do
[{"Authorization", "Bearer #{token}"}]
[{:Authorization, "Bearer #{token}"}]
end

defp get_headers(headers) when is_list(headers), do: headers
Expand Down
2 changes: 1 addition & 1 deletion lib/hunter/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule Hunter.Application do
website \\ nil,
options \\ []
) do
save? = Keyword.get(options, :save?, false)
{save?, options} = Keyword.pop(options, :save?, false)
base_url = Keyword.get(options, :api_base_url, Config.api_base_url())

app = Config.hunter_api().create_app(client_name, redirect_uris, scopes, website, base_url)
Expand Down
2 changes: 1 addition & 1 deletion lib/hunter/status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule Hunter.Status do
"""
@spec create_status(Hunter.Client.t(), String.t(), Keyword.t()) :: Hunter.Status.t() | no_return
def create_status(conn, status, options \\ []) do
Config.hunter_api().create_status(conn, status, Map.new(options))
Config.hunter_api().create_status(conn, status, options)
end

@doc """
Expand Down
8 changes: 8 additions & 0 deletions test/hunter/status_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ defmodule Hunter.StatusTest do

assert [timeline | []] = Status.public_timeline(@conn, limit: 1, local: true)
end

test "should allow to create new status" do
expect(Hunter.ApiMock, :create_status, fn _conn, status, _opts ->
%Hunter.Status{content: status}
end)

assert %Hunter.Status{content: "hello"} = Status.create_status(@conn, "hello")
end
end

0 comments on commit 33d6c68

Please sign in to comment.