Class: Twitch::Client
- Inherits:
-
Object
- Object
- Twitch::Client
- Defined in:
- lib/twitch/client.rb
Constant Summary collapse
- API_ENDPOINT =
Helix API endpoint.
"https://api.twitch.tv/helix".freeze
Instance Method Summary collapse
- #create_clip(options = {}) ⇒ Object
- #create_entitlement_grant_url(options = {}) ⇒ Object
- #create_stream_marker(options = {}) ⇒ Object
- #get_bits_leaderboard(options = {}) ⇒ Object
- #get_clips(options = {}) ⇒ Object
- #get_game_analytics(options = {}) ⇒ Object
- #get_games(options = {}) ⇒ Object
- #get_stream_markers(options = {}) ⇒ Object
- #get_streams(options = {}) ⇒ Object
- #get_streams_metadata(options = {}) ⇒ Object
- #get_top_games(options = {}) ⇒ Object
- #get_users(options = {}) ⇒ Object
- #get_users_follows(options = {}) ⇒ Object
- #get_videos(options = {}) ⇒ Object
-
#initialize(client_id: nil, access_token: nil, with_raw: false) ⇒ Client
constructor
Initializes a Twitch client.
- #update_user(options = {}) ⇒ Object
Constructor Details
#initialize(client_id: nil, access_token: nil, with_raw: false) ⇒ Client
Initializes a Twitch client.
-
client_id [String] The client ID.
Used as the Client-ID header in a request.
-
access_token [String] An access token.
Used as the Authorization header in a request. Any “Bearer ” prefix will be stripped.
-
with_raw [Boolean] Whether to include raw HTTP response
Intended for testing/checking API results
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/twitch/client.rb', line 32 def initialize(client_id: nil, access_token: nil, with_raw: false) if client_id.nil? && access_token.nil? raise "An identifier token (client ID or bearer token) is required" elsif !!client_id && !!access_token warn(%{WARNING: It is recommended that only one identifier token is specified. Unpredictable behavior may follow.}) end headers = { "User-Agent": "twitch-api ruby client #{Twitch::VERSION}" } unless client_id.nil? headers["Client-ID"] = client_id end unless access_token.nil? access_token = access_token.gsub(/^Bearer /, "") headers["Authorization"] = "Bearer #{access_token}" end @conn = Faraday.new(API_ENDPOINT, { headers: headers }) do |faraday| faraday.request :json faraday.response :json faraday.adapter Faraday.default_adapter end @with_raw = with_raw end |
Instance Method Details
#create_clip(options = {}) ⇒ Object
61 62 63 |
# File 'lib/twitch/client.rb', line 61 def create_clip( = {}) Response.new(Clip, post('clips', )) end |
#create_entitlement_grant_url(options = {}) ⇒ Object
65 66 67 |
# File 'lib/twitch/client.rb', line 65 def create_entitlement_grant_url( = {}) Response.new(EntitlementGrantUrl, post('entitlements/upload', )) end |
#create_stream_marker(options = {}) ⇒ Object
69 70 71 |
# File 'lib/twitch/client.rb', line 69 def create_stream_marker( = {}) Response.new(StreamMarker, post('streams/markers', )) end |
#get_bits_leaderboard(options = {}) ⇒ Object
77 78 79 |
# File 'lib/twitch/client.rb', line 77 def get_bits_leaderboard( = {}) Response.new(BitsLeader, get('bits/leaderboard', )) end |
#get_clips(options = {}) ⇒ Object
73 74 75 |
# File 'lib/twitch/client.rb', line 73 def get_clips( = {}) Response.new(Clip, get('clips', )) end |
#get_game_analytics(options = {}) ⇒ Object
89 90 91 |
# File 'lib/twitch/client.rb', line 89 def get_game_analytics( = {}) Response.new(GameAnalytic, get('analytics/games', )) end |
#get_games(options = {}) ⇒ Object
81 82 83 |
# File 'lib/twitch/client.rb', line 81 def get_games( = {}) Response.new(Game, get('games', )) end |
#get_stream_markers(options = {}) ⇒ Object
93 94 95 |
# File 'lib/twitch/client.rb', line 93 def get_stream_markers( = {}) Response.new(StreamMarkerResponse, get('streams/markers', )) end |
#get_streams(options = {}) ⇒ Object
97 98 99 |
# File 'lib/twitch/client.rb', line 97 def get_streams( = {}) Response.new(Stream, get('streams', )) end |
#get_streams_metadata(options = {}) ⇒ Object
101 102 103 |
# File 'lib/twitch/client.rb', line 101 def ( = {}) Response.new(StreamMetadata, get('streams/metadata', )) end |
#get_top_games(options = {}) ⇒ Object
85 86 87 |
# File 'lib/twitch/client.rb', line 85 def get_top_games( = {}) Response.new(Game, get('games/top', )) end |
#get_users(options = {}) ⇒ Object
109 110 111 |
# File 'lib/twitch/client.rb', line 109 def get_users( = {}) Response.new(User, get('users', )) end |
#get_users_follows(options = {}) ⇒ Object
105 106 107 |
# File 'lib/twitch/client.rb', line 105 def get_users_follows( = {}) Response.new(UserFollow, get('users/follows', )) end |