summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@action.fairlystable.org>2024-01-14 01:03:09 -0800
committerJoe Rayhawk <jrayhawk@fairlystable.org>2024-01-14 01:06:31 -0800
commite9b6b9695212cebdfa8f94c1a05cad5d54511043 (patch)
tree8b9733c71fc1458d71e55cabfd0187fd622d6efb /src
parentd5858e2ef8f382b9e53308301ff7c7df3bf4b745 (diff)
downloadtwitcr-e9b6b9695212cebdfa8f94c1a05cad5d54511043.tar.gz
twitcr-e9b6b9695212cebdfa8f94c1a05cad5d54511043.zip
Attempt to modernize followers/followees APIHEADmaster
Signed-off-by: Joe Rayhawk <jrayhawk@fairlystable.org>
Diffstat (limited to 'src')
-rw-r--r--src/twitcr/rest.cr47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/twitcr/rest.cr b/src/twitcr/rest.cr
index 1be3190..5e4f881 100644
--- a/src/twitcr/rest.cr
+++ b/src/twitcr/rest.cr
@@ -55,10 +55,7 @@ module Twitcr::REST
headers["Content-Type"] = contenttype
end
- begin
- ENV["DEBUG"]
- rescue KeyError
- else
+ if ENV["DEBUG"]?
puts method + " " + url_base + api + route
#pp headers# probably too sensitive
pp body
@@ -72,13 +69,16 @@ module Twitcr::REST
tls: SSL_CONTEXT
)
- begin
- ENV["DEBUG"]
- rescue KeyError
- else
+ if ENV["DEBUG"]?
+ pp response.status_code
pp response.body
end
+ if response.status_code != 200
+ STDERR.puts( "WARNING: twitcr: " + method + " " + url_base + api + route + " status: " + response.status_code.to_s )
+ STDERR.puts( response.body )
+ end
+
response.body
end
@@ -89,33 +89,23 @@ module Twitcr::REST
def get_user( id : Array( String ) ); request( "GET", Api::Helix, "/users?login=#{login.join("&login=")}" ) end
def follow!( from : UInt64, to : UInt64 ); request( "PUT", Api::Kraken, "/users/#{from.to_s}/follows/channels/#{to.to_s}" ) end
def unfollow!( from : UInt64, to : UInt64 ); request( "DELETE", Api::Kraken, "/users/#{from.to_s}/follows/channels/#{to.to_s}" ) end
- def get_user_follows( *, from : UInt64, after : String? = nil )
+ def get_channels_followed( *, to : UInt64? = nil, from : UInt64, after : String? = nil )
params = Hash( String, String ).new
params["first"] = "100"
- params["from_id"] = from.to_s
- if after ; params["after"] = after end
+ params["user_id"] = from.to_s
+ to && ( params["broadcaster_id"] = to.to_s )
+ after && ( params["after"] = after )
query_string = HTTP::Params.encode( params )
- if ! query_string.empty?; query_string = "?" + query_string end
- request( "GET", Api::Helix, "/users/follows" + query_string )
+ request( "GET", Api::Helix, "/channels/followed?" + query_string )
end
- def get_user_follows( *, to : UInt64, after : String? = nil )
+ def get_channel_followers( *, to : UInt64, from : UInt64? = nil, after : String? = nil )
params = Hash( String, String ).new
params["first"] = "100"
- params["to_id"] = to.to_s
- if after; params["after"] = after end
+ params["broadcaster_id"] = to.to_s
+ from && ( params["user_id"] = from.to_s )
+ after && ( params["after"] = after )
query_string = HTTP::Params.encode( params )
- if ! query_string.empty?; query_string = "?" + query_string end
- request( "GET", Api::Helix, "/users/follows" + query_string )
- end
- def get_user_follows( *, to : UInt64, from : UInt64, after : String? = nil )
- params = Hash( String, String ).new
- params["first"] = "100"
- params["from_id"] = from.to_s
- params["to_id"] = to.to_s
- if after ; params["after"] = after end
- query_string = HTTP::Params.encode( params )
- if ! query_string.empty?; query_string = "?" + query_string end
- request( "GET", Api::Helix, "/users/follows" + query_string )
+ request( "GET", Api::Helix, "/channels/followers?" + query_string )
end
# FIXME: support array of mixed UInt64/String
def get_games( name : String ); request( "GET", Api::Helix, "/games?name=#{URI.encode_www_form( name )}" ) end
@@ -123,6 +113,7 @@ module Twitcr::REST
def get_streams( user_ids : Array( UInt64 ) ); request( "GET", Api::Helix, "/streams?user_id=#{user_ids.join( "&user_id=" )}" ) end
def get_streams( user_id : UInt64 ); request( "GET", Api::Helix, "/streams?user_id=#{user_id}" ) end
def get_streams( game_id : UInt64 ); request( "GET", Api::Helix, "/streams?first=100&game_id=#{game_id}" ) end
+ def get_streams( game_id : UInt64, cursor : String ); request( "GET", Api::Helix, "/streams?first=100&game_id=#{game_id}&after=#{cursor}" ) end
def get_streams(); request( "GET", Api::Helix, "/streams?first=100" ) end
# Kraken returns more information
def get_streams_v5( game : String ); request( "GET", Api::Kraken, "/streams?limit=100&game=#{URI.encode_www_form( game )}" ) end