Hi guys, currently I have this code:
class TwitchService
TWITCH_ENDPOINT = URI.parse("https://api.twitch.tv/helix/webhooks/hub")
class << self
def subscribe_user_events(user_id, callback_url)
data = {
"hub.mode": :subscribe,
"hub.topic": "https://api.twitch.tv/helix/streams?user_id=#{user_id}",
"hub.callback": "#{callback_url}",
"hub.lease_seconds": 864000,
"hub.secret": "234"
}
response_body = post(data.to_json)
end
def post(body)
connection = get_connection
request = Net::HTTP::Post.new(TWITCH_ENDPOINT)
request.content_type = "application/json"
request["Client-ID"] = "thisexistsbutnotshowingit"
request.body = body
connection.request(request).body
end
# Return a connection against Twitchs servers
def get_connection
https = Net::HTTP.new(TWITCH_ENDPOINT.host, TWITCH_ENDPOINT.port)
https.use_ssl = true
https.read_timeout = 1000
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
https
end
end
end
If i unset for example hub.topic, I get this:
"{\"error\":\"Bad Request\",\"status\":400,\"message\":\"hub.topic is required\"}"
Which is how it should be, but when i’m sending it correctly i’m expecting a:
202 Accepted || 200 ok
But I don’t get any response, so what have I’ve done wrong? I’m not so experienced, so hoping it’s just a small newbie mistake somewhere.
EDIT:
Added https.set_debug_output($stdout) in my def get_connection and get the 202 response:
-> "HTTP/1.1 202 Accepted\r\n"