class CloudConvert::Webhook

Constants

Error

Raised when a webhook is malformed

InvalidSignature

Raised when a webhook does not match the CloudConvert-Signature

MissingSignature

Raised when a webhook does not have a CloudConvert-Signature

Public Class Methods

event(payload) click to toggle source

@param payload [String] The full request body (the JSON string) of our request to the webhook URL. @return [Event]

# File lib/cloudconvert/webhook.rb, line 15
def event(payload)
  Event.new(JSON.parse(payload, object_class: OpenStruct))
end
verify(payload, signature, secret) click to toggle source

@param payload [String] The full request body (the JSON string) of our request to the webhook URL. @param signature [String] The value from the CloudConvert-Signature. @param secret [String] The signing secret from for your webhook settings. @return [Boolean]

# File lib/cloudconvert/webhook.rb, line 23
def verify(payload, signature, secret)
  OpenSSL::HMAC.hexdigest("SHA256", secret.to_s, payload.to_s) == signature
end
verify!(payload, signature, secret) click to toggle source

@param payload [String] The full request body (the JSON string) of our request to the webhook URL. @param signature [String] The value from the CloudConvert-Signature. @param secret [String] The signing secret from for your webhook settings. @raise [MissingSignature, InvalidSignature] @return [Boolean]

# File lib/cloudconvert/webhook.rb, line 32
def verify!(payload, signature, secret)
  raise MissingSignature.new("Missing webhook signature") if signature.to_s.empty?
  raise InvalidSignature.new("Invalid webhook signature") unless verify(payload, signature, secret)
  true
end
verify_request(request, secret) click to toggle source

@param request [Request] The request to the webhook URL from CloudConvert. @param secret [String] The signing secret from for your webhook settings. @return [Boolean]

# File lib/cloudconvert/webhook.rb, line 41
def verify_request(request, secret)
  verify request.body.rewind && request.body.read, request.get_header("HTTP_CLOUDCONVERT_SIGNATURE"), secret
end
verify_request!(request, secret) click to toggle source

@param request [Request] The request to the webhook URL from CloudConvert. @param secret [String] The signing secret from for your webhook settings. @raise [MissingSignature, InvalidSignature] @return [Boolean]

# File lib/cloudconvert/webhook.rb, line 49
def verify_request!(request, secret)
  verify! request.body.rewind && request.body.read, request.get_header("HTTP_CLOUDCONVERT_SIGNATURE"), secret
end