{"id":13758535,"url":"https://github.com/mauricew/ruby-twitch-api","last_synced_at":"2025-05-10T08:30:33.513Z","repository":{"id":26728433,"uuid":"109623604","full_name":"mauricew/ruby-twitch-api","owner":"mauricew","description":"Ruby client for the Twitch Helix API.","archived":false,"fork":false,"pushed_at":"2025-04-19T10:46:38.000Z","size":386,"stargazers_count":39,"open_issues_count":7,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-21T08:45:20.157Z","etag":null,"topics":["helix","ruby","twitch","twitch-api","twitchtv"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mauricew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-05T22:52:13.000Z","updated_at":"2025-01-26T18:51:20.000Z","dependencies_parsed_at":"2023-02-13T22:15:40.186Z","dependency_job_id":"48d3be1b-3d09-4a3e-a788-a811400f16e7","html_url":"https://github.com/mauricew/ruby-twitch-api","commit_stats":{"total_commits":127,"total_committers":6,"mean_commits":"21.166666666666668","dds":0.5511811023622047,"last_synced_commit":"be26dfd8d3caae2d926ee4353d3a8e402b95c06c"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricew%2Fruby-twitch-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricew%2Fruby-twitch-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricew%2Fruby-twitch-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauricew%2Fruby-twitch-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauricew","download_url":"https://codeload.github.com/mauricew/ruby-twitch-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253389444,"owners_count":21900762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helix","ruby","twitch","twitch-api","twitchtv"],"created_at":"2024-08-03T13:00:31.929Z","updated_at":"2025-05-10T08:30:32.958Z","avatar_url":"https://github.com/mauricew.png","language":"Ruby","funding_links":[],"categories":["Libraries"],"sub_categories":["Ruby"],"readme":"[![Gem](https://img.shields.io/gem/v/twitch-api.svg)](https://rubygems.org/gems/twitch-api)\n[![Downloads](https://img.shields.io/gem/dt/twitch-api.svg)](https://rubygems.org/gems/twitch-api)\n[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/mauricew/ruby-twitch-api)](https://cirrus-ci.com/github/mauricew/ruby-twitch-api)\n[![License](https://img.shields.io/github/license/mauricew/ruby-twitch-api.svg)](LICENSE.txt)\n\n# Ruby Twitch API\n\nThis library is a Ruby implementation of the [Twitch Helix API](https://dev.twitch.tv/docs/api).\n\nThe goal is to provide access for the newest supported APIs provided by Twitch,\nwhile keeping extensibility for their future expansion.\nThese are still in development, as is this library which should remain in pace with changes made.\n\nGuaranteed supported APIs include:\n\n*   Helix REST (full rolling support)\n*   Helix Webhooks (coming soon)\n\nThe future may bring:\n\n*   PubSub\n\nThese will not be considered:\n\n*   [Twitch Kraken API](https://github.com/dustinlakin/twitch-rb)\n*   [Twitch GraphQL API](https://github.com/mauricew/twitch-graphql-api)\n*   [Twitch Chat (IRC/TMI)](https://github.com/EnotPoloskun/twitch-chat)\n\n## Installation\n\nAdd to your application's Gemfile:\n\n```ruby\n# If you want a full release\ngem 'twitch-api'\n# If you want to live on the edge\ngem 'twitch-api', :git =\u003e 'https://github.com/mauricew/ruby-twitch-api'\n```\n\nAnd then execute:\n\n```sh\n$ bundle\n```\n\nOr install it yourself as:\n\n```sh\n$ gem install twitch-api\n```\n\n## Usage\n\n### Authentication\n\n[Twitch documentation](https://dev.twitch.tv/docs/authentication).\n\nThis gem uses [`twitch_oauth2` gem](https://github.com/AlexWayfer/twitch_oauth2)\nfor authorization and authentication, you can read more detailed documentation there\n(but it's pretty simple).\n\nThe goal is in an object with credentials and re-using it between different gems,\nfor example for API and for chat, or for the old API and the new one.\nAlso a logic for tokens validation and refreshing is encapsulated in it.\n\nOne of references is [this JavaScript set of libraries](https://github.com/d-fischer/twitch).\n\n#### Client (application) flow\n\nThis is easier flow with limited (non-personal) access.\n\n```ruby\ntokens = TwitchOAuth2::Tokens.new(\n  client: {\n    client_id: client_id,\n    client_secret: client_secret\n  },\n\n  ## this is default\n  # token_type: :application,\n\n  ## this can be required by some Twitch end-points\n  # scopes: scopes,\n\n  ## if you already have ones\n  # access_token: access_token\n)\n\ntwitch_client = Twitch::Client.new(tokens: tokens)\n```\n\n#### Authorization (user) flow\n\nThis is flow required for user-specific actions.\n\nIf there are no `access_token` and `refresh_token` in `:tokens`,\n`TwitchOAuth2::AuthorizeError` will be raised with `#link`.\n\nIf you have a web-application with N users, you can redirect them to this link\nand use `redirect_uri` to your application for callbacks.\n\nOtherwise, if you have something like CLI tool, you can print instructions with a link for user.\n\nThen you can use `tokens.code = 'a code from params in redirect uri'`\nand it'll store new `:access_token` and `:refresh_token`.\n\n```ruby\ntokens = TwitchOAuth2::Tokens.new(\n  client: {\n    client_id: client_id,\n    client_secret: client_secret,\n\n    ## `localhost` by default, can be your application end-point\n    # redirect_uri: redirect_uri\n  },\n\n  token_type: :user,\n\n  ## this can be required by some Twitch end-points\n  # scopes: scopes,\n\n  ## if you already have these\n  # access_token: access_token,\n  # refresh_token: refresh_token\n)\n\ntwitch_client = Twitch::Client.new(tokens: tokens)\n```\n\n#### After initialization\n\nIf you've passed `refresh_token` to initialization and your `access_token` is invalid,\nrequests that require `access_token` will automatically refresh it.\n\nYou can access tokens:\n\n```ruby\ntwitch_client.tokens # =\u003e `TwitchOAuth2::Tokens` instance\ntwitch_client.tokens.access_token # =\u003e 'abcdef'\ntwitch_client.tokens.refresh_token # =\u003e 'ghijkl'\n```\n\n### Calls\n\nBecause data may change for certain endpoints, there is also the raw response\nfor any request called.\n\nRetrieval methods take in a hash equal to the parameters of the API endpoint,\nand return a response object containing the data and other associated request information:\n\n*   **data** is the data you would get back. Even if it's an array of one object,\n    it remains the same as what comes from the API.\n*   **rate_limit** and associated fields contain API request limit information.\n    Clip creation counts for a second limit (duration currently unknown).\n*   **pagination** is a hash that appears when data can be traversed,\n    and contains one member (*cursor*) which lets you paginate through certain requests.\n*   **raw** is the raw HTTP response data.\n\n```ruby\n# Get top live streams\nclient.get_streams.data\n# Get a single user\nclient.get_users({login: \"disguisedtoasths\"}).data.first\n# Find some games\n# (use an array for up to 100 of most queryable resources)\nclient.get_games({name: [\"Heroes of the Storm\", \"Super Mario Odyssey\"]}).data\n```\n\n### Error handling\n\nAn `APIError` is raised whenever an HTTP error response is returned.\nRescue it to access the body of the response, which should include an error message.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies.\nThen, run `rake spec` to run the tests.\n(Tests require a Twitch Client ID; since cassettes exist you can use any value.)\n\nYou can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/mauricew/ruby-twitch-api).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauricew%2Fruby-twitch-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauricew%2Fruby-twitch-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauricew%2Fruby-twitch-api/lists"}