Skip to content

Instantly share code, notes, and snippets.

@Daniel-Worrall
Created October 10, 2019 15:14
Show Gist options
  • Save Daniel-Worrall/215066b42ac1a7046b97cd3d44041ac5 to your computer and use it in GitHub Desktop.
Save Daniel-Worrall/215066b42ac1a7046b97cd3d44041ac5 to your computer and use it in GitHub Desktop.
require "http/client"
require "json"
http_client = HTTP::Client.new("api.twitch.tv", tls: true)
body = JSON.build do |json|
json.object do
json.field "hub.callback", "https://dev.nekka.co.uk/callback"
json.field "hub.mode", "subscribe"
json.field "hub.topic", "https://api.twitch.tv/helix/streams?user_id=158013844"
json.field "hub.lease_seconds", 864000
json.field "hub.secret", "SECRET"
end
end
headers = HTTP::Headers{"Content-Type" => "application/json"}
request = HTTP::Request.new("POST", "/helix/webhooks/hub", headers, body.to_s)
request.headers["Host"] = "api.twitch.tv"
request.headers["client-id"] = "CLIENT_ID"
response = http_client.exec(request)
Unhandled exception in spawn: SSL_read: error:1408F10B:SSL routines:ssl3_get_record:wrong version number (OpenSSL::SSL::Error)
from /usr/lib/crystal/core/openssl/ssl/socket.cr:118:9 in 'unbuffered_read'
from /usr/lib/crystal/core/io/buffered.cr:214:12 in 'fill_buffer'
from /usr/lib/crystal/core/io/buffered.cr:103:7 in 'peek'
from /usr/lib/crystal/core/io.cr:632:37 in 'gets'
from /usr/lib/crystal/core/io.cr:591:5 in 'gets'
from /usr/lib/crystal/core/http/client/response.cr:127:5 in 'from_io?'
from /usr/lib/crystal/core/http/client.cr:581:5 in 'exec_internal_single'
from /usr/lib/crystal/core/http/client.cr:567:5 in 'exec_internal'
from /usr/lib/crystal/core/http/client.cr:563:5 in 'exec'
from lib/twitch/src/twitch/rest.cr:22:16 in 'request'
from lib/twitch/src/twitch/rest.cr:14:5 in 'authed_request:client_id'
from lib/twitch/src/twitch/rest.cr:32:5 in 'webhook_subscribe'
from src/new_app.cr:153:9 in '->'
from /usr/lib/crystal/core/fiber.cr:255:3 in 'run'
from /usr/lib/crystal/core/fiber.cr:48:34 in '->'
from ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment