Class: Yapitr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yapitr/client.rb

Constant Summary collapse

@@api_key =
"trnsl.1.1.20170529T154416Z.047bb57fd7a8b3a1.97c5cf0ccade87d10fb983346cfb5703bf811b3e"

Instance Method Summary collapse

Constructor Details

#initialize(some_phrase) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/yapitr/client.rb', line 10

def initialize(some_phrase)
	@text_for_trans = some_phrase	
end

Instance Method Details

#detect_langObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yapitr/client.rb', line 30

def detect_lang
	client = HTTPClient.new
	url = "https://translate.yandex.net/api/v1.5/tr.json/detect?
				text=#{@text_for_trans}
				&hint=en,de,fr
				&key=trnsl.1.1.20170529T154416Z.047bb57fd7a8b3a1.97c5cf0ccade87d10fb983346cfb5703bf811b3e"
	uri = URI.parse(url)
	method = 'GET'
	res = client.request method, uri
	puts res.body
end

#get_langs(lang) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/yapitr/client.rb', line 18

def get_langs(lang)
	@lang = lang
	client = HTTPClient.new
	url = "https://translate.yandex.net/api/v1.5/tr.json/getLangs?
				ui=#{@lang}
				&key=#{@@api_key}"
	uri = URI.parse(url)
	method = 'GET'
	res = client.request method, uri
	puts res.body
end

#puts_phraseObject



14
15
16
# File 'lib/yapitr/client.rb', line 14

def puts_phrase
	puts @text_for_trans
end

#translate(lang) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yapitr/client.rb', line 42

def translate(lang)
	@lang_for_trans = lang
	client = HTTPClient.new
	url = "https://translate.yandex.net/api/v1.5/tr.json/translate?
				text=#{@text_for_trans}
				&lang=#{@lang_for_trans}
				&key=trnsl.1.1.20170529T154416Z.047bb57fd7a8b3a1.97c5cf0ccade87d10fb983346cfb5703bf811b3e"
	uri = URI.parse(url)
	method = 'GET'
	res = client.request method, uri
	puts res.body
end