class Inngest::Client

Constants

API_ENDPOINT
HEADERS

Public Class Methods

new(inngest_key, endpoint = API_ENDPOINT) click to toggle source
# File lib/inngest.rb, line 14
def initialize(inngest_key, endpoint = API_ENDPOINT)
  raise InngestException.new "Inngest Key can't be nil" if inngest_key.nil?

  @url = "#{endpoint}/e/#{inngest_key}"
  @http = http_client @url
end

Public Instance Methods

send(event) click to toggle source
# File lib/inngest.rb, line 21
def send(event)
  raise InngestException.new "Event can't be nil" if event.nil?
  event = Event.new(**event) if event.is_a? Hash
  raise InngestException.new "Can't construct Event" unless event.is_a? Event

  event.validate
  request = Net::HTTP::Post.new(@url, HEADERS)
  request.body = event.payload.to_json

  @http.request(request)
end

Private Instance Methods

http_client(url) click to toggle source
# File lib/inngest.rb, line 35
def http_client(url)
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.instance_of? URI::HTTPS
  http.read_timeout = 8
  http.open_timeout = 4

  http
end