diff --git a/.iex.exs b/.iex.exs deleted file mode 100644 index 1da4bc0..0000000 --- a/.iex.exs +++ /dev/null @@ -1,7 +0,0 @@ -try do - import_file "~/.iex.exs" -rescue - _ -> :ok -end - -alias Kane.{Message, Subscription, Topic, Client} diff --git a/.travis.yml b/.travis.yml index d987347..caf77d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: elixir elixir: - - 1.4 + - 1.6 otp_release: - 17.5 - 18.2 diff --git a/config/test.exs b/config/test.exs index 90b4123..252cad3 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,6 +1,9 @@ use Mix.Config -config :goth, - json: "config/test-credentials.json" |> Path.expand |> File.read! +config :gotham, + default_account: :test, + accounts: [ + {:test, file_path: "config/test-credentials.json"} + ] config :kane, :token, Kane.TestToken diff --git a/lib/kane/client.ex b/lib/kane/client.ex index 67c05e8..bf289fc 100644 --- a/lib/kane/client.ex +++ b/lib/kane/client.ex @@ -31,13 +31,18 @@ defmodule Kane.Client do defp url(path), do: Path.join([endpoint(), path]) defp endpoint, do: Application.get_env(:kane, :endpoint, "https://pubsub.googleapis.com/v1") - defp token_mod, do: Application.get_env(:kane, :token, Goth.Token) + defp token_mod, do: Application.get_env(:kane, :token, Gotham) defp auth_header do {:ok, token} = token_mod().for_scope(Kane.oauth_scope()) - {"Authorization", "#{token.type} #{token.token}"} + auth_header(token) end + defp auth_header(%Gotham.Token{token_type: type, access_token: token}), + do: {"Authorization", "#{type} #{token}"} + + defp auth_header(token), do: {"Authorization", "#{token.type} #{token.token}"} + defp handle_response({:ok, response}), do: handle_status(response) defp handle_response(err), do: err diff --git a/lib/kane/message.ex b/lib/kane/message.ex index 47087d2..43106af 100644 --- a/lib/kane/message.ex +++ b/lib/kane/message.ex @@ -104,7 +104,7 @@ defmodule Kane.Message do defp path(%Topic{name: topic}), do: path(topic) defp path(topic) do - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() "projects/#{project}/topics/#{Topic.strip!(topic)}:publish" end end diff --git a/lib/kane/subscription.ex b/lib/kane/subscription.ex index 5c5b2c3..b8b5b9f 100644 --- a/lib/kane/subscription.ex +++ b/lib/kane/subscription.ex @@ -107,7 +107,7 @@ defmodule Kane.Subscription do end defp project do - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() project end @@ -127,7 +127,7 @@ defmodule Kane.Subscription do def full_name(%__MODULE__{name: name}), do: full_name(name) def full_name(name) do - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() "projects/#{project}/subscriptions/#{name}" end diff --git a/lib/kane/topic.ex b/lib/kane/topic.ex index fa25a01..eb08c56 100644 --- a/lib/kane/topic.ex +++ b/lib/kane/topic.ex @@ -95,7 +95,7 @@ defmodule Kane.Topic do defp with_name(name), do: %__MODULE__{name: strip!(name)} defp project do - {:ok, id} = Goth.Config.get(:project_id) + {:ok, %{project_id: id}} = Gotham.get_profile() id end diff --git a/mix.exs b/mix.exs index 9911619..d63aedc 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule Kane.Mixfile do [ app: :kane, version: "0.7.0", - elixir: "~> 1.4", + elixir: "~> 1.6", package: package(), description: description(), deps: deps() @@ -18,7 +18,7 @@ defmodule Kane.Mixfile do defp deps do [ - {:goth, "~> 1.0"}, + {:gotham, "~> 0.1.1"}, {:httpoison, "~> 1.0"}, {:jason, "~> 1.1"}, {:bypass, "~> 0.1", only: :test}, diff --git a/mix.lock b/mix.lock index 2a5e7ac..3a012c2 100644 --- a/mix.lock +++ b/mix.lock @@ -7,12 +7,12 @@ "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm"}, "ex_doc": {:hex, :ex_doc, "0.19.3", "3c7b0f02851f5fc13b040e8e925051452e41248f685e40250d7e40b07b9f8c10", [:mix], [{:earmark, "~> 1.2", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"}, - "goth": {:hex, :goth, "1.0.1", "191773b527db4ae6695d9bab62602bda6645a367a95e2acaca0d51f61fe20e4d", [:mix], [{:httpoison, "~> 0.11 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.0", [hex: :joken, repo: "hexpm", optional: false]}], "hexpm"}, + "gotham": {:hex, :gotham, "0.1.2", "439d5810a6cdd74ca9ef1563a63410e5f8a7ce4e158699347ca6c180b4bbdbd7", [:mix], [{:httpoison, "~> 1.5", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.1", [hex: :joken, repo: "hexpm", optional: false]}], "hexpm"}, "hackney": {:hex, :hackney, "1.15.0", "287a5d2304d516f63e56c469511c42b016423bcb167e61b611f6bad47e3ca60e", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, "httpoison": {:hex, :httpoison, "1.5.0", "71ae9f304bdf7f00e9cd1823f275c955bdfc68282bc5eb5c85c3a9ade865d68e", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, - "joken": {:hex, :joken, "2.0.0", "ff10fca10ec539d7a73874da303f4a7a975fea53fcd59b1b89dda2a71ecb4c6b", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm"}, + "joken": {:hex, :joken, "2.1.0", "bf21a73105d82649f617c5e59a7f8919aa47013d2519ebcc39d998d8d12adda9", [:mix], [{:jose, "~> 1.9", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm"}, "jose": {:hex, :jose, "1.9.0", "4167c5f6d06ffaebffd15cdb8da61a108445ef5e85ab8f5a7ad926fdf3ada154", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"}, "makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, "makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, @@ -20,6 +20,7 @@ "mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], [], "hexpm"}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, "mix_test_watch": {:hex, :mix_test_watch, "0.4.1", "a98a84c795623f1ba020324f4354cf30e7120ba4dab65f9c2ae300f830a25f75", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"}, + "mox": {:hex, :mox, "0.5.1", "f86bb36026aac1e6f924a4b6d024b05e9adbed5c63e8daa069bd66fb3292165b", [:mix], [], "hexpm"}, "nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, "plug": {:hex, :plug, "1.3.5", "7503bfcd7091df2a9761ef8cecea666d1f2cc454cbbaf0afa0b6e259203b7031", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"}, diff --git a/test/kane/message_test.exs b/test/kane/message_test.exs index 75cd52b..a5ab5b7 100644 --- a/test/kane/message_test.exs +++ b/test/kane/message_test.exs @@ -39,7 +39,7 @@ defmodule Kane.MessageTest do end test "publishing a message", %{bypass: bypass} do - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() topic = "publish" Bypass.expect(bypass, fn conn -> @@ -53,7 +53,7 @@ defmodule Kane.MessageTest do end test "publishing multiple messages", %{bypass: bypass} do - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() topic = "publish-multi" ids = ["hello", "hi", "howdy"] @@ -63,7 +63,7 @@ defmodule Kane.MessageTest do Plug.Conn.resp( conn, 201, - ~s({"messageIds": [ "#{Enum.at(ids, 0)}", "#{Enum.at(ids, 1)}", "#{Enum.at(ids, 2)}" ]}) + ~s({"messageIds": [ "#{Enum.at(ids, 0)}", "#{Enum.at(ids, 1)}", "#{Enum.at(ids, 2)}"]}) ) end) diff --git a/test/kane/subscription_test.exs b/test/kane/subscription_test.exs index 9538e75..7163fbc 100644 --- a/test/kane/subscription_test.exs +++ b/test/kane/subscription_test.exs @@ -7,7 +7,7 @@ defmodule Kane.SubscriptionTest do setup do bypass = Bypass.open() Application.put_env(:kane, :endpoint, "http://localhost:#{bypass.port}") - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() {:ok, bypass: bypass, project: project} end @@ -153,7 +153,8 @@ defmodule Kane.SubscriptionTest do end) assert {:ok, []} = - Subscription.pull(%Subscription{name: "capped", topic: "sure"}, + Subscription.pull( + %Subscription{name: "capped", topic: "sure"}, max_messages: 5, return_immediately: false ) diff --git a/test/kane/topic_test.exs b/test/kane/topic_test.exs index 19875ad..6a1996f 100644 --- a/test/kane/topic_test.exs +++ b/test/kane/topic_test.exs @@ -5,7 +5,7 @@ defmodule Kane.TopicTest do setup do bypass = Bypass.open() Application.put_env(:kane, :endpoint, "http://localhost:#{bypass.port}") - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() {:ok, bypass: bypass, project: project} end @@ -54,7 +54,7 @@ defmodule Kane.TopicTest do end test "finding a topic with a fully-qualified name", %{bypass: bypass} do - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() short_name = "fqn" full_name = "projects/#{project}/topics/#{short_name}" @@ -77,7 +77,7 @@ defmodule Kane.TopicTest do test "listing all topics", %{bypass: bypass} do Bypass.expect(bypass, fn conn -> - {:ok, project} = Goth.Config.get(:project_id) + {:ok, %{project_id: project}} = Gotham.get_profile() assert Regex.match?(~r/\/projects\/#{project}\/topics/, conn.request_path) Plug.Conn.resp(conn, 200, ~s({"topics": [ diff --git a/test/test_helper.exs b/test/test_helper.exs index 36c1bc4..5ade5b3 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -4,11 +4,13 @@ Application.ensure_all_started(:bypass) defmodule Kane.TestToken do def for_scope(scope) do {:ok, - %Goth.Token{ + %Gotham.Token{ + access_token: UUID.uuid1(), + account_name: :account1, + expire_at: :os.system_time(:seconds) + 3600, + project_id: "pxn-staging-env", scope: scope, - expires: :os.system_time(:seconds) + 3600, - type: "Bearer", - token: UUID.uuid1() + token_type: "Bearer" }} end end