Class: SyllabsApi::HttpProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/syllabs-api/http_processor.rb

Constant Summary collapse

TIMEOUT =
30

Class Method Summary collapse

Class Method Details

.post(api_key, api_url, params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/syllabs-api/http_processor.rb', line 6

def self.post(api_key, api_url, params)
  raise Exceptions::InvalidKey if api_key.nil?

  header = {'Api-Key' => api_key}
  api_uri = URI.parse(api_url)

  http_response = nil
  Timeout::timeout(TIMEOUT) do
    http = Net::HTTP.new(api_uri.host, api_uri.port)
    post = Net::HTTP::Post.new(api_uri.request_uri, header)
    post.set_form_data(params)
    http_response = http.request post
  end
  return http_response

rescue Exception => e
  raise e
end