Module: Swiftype::Request

Included in:
Client
Defined in:
lib/swiftype/request.rb

Instance Method Summary collapse

Instance Method Details

#delete(path, params = {}) ⇒ Object



25
26
27
# File 'lib/swiftype/request.rb', line 25

def delete(path, params={})
  request(:delete, path, params)
end

#get(path, params = {}) ⇒ Object



13
14
15
# File 'lib/swiftype/request.rb', line 13

def get(path, params={})
  request(:get, path, params)
end

#post(path, params = {}) ⇒ Object



17
18
19
# File 'lib/swiftype/request.rb', line 17

def post(path, params={})
  request(:post, path, params)
end

#put(path, params = {}) ⇒ Object



21
22
23
# File 'lib/swiftype/request.rb', line 21

def put(path, params={})
  request(:put, path, params)
end

#request(method, path, params = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/swiftype/request.rb', line 29

def request(method, path, params={})
  uri = URI.parse("#{Swiftype.endpoint}#{path}")

  request = build_request(method, uri, params)
  http = Net::HTTP.new(uri.host, uri.port)

  if uri.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    http.ca_file = File.join(__FILE__, '..', 'data', 'ca-bundle.crt')
  end

  response = http.request(request)

  handle_errors(response)

  JSON.parse(response.body) if response.body && response.body.strip != ''
end