Class: Cangaroo::Webhook::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cangaroo/webhook/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, path) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/cangaroo/webhook/client.rb', line 10

def initialize(connection, path)
  @connection = connection
  @path = path
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



8
9
10
# File 'lib/cangaroo/webhook/client.rb', line 8

def connection
  @connection
end

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/cangaroo/webhook/client.rb', line 8

def path
  @path
end

Instance Method Details

#post(payload, request_id, parameters) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cangaroo/webhook/client.rb', line 15

def post(payload, request_id, parameters)
  request_body = body(payload, request_id, parameters).to_json

  request_options = {
    headers: headers,
    body: request_body
  }

  if Rails.configuration.cangaroo.basic_auth
    request_options[:basic_auth] = {
      username: connection.key,
      password: connection.token
    }
  end

  if timeout = Rails.configuration.cangaroo.client_timeout
    request_options[:timeout] = timeout
  end

  req = self.class.post(url, request_options)

  sanitized_response = sanitize_response(req)

  fail Cangaroo::Webhook::Error, sanitized_response unless %w(200 201 202 204).include?(req.response.code)
  sanitized_response
end