diff --git a/config/config.exs b/config/config.exs index 74c34e46d..e0f7b132e 100644 --- a/config/config.exs +++ b/config/config.exs @@ -12,7 +12,7 @@ config :plug, :types, %{ } # Use Jason for JSON parsing in Phoenix -config :phoenix, :json_library, Poison +config :phoenix, :json_library, Jason # General application configuration config :ask, diff --git a/lib/ask/ecto_types/day_of_week.ex b/lib/ask/ecto_types/day_of_week.ex index 4151d6273..79c4aa171 100644 --- a/lib/ask/ecto_types/day_of_week.ex +++ b/lib/ask/ecto_types/day_of_week.ex @@ -1,6 +1,7 @@ defmodule Ask.DayOfWeek do alias __MODULE__ + @derive Jason.Encoder defstruct [:sun, :mon, :tue, :wed, :thu, :fri, :sat] def cast(%DayOfWeek{} = day_of_week) do diff --git a/lib/ask/ecto_types/json.ex b/lib/ask/ecto_types/json.ex index c17328ebe..b052dfe51 100644 --- a/lib/ask/ecto_types/json.ex +++ b/lib/ask/ecto_types/json.ex @@ -2,6 +2,6 @@ defmodule Ask.Ecto.Type.JSON do use Ecto.Type def type, do: :longtext def cast(any), do: {:ok, any} - def load(string) when is_binary(string), do: Poison.decode(string) - def dump(json), do: Poison.encode(json) + def load(string) when is_binary(string), do: Jason.decode(string) + def dump(json), do: Jason.encode(json) end diff --git a/lib/ask/ecto_types/schedule.ex b/lib/ask/ecto_types/schedule.ex index 2c70e9c3a..5d50ca27e 100644 --- a/lib/ask/ecto_types/schedule.ex +++ b/lib/ask/ecto_types/schedule.ex @@ -11,6 +11,7 @@ defmodule Ask.Schedule do alias __MODULE__ alias Ask.{DayOfWeek, ScheduleError, SystemTime} + @derive Jason.Encoder defstruct [ :day_of_week, :start_time, @@ -96,7 +97,7 @@ defmodule Ask.Schedule do defp cast_blocked_days(_), do: [] - def load(string) when is_binary(string), do: cast(Poison.decode!(string)) + def load(string) when is_binary(string), do: cast(Jason.decode!(string)) def load(nil), do: {:ok, always()} def load(_), do: :error @@ -110,7 +111,7 @@ defmodule Ask.Schedule do def dump(%Schedule{day_of_week: day_of_week} = schedule) do {:ok, day_of_week} = DayOfWeek.dump(day_of_week) schedule = %{schedule | day_of_week: day_of_week, blocked_days: schedule.blocked_days || []} - Poison.encode(schedule) + Jason.encode(schedule) end def dump(_), do: :error diff --git a/lib/ask/ecto_types/stats.ex b/lib/ask/ecto_types/stats.ex index 5c33818b4..ca53a1da0 100644 --- a/lib/ask/ecto_types/stats.ex +++ b/lib/ask/ecto_types/stats.ex @@ -2,6 +2,7 @@ defmodule Ask.Stats do use Ecto.Type alias __MODULE__ + @derive Jason.Encoder defstruct total_received_sms: 0, total_sent_sms: 0, total_call_time: nil, @@ -52,10 +53,10 @@ defmodule Ask.Stats do def cast(nil), do: {:ok, %Stats{}} def cast(_), do: :error - def load(string) when is_binary(string), do: cast(Poison.decode!(string)) + def load(string) when is_binary(string), do: cast(Jason.decode!(string)) def load(_), do: :error - def dump(%Stats{} = stats), do: Poison.encode(stats) + def dump(%Stats{} = stats), do: Jason.encode(stats) def dump(_), do: :error def total_received_sms(%Stats{total_received_sms: count}), do: count diff --git a/lib/ask/ecto_types/steps.ex b/lib/ask/ecto_types/steps.ex index 2daeaba1e..80b8d30a6 100644 --- a/lib/ask/ecto_types/steps.ex +++ b/lib/ask/ecto_types/steps.ex @@ -16,14 +16,14 @@ defmodule Ask.Ecto.Type.Steps do end def load(string) when is_binary(string) do - case Poison.decode(string) do + case Jason.decode(string) do {:ok, steps} -> {:ok, transform(steps)} any -> any end end def dump(json) do - Poison.encode(json) + Jason.encode(json) end defp transform(steps) when is_nil(steps), do: nil diff --git a/lib/ask/floip_pusher.ex b/lib/ask/floip_pusher.ex index 51eb53ff8..4f78d71ba 100644 --- a/lib/ask/floip_pusher.ex +++ b/lib/ask/floip_pusher.ex @@ -128,7 +128,7 @@ defmodule Ask.FloipPusher do end def create_package(survey, endpoint, responses_uri) do - {:ok, body} = FloipPackage.descriptor(survey, responses_uri) |> Poison.encode() + {:ok, body} = FloipPackage.descriptor(survey, responses_uri) |> Jason.encode() endpoint_uri = String.to_charlist("#{endpoint.uri}/flow-results/packages") @@ -150,7 +150,7 @@ defmodule Ask.FloipPusher do end defp push_responses(endpoint, responses) do - {:ok, body} = Poison.encode(responses) + {:ok, body} = Jason.encode(responses) endpoint_uri = String.to_charlist( diff --git a/lib/ask/json_schema.ex b/lib/ask/json_schema.ex index 0bf340842..efb509aaa 100644 --- a/lib/ask/json_schema.ex +++ b/lib/ask/json_schema.ex @@ -67,7 +67,7 @@ defmodule Ask.JsonSchema do defp load_schema(schema_path) do File.read!(schema_path) - |> Poison.decode!() + |> Jason.decode!() |> ExJsonSchema.Schema.resolve() end diff --git a/lib/ask/metrics/respondent_stats_metrics.ex b/lib/ask/metrics/respondent_stats_metrics.ex index 60fb674ce..2abe62976 100644 --- a/lib/ask/metrics/respondent_stats_metrics.ex +++ b/lib/ask/metrics/respondent_stats_metrics.ex @@ -67,7 +67,7 @@ defmodule Ask.RespondentStatsMetrics do end defp parse_mode(key, value) when key == :mode and value != "" do - {key, Poison.decode!(value) |> Enum.join(",")} + {key, Jason.decode!(value) |> Enum.join(",")} end defp parse_mode(key, value), do: {key, value} diff --git a/lib/ask/number_translator.ex b/lib/ask/number_translator.ex index e4b79d48a..3096b54f9 100644 --- a/lib/ask/number_translator.ex +++ b/lib/ask/number_translator.ex @@ -4,7 +4,7 @@ defmodule Ask.NumberTranslator.Macros do |> Enum.map(fn filename -> filename = filename |> Path.basename(".json") - data = Poison.decode!(File.read!("#{__DIR__}/numbers/#{filename}.json")) + data = Jason.decode!(File.read!("#{__DIR__}/numbers/#{filename}.json")) data = {:%{}, [], data |> Enum.to_list()} quote do diff --git a/lib/ask/o_auth_token.ex b/lib/ask/o_auth_token.ex index a4fa37d2b..3418758d7 100644 --- a/lib/ask/o_auth_token.ex +++ b/lib/ask/o_auth_token.ex @@ -35,6 +35,6 @@ defmodule Ask.OAuthToken do end def access_token(token) do - Poison.Decode.decode(token.access_token, as: %OAuth2.AccessToken{}) + OAuth2.AccessToken.new(token.access_token["access_token"]) end end diff --git a/lib/ask/runtime/questionnaire_action.ex b/lib/ask/runtime/questionnaire_action.ex index 49584d887..986e4ae29 100644 --- a/lib/ask/runtime/questionnaire_action.ex +++ b/lib/ask/runtime/questionnaire_action.ex @@ -87,7 +87,7 @@ defmodule Ask.Runtime.QuestionnaireExport do manifest: manifest, audio_entries: audio_entries }) do - {:ok, json} = Poison.encode(manifest) + {:ok, json} = Jason.encode(manifest) json_entry = Stream.map([json], fn json -> diff --git a/lib/ask/runtime/reply.ex b/lib/ask/runtime/reply.ex index 2415e9e72..d0a5c1257 100644 --- a/lib/ask/runtime/reply.ex +++ b/lib/ask/runtime/reply.ex @@ -54,6 +54,7 @@ defmodule Ask.Runtime.Reply do end defmodule Ask.Runtime.ReplyStep do + @derive Jason.Encoder defstruct prompts: [], id: nil, title: nil, diff --git a/lib/ask/runtime/respondent_group_action.ex b/lib/ask/runtime/respondent_group_action.ex index ecf5bb247..d7a3f1099 100644 --- a/lib/ask/runtime/respondent_group_action.ex +++ b/lib/ask/runtime/respondent_group_action.ex @@ -142,11 +142,13 @@ defmodule Ask.Runtime.RespondentGroupAction do zip = canonical_numbers |> Enum.zip(phone_numbers) - |> List.foldl(%{}, fn ({k, v}, zip) -> Map.put(zip, k, v) end) + |> List.foldl(%{}, fn {k, v}, zip -> Map.put(zip, k, v) end) existing_numbers - |> List.foldl(zip, fn (n, zip) -> Map.delete(zip, n) end) # remove duplicates (using canonical number) - |> Map.values() # return the de-duplicated list of phone numbers + # remove duplicates (using canonical number) + |> List.foldl(zip, fn n, zip -> Map.delete(zip, n) end) + # return the de-duplicated list of phone numbers + |> Map.values() end end diff --git a/lib/ask/url_shortener.ex b/lib/ask/url_shortener.ex index 8b6a41c82..6af438219 100644 --- a/lib/ask/url_shortener.ex +++ b/lib/ask/url_shortener.ex @@ -41,7 +41,7 @@ defmodule Ask.UrlShortener do end def build_short_url(host, response_body) do - "#{host}/#{Poison.decode!(response_body)["key"]}" + "#{host}/#{Jason.decode!(response_body)["key"]}" end defp get_api_key, do: ConfigHelper.get_config(__MODULE__, :url_shortener_api_key) diff --git a/lib/ask_web/controllers/folder_controller.ex b/lib/ask_web/controllers/folder_controller.ex index 4cdee384b..3d981e8c2 100644 --- a/lib/ask_web/controllers/folder_controller.ex +++ b/lib/ask_web/controllers/folder_controller.ex @@ -51,7 +51,7 @@ defmodule AskWeb.FolderController do from(s in Survey, left_join: ps in PanelSurvey, on: s.panel_survey_id == ps.id, - where: (ps.folder_id == ^folder_id or s.folder_id == ^folder_id), + where: ps.folder_id == ^folder_id or s.folder_id == ^folder_id, where: s.state == ^:running, select: count(s.id) ) diff --git a/lib/ask_web/controllers/questionnaire_controller.ex b/lib/ask_web/controllers/questionnaire_controller.ex index 29c7f5426..23c2713e8 100644 --- a/lib/ask_web/controllers/questionnaire_controller.ex +++ b/lib/ask_web/controllers/questionnaire_controller.ex @@ -345,7 +345,7 @@ defmodule AskWeb.QuestionnaireController do |> Enum.into(%{}) json = files |> Map.get("manifest.json") - {:ok, manifest} = Poison.decode(json) + {:ok, manifest} = Jason.decode(json) audio_files = manifest |> Map.get("audio_files") diff --git a/lib/ask_web/controllers/respondent_controller.ex b/lib/ask_web/controllers/respondent_controller.ex index 5bd24bc90..549339f46 100644 --- a/lib/ask_web/controllers/respondent_controller.ex +++ b/lib/ask_web/controllers/respondent_controller.ex @@ -611,7 +611,7 @@ defmodule AskWeb.RespondentController do |> Enum.map(fn {state, disposition, questionnaire_id, mode, count} -> reference_id = if mode && questionnaire_id do - "#{questionnaire_id}#{mode |> Poison.decode!() |> Enum.join("")}" + "#{questionnaire_id}#{mode |> Jason.decode!() |> Enum.join("")}" else nil end @@ -652,7 +652,7 @@ defmodule AskWeb.RespondentController do {r.questionnaire_id, r.mode, r.date, fragment("CAST(? AS UNSIGNED)", sum(r.count))} ) |> Enum.map(fn {questionnaire_id, mode, completed_at, count} -> - {"#{questionnaire_id}#{mode |> Poison.decode!() |> Enum.join("")}", completed_at, count} + {"#{questionnaire_id}#{mode |> Jason.decode!() |> Enum.join("")}", completed_at, count} end) end @@ -665,7 +665,7 @@ defmodule AskWeb.RespondentController do select: {r.mode, r.date, fragment("CAST(? AS UNSIGNED)", sum(r.count))} ) |> Enum.map(fn {mode, completed_at, count} -> - {mode |> Poison.decode!() |> Enum.join(""), completed_at, count} + {mode |> Jason.decode!() |> Enum.join(""), completed_at, count} end) end diff --git a/lib/ask_web/endpoint.ex b/lib/ask_web/endpoint.ex index 34a2aefd2..11d8e054d 100644 --- a/lib/ask_web/endpoint.ex +++ b/lib/ask_web/endpoint.ex @@ -20,7 +20,7 @@ defmodule AskWeb.Endpoint do plug Plug.Parsers, parsers: [:urlencoded, :multipart, :json], pass: ["*/*"], - json_decoder: Poison, + json_decoder: Jason, length: 1_073_741_824, read_timeout: 60_000 diff --git a/lib/ask_web/templates/mobile_survey/index.html.eex b/lib/ask_web/templates/mobile_survey/index.html.eex index d88e4c791..ff49a830d 100644 --- a/lib/ask_web/templates/mobile_survey/index.html.eex +++ b/lib/ask_web/templates/mobile_survey/index.html.eex @@ -1,5 +1,5 @@
- +