I have a gem in ruby that does translations using google API and I am "translating" it to Elixir.
For example, I get from API some like this: api-data
And in Ruby today I do this:
encoded = rawdata.force_encoding("UTF-8")
I would like to know if there is a way to "force_encode" (like Ruby does) but with Elixir?
UPDATE SOLUTION
I reached a solution based in your answers guys thanks a lot!
As Elixir handle it as binaries then that is the trick: I get the response body: body |> IO.iodata_to_binary ...
defmodule Request do
alias Extract
use HTTPotion.Base
def process_url(url) do
"https://translate.google.com/translate_a/" <> url
end
def process_response_body(body) do
body |> IO.iodata_to_binary |> Extract.extract
end
end
force_encoding. Any thought?