Skip to content

Instantly share code, notes, and snippets.

@joshed-io
Created November 14, 2013 19:27
Show Gist options
  • Save joshed-io/7472823 to your computer and use it in GitHub Desktop.
Save joshed-io/7472823 to your computer and use it in GitHub Desktop.
How to publish an event asynchronously from a simple ruby script using keen-gem
require "keen"
require "em-http-request"
# make sure the environment is set up
ENV["KEEN_PROJECT_ID"] = "..."
ENV["KEEN_WRITE_KEY"] = "..."
Thread.new { EventMachine.run }
sleep 1
http = Keen.publish_async(:sign_ups, {
username: "dzello"
})
http.callback do |response|
puts "Success: #{response}"
# now we can exit the process
exit
end
http.errback do |e|
puts "was a failurrr :,("
exit
end
# keep this thread running so the process stays up
while true
sleep 1
end
@micke
Copy link

micke commented Nov 15, 2013

Isn't it better to just join with the EM thread instead of looping a sleep?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment