Class: CognitiveVision::Connection

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

Constant Summary collapse

ENDPOINT =
'https://westus.api.cognitive.microsoft.com/vision/v1.0/'.freeze

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



8
9
10
11
12
# File 'lib/cognitive_vision/connection.rb', line 8

def initialize
  @uri          = URI(ENDPOINT)
  @http         = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl = @uri.scheme == 'https'
end

Instance Method Details

#post(path, params, body) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/cognitive_vision/connection.rb', line 14

def post(path, params, body)
  uri = prepare_uri(path, params)
  request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
  request['Ocp-Apim-Subscription-Key'] = CognitiveVision.configuration.key
  request.body = body.to_json
  request_json(request)
end