Skip to content
Open
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
4 changes: 3 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use Mix.Config

config :google_maps,
url: "http://localhost/google/",
api_key: "bsafdkey"
# Print only warnings and errors during test
config :logger, level: :warn
146 changes: 0 additions & 146 deletions lib/google_maps/http.ex

This file was deleted.

12 changes: 8 additions & 4 deletions lib/google_maps/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule GoogleMaps.Request do
@doc """
GET an endpoint with param keyword list
"""
@spec get(String.t, keyword()) :: GoogleMaps.Response.t
@spec get(String.t(), keyword()) :: GoogleMaps.Response.t()
def get(endpoint, params) do
{secure, params} = Keyword.pop(params, :secure)
{output, params} = Keyword.pop(params, :output, "json")
Expand All @@ -13,15 +13,19 @@ defmodule GoogleMaps.Request do
{options, params} = Keyword.pop(params, :options, [])

unless is_nil(secure) do
IO.puts "`secure` param is deprecated since Google requires request over SSL with API key."
IO.puts("`secure` param is deprecated since Google requires request over SSL with API key.")
end

query = params
query =
params
|> Keyword.put(:key, key)
|> Enum.map(&transform_param/1)
|> URI.encode_query()

url = Path.join("https://maps.googleapis.com/maps/api/#{endpoint}", output)
url =
(Application.get_env(:google_maps, :url, "https://maps.googleapis.com/maps/api/") <>
endpoint)
|> Path.join(output)

requester().get("#{url}?#{query}", headers, options)
|> format_headers()
Expand Down
25 changes: 17 additions & 8 deletions lib/google_maps/response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ defmodule GoogleMaps.Response do

@type t :: {:ok, map()} | {:error, error()} | {:error, error(), String.t()}

@type status :: String.t
@type status :: String.t()

@type error :: String.t
# @type error :: String.t
@type error :: HTTPoison.Error.t() | status()

def wrap({:error, error}), do: {:error, error}
def wrap({:ok, %{body: body, headers: %{"content-type" => "application/json" <> _}} = response})
when is_binary(body) do

def wrap({:ok, %{body: body, headers: %{"Content-Type" => "application/json" <> _}} = response})
when is_binary(body) do
wrap({:ok, %{response | body: Jason.decode!(body)}})
end

def wrap({:ok, %{body: %{"status" => "OK"} = body}}), do: {:ok, body}
def wrap({:ok, %{body: %{"status" => status, "error_message" => error_message}}}), do: {:error, status, error_message}

def wrap({:ok, %{body: %{"status" => status, "error_message" => error_message}}}),
do: {:error, status, error_message}

def wrap({:ok, %{body: %{"status" => status}}}), do: {:error, status}
def wrap({:ok, %{body: body, status_code: 200, headers: %{"content-type" => "image" <> _}}})
when is_binary(body), do: {:ok, body}
def wrap({:ok, %{status_code: status, headers: %{"content-type" => _}}}), do: {:error, status}

def wrap({:ok, %{body: body, status_code: 200, headers: %{"Content-Type" => "image" <> _}}})
when is_binary(body),
do: {:ok, body}

def wrap({:ok, %{status_code: status, headers: %{"Content-Type" => _}}}), do: {:error, status}
end
56 changes: 32 additions & 24 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
defmodule GoogleMaps.Mixfile do
use Mix.Project

@version File.read!("VERSION") |> String.trim
@version File.read!("VERSION") |> String.trim()

def project do
[app: :google_maps,
description: "A Google Maps API in Elixir",
version: @version,
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps(),
package: package(),
[
app: :google_maps,
description: "A Google Maps API in Elixir",
version: @version,
elixir: "~> 1.3",
elixirc_paths: elixirc_paths(Mix.env()),
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
package: package(),

# Docs
name: "GoogleMaps",
source_url: "https://github.com/sntran/ex_maps",
homepage_url: "https://hex.pm/packages/google_maps/",
docs: docs()
# Docs
name: "GoogleMaps",
source_url: "https://github.com/sntran/ex_maps",
homepage_url: "https://hex.pm/packages/google_maps/",
docs: docs()
]
end

Expand All @@ -26,11 +28,14 @@ defmodule GoogleMaps.Mixfile do
# Type "mix help compile.app" for more information
def application do
[
applications: [:logger],
env: [requester: GoogleMaps.HTTP]
applications: [:logger, :httpoison],
env: [requester: HTTPoison]
]
end

defp elixirc_paths(:test), do: ["lib", "test"]
defp elixirc_paths(_), do: ["lib"]

# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
Expand All @@ -42,23 +47,26 @@ defmodule GoogleMaps.Mixfile do
# Type "mix help deps" for more examples and options
defp deps do
[
{:castore, "~> 0.1.0"},
{:mint, "~> 0.2.0"},
{:httpoison, "~>1.5"},
{:jason, "~> 1.1"},
{:ex_doc, ">= 0.0.0", only: :dev}
{:ex_doc, ">= 0.0.0", only: :dev},
{:bypass, "~> 1.0", only: :test}
]
end

defp package do
[files: ~w(lib mix.exs README.md LICENSE.md VERSION),
maintainers: ["Son Tran-Nguyen"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/sntran/ex_maps"}]
[
files: ~w(lib mix.exs README.md LICENSE.md VERSION),
maintainers: ["Son Tran-Nguyen"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/sntran/ex_maps"}
]
end

defp docs do
[
main: "GoogleMaps", # The main page in the docs
# The main page in the docs
main: "GoogleMaps",
extras: ["README.md"]
]
end
Expand Down
19 changes: 17 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
%{
"castore": {:hex, :castore, "0.1.1", "a8905530209152ddb74989fa2a5bd4fa3a2d3ff5d15ad12578caa7460d807c8b", [:mix], [], "hexpm"},
"bypass": {:hex, :bypass, "1.0.0", "b78b3dcb832a71aca5259c1a704b2e14b55fd4e1327ff942598b4e7d1a7ad83d", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"cowboy": {:hex, :cowboy, "2.6.3", "99aa50e94e685557cad82e704457336a453d4abcb77839ad22dbe71f311fcc06", [:rebar3], [{:cowlib, "~> 2.7.3", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [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.1", [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.1", "0f55b5b673b03c5c327dac7015a67cb571b99b631acc0bc1b0b98dcd6b9f2104", [: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"},
"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"},
"mint": {:hex, :mint, "0.2.1", "a2ec8729fcad5c8b6460e07dfa64b008b3d9697a9f4604cd5684a87b44677c99", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "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.8.0", "9d2685cb007fe5e28ed9ac27af2815bc262b7817a00929ac10f56f169f43b977", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"},
"plug_cowboy": {:hex, :plug_cowboy, "2.0.2", "6055f16868cc4882b24b6e1d63d2bada94fb4978413377a3b32ac16c18dffba2", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
}
Loading