Skip to content

Commit

Permalink
Merge pull request #38 from baldmountain/master
Browse files Browse the repository at this point in the history
Update httpoison to 1.4.0
  • Loading branch information
mmrobins authored Oct 25, 2018
2 parents c052c74 + 57d9435 commit e25616e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions lib/forcex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ defmodule Forcex do
require Logger

@type client :: map
@type response :: map | {number, any} | String.t
@type forcex_response :: map | {number, any} | String.t
@type method :: :get | :put | :post | :patch | :delete

@api Application.get_env(:forcex, :api) || Forcex.Api.Http

@spec json_request(method, String.t, map | String.t, list, list) :: response
@spec json_request(method, String.t, map | String.t, list, list) :: forcex_response
def json_request(method, url, body, headers, options) do
@api.raw_request(method, url, format_body(body), headers, options)
end

@spec post(String.t, map | String.t, client) :: response
@spec post(String.t, map | String.t, client) :: forcex_response
def post(path, body \\ "", client) do
url = client.endpoint <> path
headers = [{"Content-Type", "application/json"}]
json_request(:post, url, body, headers ++ client.authorization_header, [])
end

@spec patch(String.t, String.t, client) :: response
@spec patch(String.t, String.t, client) :: forcex_response
def patch(path, body \\ "", client) do
url = client.endpoint <> path
headers = [{"Content-Type", "application/json"}]
json_request(:patch, url, body, headers ++ client.authorization_header, [])
end

@spec delete(String.t, client) :: response
@spec delete(String.t, client) :: forcex_response
def delete(path, client) do
url = client.endpoint <> path
@api.raw_request(:delete, url, "", client.authorization_header, [])
end

@spec get(String.t, map | String.t, list, client) :: response
@spec get(String.t, map | String.t, list, client) :: forcex_response
def get(path, body \\ "", headers \\ [], client) do
url = client.endpoint <> path
json_request(:get, url, body, headers ++ client.authorization_header, [])
end

@spec versions(client) :: response
@spec versions(client) :: forcex_response
def versions(%Forcex.Client{} = client) do
get("/services/data", client)
end

@spec services(client) :: response
@spec services(client) :: forcex_response
def services(%Forcex.Client{} = client) do
get("/services/data/v#{client.api_version}", client)
end
Expand All @@ -62,15 +62,15 @@ defmodule Forcex do
]

for {function, service} <- @basic_services do
@spec unquote(function)(client) :: response
@spec unquote(function)(client) :: forcex_response
def unquote(function)(%Forcex.Client{} = client) do
client
|> service_endpoint(unquote(service))
|> get(client)
end
end

@spec describe_sobject(String.t, client) :: response
@spec describe_sobject(String.t, client) :: forcex_response
def describe_sobject(sobject, %Forcex.Client{} = client) do
base = service_endpoint(client, :sobjects)

Expand All @@ -85,21 +85,21 @@ defmodule Forcex do
|> get(client)
end

@spec metadata_changes_since(String.t, String.t, client) :: response
@spec metadata_changes_since(String.t, String.t, client) :: forcex_response
def metadata_changes_since(sobject, since, client) do
base = service_endpoint(client, :sobjects)

"#{base}/#{sobject}/describe/"
|> get("", [{"If-Modified-Since", since}], client)
end

@spec composite_query(map, client) :: response
@spec composite_query(map, client) :: forcex_response
def composite_query(body, %Forcex.Client{} = client) do
service_endpoint(client, :composite)
|> post(body, client)
end

@spec query(String.t, client) :: response
@spec query(String.t, client) :: forcex_response
def query(query, %Forcex.Client{} = client) do
base = service_endpoint(client, :query)
params = %{"q" => query} |> URI.encode_query
Expand All @@ -108,7 +108,7 @@ defmodule Forcex do
|> get(client)
end

@spec query_all(String.t, client) :: response
@spec query_all(String.t, client) :: forcex_response
def query_all(query, %Forcex.Client{} = client) do
base = service_endpoint(client, :queryAll)
params = %{"q" => query} |> URI.encode_query
Expand Down
4 changes: 2 additions & 2 deletions lib/forcex/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Forcex.Api do
"""

@type method :: :get | :put | :post | :patch | :delete
@type response :: map | {number, any} | String.t
@type forcex_response :: map | {number, any} | String.t

@callback raw_request(method, String.t, map | String.t, list, list) :: response
@callback raw_request(method, String.t, map | String.t, list, list) :: forcex_response
end
4 changes: 2 additions & 2 deletions lib/forcex/api/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Forcex.Api.Http do
@accept_encoding [{"Accept-Encoding", "gzip,deflate"}]

@type method :: :get | :put | :post | :patch | :delete
@type response :: map | {number, any} | String.t
@type forcex_response :: map | {number, any} | String.t

def raw_request(method, url, body, headers, options) do
response = method |> request!(url, body, headers, extra_options() ++ options) |> process_response
Expand All @@ -25,7 +25,7 @@ defmodule Forcex.Api.Http do
Application.get_env(:forcex, :request_options, [])
end

@spec process_response(HTTPoison.Response.t) :: response
@spec process_response(HTTPoison.Response.t) :: forcex_response
defp process_response(%HTTPoison.Response{body: body, headers: %{"Content-Encoding" => "gzip"} = headers} = resp) do
%{resp | body: :zlib.gunzip(body), headers: Map.drop(headers, ["Content-Encoding"])}
|> process_response
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"gettext": {:hex, :gettext, "0.16.0", "4a7e90408cef5f1bf57c5a39e2db8c372a906031cc9b1466e963101cb927dafc", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.14.0", "66e29e78feba52176c3a4213d42b29bdc4baff93a18cfe480f73b04677139dee", [: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"},
"hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [: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"},
"html_entities": {:hex, :html_entities, "0.4.0", "f2fee876858cf6aaa9db608820a3209e45a087c5177332799592142b50e89a6b", [:mix], [], "hexpm"},
"httpoison": {:hex, :httpoison, "1.3.1", "7ac607311f5f706b44e8b3fab736d0737f2f62a31910ccd9afe7227b43edb7f0", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.4.0", "e0b3c2ad6fa573134e42194d13e925acfa8f89d138bc621ffb7b1989e6d22e73", [: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.1", "d3ccb840dfb06f2f90a6d335b536dd074db748b3e7f5b11ab61d239506585eb2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"},
Expand Down

0 comments on commit e25616e

Please sign in to comment.