Skip to content

Commit 063ecbb

Browse files
r-icarusJorge Chavez
authored andcommitted
Set locale via application configuration (altyaper#5)
* Set locale via application configuration It is set as a header like the secret key * Use message because it changes language
1 parent be1de37 commit 063ecbb

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

config/config.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ use Mix.Config
22

33
config :conekta,
44
publickey: "PUBLIC",
5-
privatekey: "PRIVATE"
5+
privatekey: "PRIVATE",
6+
locale: "es"

lib/error_handler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Conekta.ErrorHandler do
99

1010
def catch_error(content) do
1111
{:ok, error} = Poison.decode(content.body, as: %ErrorResponse{})
12-
raise ConektaError, message: hd(error.details)["debug_message"]
12+
raise ConektaError, message: hd(error.details)["message"]
1313
end
1414

1515
def raise_error(content) when is_map(content) do

lib/wrapper.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ defmodule Conekta.Wrapper do
1313

1414
def headers do
1515
basic_auth = "Basic " <> Base.encode64(key() <> ":")
16-
["Accept": @conekta_accept_header, "Content-type": "application/json", "Authorization": basic_auth]
16+
["Accept": @conekta_accept_header, "Accept-Language": locale(),"Content-type": "application/json", "Authorization": basic_auth]
1717
end
1818

1919
def key do
2020
Application.get_env(:conekta, :privatekey)
2121
end
2222

23+
def locale do
24+
Application.get_env(:conekta, :locale)
25+
end
26+
2327
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Conekta.Mixfile do
77

88
def project do
99
[app: :conekta,
10-
version: "1.0.7",
10+
version: "1.0.8",
1111
description: @description,
1212
name: "Conekta",
1313
elixir: "~> 1.4",

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [:mix], [{:meck, "~> 0.8.2", [hex: :meck, optional: false]}]},
1414
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
1515
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
16-
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [], [], "hexpm"},
16+
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
1717
}

test/auth_request_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ defmodule ConektaTest.AuthRequest do
1010
test "should get the right headers" do
1111

1212
basic_auth = "Basic " <> Base.encode64("key_123456789012345" <> ":")
13-
headers = ["Accept": "application/vnd.conekta-v2.0.0+json", "Content-type": "application/json", "Authorization": basic_auth]
13+
headers = ["Accept": "application/vnd.conekta-v2.0.0+json",
14+
"Accept-Language": "es", "Content-type": "application/json", "Authorization": basic_auth]
1415
assert Conekta.Wrapper.headers() == headers
1516

1617
end

0 commit comments

Comments
 (0)