
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
This library is a Ruby implementation of the Twitch Helix API.
The goal is to provide access for the newest supported APIs provided by Twitch, while keeping extensibility for their future expansion. These are still in development, as is this library which should remain in pace with changes made.
Guaranteed supported APIs include:
The future may bring:
These will not be considered:
Add to your application's Gemfile:
# If you want a full release
gem 'twitch-api'
# If you want to live on the edge
gem 'twitch-api', :git => 'https://github.com/mauricew/ruby-twitch-api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install twitch-api
This gem uses twitch_oauth2
gem
for authorization and authentication, you can read more detailed documentation there
(but it's pretty simple).
The goal is in an object with credentials and re-using it between different gems, for example for API and for chat, or for the old API and the new one. Also a logic for tokens validation and refreshing is encapsulated in it.
One of references is this JavaScript set of libraries.
This is easier flow with limited (non-personal) access.
tokens = TwitchOAuth2::Tokens.new(
client: {
client_id: client_id,
client_secret: client_secret
},
## this is default
# token_type: :application,
## this can be required by some Twitch end-points
# scopes: scopes,
## if you already have ones
# access_token: access_token
)
twitch_client = Twitch::Client.new(tokens: tokens)
This is flow required for user-specific actions.
If there are no access_token
and refresh_token
in :tokens
,
TwitchOAuth2::AuthorizeError
will be raised with #link
.
If you have a web-application with N users, you can redirect them to this link
and use redirect_uri
to your application for callbacks.
Otherwise, if you have something like CLI tool, you can print instructions with a link for user.
Then you can use tokens.code = 'a code from params in redirect uri'
and it'll store new :access_token
and :refresh_token
.
tokens = TwitchOAuth2::Tokens.new(
client: {
client_id: client_id,
client_secret: client_secret,
## `localhost` by default, can be your application end-point
# redirect_uri: redirect_uri
},
token_type: :user,
## this can be required by some Twitch end-points
# scopes: scopes,
## if you already have these
# access_token: access_token,
# refresh_token: refresh_token
)
twitch_client = Twitch::Client.new(tokens: tokens)
If you've passed refresh_token
to initialization and your access_token
is invalid,
requests that require access_token
will automatically refresh it.
You can access tokens:
twitch_client.tokens # => `TwitchOAuth2::Tokens` instance
twitch_client.tokens.access_token # => 'abcdef'
twitch_client.tokens.refresh_token # => 'ghijkl'
Because data may change for certain endpoints, there is also the raw response for any request called.
Retrieval methods take in a hash equal to the parameters of the API endpoint, and return a response object containing the data and other associated request information:
# Get top live streams
client.get_streams.data
# Get a single user
client.get_users({login: "disguisedtoasths"}).data.first
# Find some games
# (use an array for up to 100 of most queryable resources)
client.get_games({name: ["Heroes of the Storm", "Super Mario Odyssey"]}).data
An APIError
is raised whenever an HTTP error response is returned.
Rescue it to access the body of the response, which should include an error message.
After checking out the repo, run bin/setup
to install dependencies.
Then, run rake spec
to run the tests.
(Tests require a Twitch Client ID; since cassettes exist you can use any value.)
You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
.
Bug reports and pull requests are welcome on GitHub.
FAQs
Unknown package
We found that twitch-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.