Class: BingTranslator::ApiClient

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

Constant Summary collapse

API_HOST =
'https://api.cognitive.microsofttranslator.com'.freeze
COGNITIVE_ACCESS_TOKEN_URI =
URI.parse('https://api.cognitive.microsoft.com/sts/v1.0/issueToken').freeze

Instance Method Summary collapse

Constructor Details

#initialize(subscription_key, skip_ssl_verify, read_timeout = 60, open_timeout = 60) ⇒ ApiClient

Returns a new instance of ApiClient.


22
23
24
25
26
27
# File 'lib/bing_translator.rb', line 22

def initialize(subscription_key, skip_ssl_verify, read_timeout = 60, open_timeout = 60)
  @subscription_key = subscription_key
  @skip_ssl_verify = skip_ssl_verify
  @read_timeout = read_timeout
  @open_timeout = open_timeout
end

Instance Method Details

#get(path, params: {}, headers: {}, authorization: false) ⇒ Object


29
30
31
32
33
34
# File 'lib/bing_translator.rb', line 29

def get(path, params: {}, headers: {}, authorization: false)
  uri = request_uri(path, params)
  request = Net::HTTP::Get.new(uri.request_uri, default_headers(authorization).merge(headers))

  json_response(uri, request)
end

#post(path, params: {}, headers: {}, data: {}, authorization: true) ⇒ Object


36
37
38
39
40
41
42
43
# File 'lib/bing_translator.rb', line 36

def post(path, params: {}, headers: {}, data: {}, authorization: true)
  uri = request_uri(path, params)

  request = Net::HTTP::Post.new(uri.request_uri, default_headers(authorization).merge(headers))
  request.body = data

  json_response(uri, request)
end