Skip to content
Closed
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
7 changes: 0 additions & 7 deletions .iex.exs

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: elixir
elixir:
- 1.4
- 1.6
otp_release:
- 17.5
- 18.2
Expand Down
7 changes: 5 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions lib/kane/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/kane/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/kane/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/kane/topic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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},
Expand Down
5 changes: 3 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
"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"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"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"},
Expand Down
6 changes: 3 additions & 3 deletions test/kane/message_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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"]

Expand All @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions test/kane/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Expand Down
6 changes: 3 additions & 3 deletions test/kane/topic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}"

Expand All @@ -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": [
Expand Down
10 changes: 6 additions & 4 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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