Class: Hookly::Request

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

Class Method Summary collapse

Class Method Details

.run(name, path, options, body = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/request.rb', line 3

def self.run(name, path, options, body={})
  request_options = {
    method: name,
    accept_encoding: :gzip,
    headers: { 'Content-Type' => 'application/json', 'User-Agent' => user_agent }
  }

  request_options[body_param(name)] = processed_body(name, options.merge( secret: Hookly.secret, :body => body ))

  response = Typhoeus::Request.new("#{Hookly.url}/#{path}", request_options).run

  if response.success?
    JSON.parse(response.response_body)['message']
  else
    raise ResponseError.new(response)
  end
end