Fix houncibot offenses.
This commit is contained in:
@@ -24,22 +24,22 @@ module RemoteTranslations::Microsoft::AvailableLocales
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def remote_available_locales
|
def remote_available_locales
|
||||||
host = "https://api.cognitive.microsofttranslator.com"
|
host = "https://api.cognitive.microsofttranslator.com"
|
||||||
path = "/languages?api-version=3.0"
|
path = "/languages?api-version=3.0"
|
||||||
|
|
||||||
uri = URI (host + path)
|
uri = URI (host + path)
|
||||||
|
|
||||||
request = Net::HTTP::Get.new(uri)
|
request = Net::HTTP::Get.new(uri)
|
||||||
request["Ocp-Apim-Subscription-Key"] = Rails.application.secrets.microsoft_api_key
|
request["Ocp-Apim-Subscription-Key"] = Rails.application.secrets.microsoft_api_key
|
||||||
|
|
||||||
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == "https") do |http|
|
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == "https") do |http|
|
||||||
http.request (request)
|
http.request (request)
|
||||||
|
end
|
||||||
|
|
||||||
|
result = response.body.force_encoding("utf-8")
|
||||||
|
|
||||||
|
JSON.parse(result)["translation"]
|
||||||
end
|
end
|
||||||
|
|
||||||
result = response.body.force_encoding("utf-8")
|
|
||||||
|
|
||||||
JSON.parse(result)["translation"]
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
module RemoteTranslations::Microsoft::SentencesParser
|
module RemoteTranslations::Microsoft::SentencesParser
|
||||||
|
|
||||||
def detect_split_position(text)
|
def detect_split_position(text)
|
||||||
minimum_valid_index = text.size - RemoteTranslations::Microsoft::Client::CHARACTERS_LIMIT_PER_REQUEST
|
limit = RemoteTranslations::Microsoft::Client::CHARACTERS_LIMIT_PER_REQUEST
|
||||||
|
minimum_valid_index = text.size - limit
|
||||||
valid_point = text[minimum_valid_index..text.size].index(".")
|
valid_point = text[minimum_valid_index..text.size].index(".")
|
||||||
valid_whitespace = text[minimum_valid_index..text.size].index(" ")
|
valid_whitespace = text[minimum_valid_index..text.size].index(" ")
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
describe "#call" do
|
describe "#call" do
|
||||||
|
|
||||||
|
let(:client) { RemoteTranslations::Microsoft::Client }
|
||||||
|
|
||||||
context "Debates" do
|
context "Debates" do
|
||||||
|
|
||||||
let(:debate) { create(:debate) }
|
let(:debate) { create(:debate) }
|
||||||
@@ -21,7 +23,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "returns the resource with new translation persisted" do
|
it "returns the resource with new translation persisted" do
|
||||||
response = ["Título traducido", "Descripción traducida"]
|
response = ["Título traducido", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale skip length validations" do
|
it "when new translation locale is distinct to default_locale skip length validations" do
|
||||||
response = ["TT", "Descripción traducida"]
|
response = ["TT", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale not skip presence validations" do
|
it "when new translation locale is distinct to default_locale not skip presence validations" do
|
||||||
response = ["", "Descripción traducida"]
|
response = ["", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "destroy remote translation instance" do
|
it "destroy remote translation instance" do
|
||||||
response = ["Título traducido", "Descripción traducida"]
|
response = ["Título traducido", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ describe RemoteTranslations::Caller do
|
|||||||
it "returns the resource with new translation persisted" do
|
it "returns the resource with new translation persisted" do
|
||||||
response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
|
response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
|
||||||
"Resumen traducido", nil]
|
"Resumen traducido", nil]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale skip lenght validations" do
|
it "when new translation locale is distinct to default_locale skip lenght validations" do
|
||||||
response = ["TT", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
|
response = ["TT", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -90,7 +92,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale do not skip presence validations" do
|
it "when new translation locale is distinct to default_locale do not skip presence validations" do
|
||||||
response = ["", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
|
response = ["", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ describe RemoteTranslations::Caller do
|
|||||||
it "destroy remote translation instance" do
|
it "destroy remote translation instance" do
|
||||||
response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
|
response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
|
||||||
"Resumen traducido", nil]
|
"Resumen traducido", nil]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -120,7 +122,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "returns the resource with new translation persisted" do
|
it "returns the resource with new translation persisted" do
|
||||||
response = ["Título traducido", "Descripción traducida"]
|
response = ["Título traducido", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -129,7 +131,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale skip lenght validations" do
|
it "when new translation locale is distinct to default_locale skip lenght validations" do
|
||||||
response = ["TT", "Descripción traducida"]
|
response = ["TT", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -140,7 +142,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale not skip presence validations" do
|
it "when new translation locale is distinct to default_locale not skip presence validations" do
|
||||||
response = ["", "Descripción traducida"]
|
response = ["", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -151,7 +153,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "destroy remote translation instance" do
|
it "destroy remote translation instance" do
|
||||||
response = ["Título traducido", "Descripción traducida"]
|
response = ["Título traducido", "Descripción traducida"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -168,7 +170,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "returns the resource with new translation persisted" do
|
it "returns the resource with new translation persisted" do
|
||||||
response = ["Body traducido"]
|
response = ["Body traducido"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -177,7 +179,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale skip lenght validations" do
|
it "when new translation locale is distinct to default_locale skip lenght validations" do
|
||||||
response = ["BT"]
|
response = ["BT"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -188,7 +190,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "when new translation locale is distinct to default_locale not skip presence validations" do
|
it "when new translation locale is distinct to default_locale not skip presence validations" do
|
||||||
response = [""]
|
response = [""]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
@@ -199,7 +201,7 @@ describe RemoteTranslations::Caller do
|
|||||||
|
|
||||||
it "destroy remote translation instance" do
|
it "destroy remote translation instance" do
|
||||||
response = ["Body traducido"]
|
response = ["Body traducido"]
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
|
expect_any_instance_of(client).to receive(:call).and_return(response)
|
||||||
|
|
||||||
caller.call
|
caller.call
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user