Class: Telegem::Plugins::Translate
- Inherits:
-
Object
- Object
- Telegem::Plugins::Translate
- Defined in:
- lib/plugins/translate.rb
Instance Method Summary collapse
-
#initialize(word, from, to) ⇒ Translate
constructor
A new instance of Translate.
- #start_translating ⇒ Object
Constructor Details
#initialize(word, from, to) ⇒ Translate
Returns a new instance of Translate.
6 7 8 9 10 11 |
# File 'lib/plugins/translate.rb', line 6 def initialize(word, from, to) @word = word @from = from @to = to start_translating end |
Instance Method Details
#start_translating ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/plugins/translate.rb', line 13 def start_translating url = "https://zen-drx-api.onrender.com/api/translate" = { body: { word: @word, from: @from, to: @to }.to_json, headers: { 'Content-Type' => 'application/json' } } response = HTTParty.post(url, ) if response.success? translation = response.parsed_response["translation"] { error: "false", translation: translation } else { error: "an error occurred", code: "#{response.code}" } end end |