Class: Twitch::Client
- Inherits:
-
Object
- Object
- Twitch::Client
- Defined in:
- lib/twitch/client.rb
Constant Summary collapse
- API_ENDPOINT =
"https://api.twitch.tv/helix".freeze
Instance Method Summary collapse
- #get_games(options = {}) ⇒ Object
- #get_streams(options = {}) ⇒ Object
- #get_users(options = {}) ⇒ Object
- #get_videos(options = {}) ⇒ Object
-
#initialize(client_id:, access_token: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(client_id:, access_token: nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/twitch/client.rb', line 13 def initialize(client_id:, access_token: nil) headers = { "Client-ID": client_id, "User-Agent": "twitch-api ruby client #{Twitch::VERSION}" } unless access_token.nil? headers["Authorization"] = "Bearer #{access_token}" end @conn = Faraday.new(API_ENDPOINT, { headers: headers }) do |faraday| faraday.response :json faraday.adapter Faraday.default_adapter end end |
Instance Method Details
#get_games(options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/twitch/client.rb', line 40 def get_games( = {}) res = get('games', ) games = res.body['data'].map { |g| Game.new(g) } end |
#get_streams(options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/twitch/client.rb', line 28 def get_streams( = {}) res = get('streams', ) streams = res.body['data'].map { |s| Stream.new(s) } end |